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/cloudflare.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { fitted, ignoring, lines, withCli, withDependencies, withLines } from "./files.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { itemsAt, jsonString, manifestText, parseJsonc, stringAt, withEntries, withValue } from "./jsonc.mjs";
|
|
2
|
+
import { effectImports, featuresLines, gitDependencies, gitImports, gitPackages, header, runtimeLines, writtenCpu } from "./git-module.mjs";
|
|
3
|
+
import { itemsAt, jsonString, manifestText, nodeAt, parseJsonc, stringAt, withEntries, withValue } from "./jsonc.mjs";
|
|
4
4
|
import { filled, templates, unless } from "./template.mjs";
|
|
5
5
|
import { catalog } from "./metadata.mjs";
|
|
6
6
|
import * as Redacted from "effect/Redacted";
|
|
@@ -15,21 +15,10 @@ import * as Redacted from "effect/Redacted";
|
|
|
15
15
|
const secretFiles = [".dev.vars"];
|
|
16
16
|
/** The secrets Git's Worker takes: the admin's, which signs in to make repos and tokens. */
|
|
17
17
|
const gitSecrets = ["ADMIN_TOKEN"];
|
|
18
|
-
/**
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
first: (request) => `(await github.route(${request})) ?? (await rest.route(${request}))`
|
|
23
|
-
},
|
|
24
|
-
api: {
|
|
25
|
-
names: "rest",
|
|
26
|
-
first: (request) => `(await rest.route(${request}))`
|
|
27
|
-
},
|
|
28
|
-
git: {
|
|
29
|
-
names: "git",
|
|
30
|
-
first: (request) => `(await git.route(${request}))`
|
|
31
|
-
}
|
|
32
|
-
};
|
|
18
|
+
/** What an entry that falls through to its host's own `fetch` imports, to route Git's URLs first. */
|
|
19
|
+
const fallThroughImports = lines("import { Git } from '@ref0/git';", "import * as Option from 'effect/Option';");
|
|
20
|
+
/** Git's answer to `request` on the module's runtime, `undefined` for a URL no route of Git's owns. */
|
|
21
|
+
const routed = (request) => `Option.getOrUndefined(await runtime.runPromise(Git.route(${request})))`;
|
|
33
22
|
/** The bindings and classes Git needs. */
|
|
34
23
|
const gitClasses = [{
|
|
35
24
|
name: "RECORDS",
|
|
@@ -41,41 +30,45 @@ const gitClasses = [{
|
|
|
41
30
|
/** The infra import of a `src/git.ts` with no bucket. */
|
|
42
31
|
const looseInfraImport = "import { layer, toJobObject, toRecordsObject } from '@ref0/infra/cloudflare';";
|
|
43
32
|
/** The adapter of a `src/git.ts` with no bucket: the records and jobs' Layer alone. */
|
|
44
|
-
const looseAdapter = "
|
|
33
|
+
const looseAdapter = lines("/** The records and job objects. */", "const adapter = layer({ records: env.RECORDS, jobs: env.JOBS });", "", "");
|
|
34
|
+
/** A push's pack upload, once the bucket signs parts: `signed` only with R2's S3 credentials. */
|
|
35
|
+
const uploads = lines(" // A push past 64 MiB may upload its pack, once the bucket signs parts.", " signed === undefined", " ? Layer.empty", " : Layer.provide(Git.layerUploads({ above: 64 * 1024 * 1024 }), signed),");
|
|
45
36
|
/** `src/git.ts`: `examples/git-worker`'s own, with what it serves, the store and the queue as chosen. */
|
|
46
|
-
const gitModule = (choices, envFile) => {
|
|
37
|
+
const gitModule = (choices, envFile, cpu) => {
|
|
47
38
|
const packs = choices.objects === "packs";
|
|
48
|
-
const queue = choices.queue === "on";
|
|
49
|
-
const github = choices.serve === "github";
|
|
50
|
-
const basePath = basePathLines(choices);
|
|
51
39
|
return filled(templates.workerGit, {
|
|
52
40
|
header: `${header(choices, "Cloudflare")}\n`,
|
|
53
41
|
gitImports: `${gitImports(choices)}\n`,
|
|
54
42
|
infraImport: unless(packs, looseInfraImport),
|
|
43
|
+
effectImports: `${effectImports(choices)}\n`,
|
|
55
44
|
envFile: `'${envFile}'`,
|
|
56
45
|
safety: unless(packs, "binds the objects"),
|
|
57
|
-
bucket: unless(packs,
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
46
|
+
bucket: unless(packs, looseAdapter),
|
|
47
|
+
merge: unless(choices.queue === "on", ""),
|
|
48
|
+
features: `${featuresLines(choices, {
|
|
49
|
+
cpu,
|
|
50
|
+
merges: "{ xdiff }",
|
|
51
|
+
uploads: packs && uploads
|
|
52
|
+
})}\n`,
|
|
53
|
+
runtime: `${runtimeLines(choices, {
|
|
54
|
+
token: "env.ADMIN_TOKEN",
|
|
55
|
+
adapter: "adapter"
|
|
56
|
+
})}\n`
|
|
68
57
|
});
|
|
69
58
|
};
|
|
70
|
-
/**
|
|
71
|
-
const
|
|
72
|
-
github:
|
|
73
|
-
|
|
59
|
+
/** What a Worker `init` writes serves, which its entry's comment names. */
|
|
60
|
+
const servedSays = {
|
|
61
|
+
github: "The drop-in's URLs, Git's REST and protocol",
|
|
62
|
+
api: "Git's REST and protocol",
|
|
63
|
+
git: "Git's protocol and sign-in"
|
|
74
64
|
};
|
|
75
|
-
/**
|
|
65
|
+
/**
|
|
66
|
+
* `src/worker.ts`, the entry of a Worker `init` writes whole: `examples/git-worker`'s own, without
|
|
67
|
+
* the device page's front door, as a Worker `init` writes serves no sign-in.
|
|
68
|
+
*/
|
|
76
69
|
const workerEntry = (choices) => filled(templates.workerEntry, {
|
|
77
|
-
|
|
78
|
-
exports: choices.serve
|
|
70
|
+
gate: "",
|
|
71
|
+
exports: lines(`/** ${servedSays[choices.serve]}, then a JSON \`404\`. */`, "export default { fetch: Git.toFetch(runtime) } satisfies ExportedHandler<Env>;", "")
|
|
79
72
|
});
|
|
80
73
|
/** `main`'s path as `src/git-entry.ts` imports it. */
|
|
81
74
|
const fromEntry = (main) => {
|
|
@@ -83,9 +76,9 @@ const fromEntry = (main) => {
|
|
|
83
76
|
return up.startsWith("../") ? up : `./${up}`;
|
|
84
77
|
};
|
|
85
78
|
/** `src/git-entry.ts`: an existing Worker's new `main`, which runs its own after Git's URLs. */
|
|
86
|
-
const wrappedEntry = (
|
|
79
|
+
const wrappedEntry = (main) => lines("// This Worker's entry, written by `ref0-git init`: Git's URLs first, then the Worker in", `// \`${main}\`, whose other exports and handlers it keeps. \`wrangler.jsonc\`'s \`main\` names it.`, fallThroughImports, "", `import worker from '${fromEntry(main)}';`, "", "import { runtime } from './git.ts';", "", `export * from '${fromEntry(main)}';`, "", "export { Jobs, Records } from './git.ts';", "", "export default {", " ...worker,", " fetch: async (...call: Parameters<typeof worker.fetch>) =>", ` ${routed("call[0]")} ?? worker.fetch(...call),`, "};", "");
|
|
87
80
|
/** `src/server.ts`: Start's server entry, Git's URLs before the app's. */
|
|
88
|
-
const startEntry =
|
|
81
|
+
const startEntry = lines("// Start's server entry, written by `ref0-git init`: Git's URLs first, then the app.", "// `wrangler.jsonc`'s `main` names it, so the Worker exports Git's two classes too.", fallThroughImports, "import handler, { createServerEntry } from '@tanstack/react-start/server-entry';", "", "import { runtime } from './git.ts';", "", "export { Jobs, Records } from './git.ts';", "", "export default createServerEntry({", fitted(" fetch: async (request) =>", `${routed("request")} ?? handler.fetch(request),`), "});", "");
|
|
89
82
|
/** `src/env.ts`, or `src/git-env.ts` beside a project's own: `examples/git-worker`'s, as the store has it. */
|
|
90
83
|
const envModule = (choices) => {
|
|
91
84
|
const packs = choices.objects === "packs";
|
|
@@ -98,6 +91,8 @@ const envModule = (choices) => {
|
|
|
98
91
|
const bucketName = (name) => `${name}-packs`;
|
|
99
92
|
/** `wrangler.jsonc`'s bucket line, with its newline, for a store that has one. */
|
|
100
93
|
const bucketLine = (choices, name) => choices.objects === "packs" ? ` "r2_buckets": [{ "binding": "PACKS", "bucket_name": "${bucketName(name)}" }],\n` : "";
|
|
94
|
+
/** `wrangler.jsonc`'s CPU a request may use, which `Lfs.layer` in `src/git.ts` takes too. */
|
|
95
|
+
const limitsLine = ` "limits": { "cpu_ms": ${writtenCpu.ms} },`;
|
|
101
96
|
/** `wrangler.jsonc` for a Worker `init` writes whole: `examples/git-worker`'s, named `name`. */
|
|
102
97
|
const wranglerConfig = (choices, name) => {
|
|
103
98
|
const packs = choices.objects === "packs";
|
|
@@ -105,6 +100,7 @@ const wranglerConfig = (choices, name) => {
|
|
|
105
100
|
about: unless(packs, "Durable Object classes"),
|
|
106
101
|
signing: unless(packs, ""),
|
|
107
102
|
name: ` "name": ${jsonString(name)},`,
|
|
103
|
+
limits: limitsLine,
|
|
108
104
|
bucket: bucketLine(choices, name),
|
|
109
105
|
vars: packs ? ` "vars": { "PACKS_BUCKET": "${bucketName(name)}" },\n` : ""
|
|
110
106
|
});
|
|
@@ -122,6 +118,38 @@ const bound = (text, path, key) => itemsAt(parseJsonc(text), path).flatMap((item
|
|
|
122
118
|
/** Each string a TOML config sets `key` to, basic or literal, on a line of its own or in an array. */
|
|
123
119
|
const tomlStrings = (text, key) => [...text.matchAll(new RegExp(`^\\s*${key}\\s*=\\s*(\\[[^\\]]*\\]|"[^"]*"|'[^']*')`, "gm"))].flatMap((line) => [...(line[1] ?? "").matchAll(/"([^"]*)"|'([^']*)'/g)].map((each) => each[1] ?? each[2] ?? ""));
|
|
124
120
|
/**
|
|
121
|
+
* The CPU a Worker's config gives one request, its `limits.cpu_ms`, if it sets one: where it sets
|
|
122
|
+
* none, the platform's default, which the adapter holds an upload to.
|
|
123
|
+
*/
|
|
124
|
+
const configCpu = (file, text) => {
|
|
125
|
+
const raw = file === "wrangler.toml" ? tomlCpu(text) : rawAt(nodeAt(parseJsonc(text), ["limits", "cpu_ms"]));
|
|
126
|
+
return raw !== void 0 && /^\d+$/.test(raw) && Number(raw) > 0 ? {
|
|
127
|
+
ms: Number(raw),
|
|
128
|
+
file
|
|
129
|
+
} : void 0;
|
|
130
|
+
};
|
|
131
|
+
/** How a `wrangler.toml` line sets the root `limits.cpu_ms`, by the table it's in: none in an env's. */
|
|
132
|
+
const tomlCpuLines = /* @__PURE__ */ new Map([["limits", /^cpu_ms\s*=\s*([\d_]+)$/], ["", /^limits\s*(?:\.\s*cpu_ms\s*=|=\s*\{.*\bcpu_ms\s*=)\s*([\d_]+)/]]);
|
|
133
|
+
/**
|
|
134
|
+
* A `wrangler.toml`'s root `limits.cpu_ms`, its digits without their `_`: in its `[limits]` table,
|
|
135
|
+
* or as `limits = { cpu_ms = … }` or `limits.cpu_ms = …` before any table, never an env's.
|
|
136
|
+
*/
|
|
137
|
+
const tomlCpu = (text) => {
|
|
138
|
+
let table = "";
|
|
139
|
+
for (const line of text.split("\n")) {
|
|
140
|
+
const bare = line.replace(/#.*$/, "").trim();
|
|
141
|
+
const header = /^\[\s*([^\]]+?)\s*\]$/.exec(bare)?.[1];
|
|
142
|
+
if (header !== void 0) {
|
|
143
|
+
table = header.replace(/^(["'])(.*)\1$/, "$2");
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
const found = tomlCpuLines.get(table)?.exec(bare)?.[1];
|
|
147
|
+
if (found !== void 0) return found.replaceAll("_", "");
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
/** A JSONC value's text, when `node` is one and not an object or an array. */
|
|
151
|
+
const rawAt = (node) => node?.kind === "value" ? node.raw : void 0;
|
|
152
|
+
/**
|
|
125
153
|
* What `doctor` reads of a Worker's config, `wrangler.jsonc` or `wrangler.json` as JSONC, and
|
|
126
154
|
* `wrangler.toml`, which `init` writes nothing into, by its lines: its `main`, the Durable Objects
|
|
127
155
|
* it binds, the classes its migrations make, the buckets it binds and the D1 databases it binds
|
|
@@ -191,11 +219,28 @@ const devVars = (names, secret) => ({
|
|
|
191
219
|
secrets: names,
|
|
192
220
|
merge: (current) => withLines(current, names.map((name) => `${name}=${Redacted.value(secret())}`), (line) => line.split("=")[0] ?? "")
|
|
193
221
|
});
|
|
222
|
+
/**
|
|
223
|
+
* The packs' bucket's rule that aborts an upload a day after it began: one a crashed merge left,
|
|
224
|
+
* which no row names, ends no other way (#2226). Alchemy clears every rule its bucket doesn't
|
|
225
|
+
* declare, so it goes in the bucket's line, as `examples/git-alchemy` has it.
|
|
226
|
+
*/
|
|
227
|
+
const abortUploads = [
|
|
228
|
+
" lifecycleRules: [",
|
|
229
|
+
" {",
|
|
230
|
+
" id: \"abort-uploads\",",
|
|
231
|
+
" abortMultipartUploadsTransition: { condition: { type: \"Age\", maxAge: 86_400 } },",
|
|
232
|
+
" },",
|
|
233
|
+
" ],"
|
|
234
|
+
];
|
|
194
235
|
/** Alchemy's lines for Git's part of a Worker's `env`, as the Alchemy guide gives them. */
|
|
195
236
|
const alchemyLines = (choices, _name) => [
|
|
196
237
|
" RECORDS: Cloudflare.DurableObject(\"Records\"),",
|
|
197
238
|
" JOBS: Cloudflare.DurableObject(\"Jobs\"),",
|
|
198
|
-
...choices.objects === "packs" ? [
|
|
239
|
+
...choices.objects === "packs" ? [
|
|
240
|
+
" PACKS: Cloudflare.R2.Bucket(\"Packs\", {",
|
|
241
|
+
...abortUploads,
|
|
242
|
+
" }),"
|
|
243
|
+
] : [],
|
|
199
244
|
" ADMIN_TOKEN: Config.Redacted(\"ADMIN_TOKEN\"),"
|
|
200
245
|
];
|
|
201
246
|
/** The lines a `wrangler.toml` needs, since `init` writes no TOML. */
|
|
@@ -217,11 +262,13 @@ const tomlLines = (choices, name) => [
|
|
|
217
262
|
"new_sqlite_classes = [\"Records\", \"Jobs\"]"
|
|
218
263
|
];
|
|
219
264
|
/** What a Worker's own entry needs, to answer Git's URLs first and export its classes. */
|
|
220
|
-
const entryLines = (
|
|
221
|
-
|
|
265
|
+
const entryLines = (_choices, _name) => [
|
|
266
|
+
"import { Git } from '@ref0/git';",
|
|
267
|
+
"import * as Option from 'effect/Option';",
|
|
268
|
+
"import { runtime } from './git.ts';",
|
|
222
269
|
"export { Jobs, Records } from './git.ts';",
|
|
223
270
|
"// First in its fetch, before its own routes:",
|
|
224
|
-
`const answered = ${
|
|
271
|
+
`const answered = ${routed("request")};`,
|
|
225
272
|
"if (answered !== undefined) return answered;"
|
|
226
273
|
];
|
|
227
274
|
/** The lines each kind of manual step prints. */
|
|
@@ -247,12 +294,12 @@ const entryOf = (choices, layout) => {
|
|
|
247
294
|
};
|
|
248
295
|
case "wrapped": return {
|
|
249
296
|
path: "src/git-entry.ts",
|
|
250
|
-
text: wrappedEntry(
|
|
297
|
+
text: wrappedEntry(layout.main),
|
|
251
298
|
main: "src/git-entry.ts"
|
|
252
299
|
};
|
|
253
300
|
case "start": return {
|
|
254
301
|
path: "src/server.ts",
|
|
255
|
-
text: startEntry
|
|
302
|
+
text: startEntry,
|
|
256
303
|
main: "src/server.ts"
|
|
257
304
|
};
|
|
258
305
|
case "manual":
|
|
@@ -266,9 +313,11 @@ const cloudflareOutput = (choices, project, secret, vendor) => {
|
|
|
266
313
|
const envFile = own ? "env.ts" : "git-env.ts";
|
|
267
314
|
const entry = entryOf(choices, layout);
|
|
268
315
|
const config = project.config?.file ?? "wrangler.jsonc";
|
|
316
|
+
const jsonc = config !== "wrangler.toml" && !(layout.kind === "manual" && layout.why === "alchemy");
|
|
317
|
+
const cpu = project.config === void 0 ? jsonc ? writtenCpu : void 0 : configCpu(project.config.file, project.config.text);
|
|
269
318
|
return {
|
|
270
319
|
files: [
|
|
271
|
-
...
|
|
320
|
+
...jsonc ? [{
|
|
272
321
|
path: config,
|
|
273
322
|
kind: "merge",
|
|
274
323
|
merge: (current) => current === void 0 ? wranglerConfig(choices, name) : mergeWrangler(current, choices, name, entry?.main)
|
|
@@ -281,7 +330,7 @@ const cloudflareOutput = (choices, project, secret, vendor) => {
|
|
|
281
330
|
{
|
|
282
331
|
path: "src/git.ts",
|
|
283
332
|
kind: "whole",
|
|
284
|
-
text: gitModule(choices, `./${envFile}
|
|
333
|
+
text: gitModule(choices, `./${envFile}`, cpu)
|
|
285
334
|
},
|
|
286
335
|
...entry === void 0 ? [] : [{
|
|
287
336
|
path: entry.path,
|
|
@@ -317,4 +366,4 @@ const cloudflareOutput = (choices, project, secret, vendor) => {
|
|
|
317
366
|
next: "Check it, then deploy it"
|
|
318
367
|
};
|
|
319
368
|
};
|
|
320
|
-
export { bucketLine, bucketName, cloudflareOutput, configParts, devVars, gitClasses, gitModule, gitSecrets, looseAdapter, looseInfraImport, mergePackage, mergeWrangler, secretFiles };
|
|
369
|
+
export { bucketLine, bucketName, cloudflareOutput, configCpu, configParts, devVars, gitClasses, gitModule, gitSecrets, limitsLine, looseAdapter, looseInfraImport, mergePackage, mergeWrangler, secretFiles };
|
package/dist/init/create.mjs
CHANGED
|
@@ -10,7 +10,7 @@ import * as Schema from "effect/Schema";
|
|
|
10
10
|
const creators = {
|
|
11
11
|
next: "create-next-app@16.4.6",
|
|
12
12
|
sveltekit: "sv@1.7.1",
|
|
13
|
-
nuxt: "create-nuxt@4.1.
|
|
13
|
+
nuxt: "create-nuxt@4.1.1"
|
|
14
14
|
};
|
|
15
15
|
/** The values `--framework` takes, in the table's order. */
|
|
16
16
|
const creatable = Object.keys(creators);
|
package/dist/init/detect.mjs
CHANGED
|
@@ -53,12 +53,14 @@ const readBack = (text) => {
|
|
|
53
53
|
const vercel = imports("vercel");
|
|
54
54
|
const onNode = !vercel && (imports("node") || imports("sqlite"));
|
|
55
55
|
if (!vercel && !onNode && !imports("cloudflare")) return void 0;
|
|
56
|
-
const
|
|
56
|
+
const app = text.includes("from './signin/auth.ts'");
|
|
57
|
+
const loose = /\bObjects\.layerRecords\(\)/.test(text);
|
|
58
|
+
const queue = text.includes("MergeQueue.layer({ target: 'refs/heads/main', keys: ");
|
|
57
59
|
const shared = {
|
|
58
|
-
serve: text.includes("from '@ref0/github'") ? "github" :
|
|
59
|
-
app:
|
|
60
|
-
queue:
|
|
61
|
-
basePath:
|
|
60
|
+
serve: text.includes("from '@ref0/github'") ? "github" : /^ {2}Rest\.layer\(\),$/m.test(text) ? "api" : "git",
|
|
61
|
+
app: app ? "ref0" : "none",
|
|
62
|
+
queue: queue ? "on" : "off",
|
|
63
|
+
basePath: /\bGit\.layer\(\{ basePath: '([^']*)'/.exec(text)?.[1] ?? "/"
|
|
62
64
|
};
|
|
63
65
|
if (vercel) return {
|
|
64
66
|
...shared,
|
package/dist/init/files.mjs
CHANGED
|
@@ -5,6 +5,11 @@ import * as Predicate from "effect/Predicate";
|
|
|
5
5
|
// src/init/files.ts
|
|
6
6
|
/** The parts that are strings, one a line: a part that's `false` is left out. */
|
|
7
7
|
const lines = (...parts) => parts.filter(Predicate.isString).join("\n");
|
|
8
|
+
/** An import of `names` from `from`, on one line, or one name a line past the formatter's width. */
|
|
9
|
+
const importLine = (names, from) => {
|
|
10
|
+
const line = `import { ${names.join(", ")} } from '${from}';`;
|
|
11
|
+
return line.length <= 100 ? line : lines("import {", ...names.map((name) => ` ${name},`), `} from '${from}';`);
|
|
12
|
+
};
|
|
8
13
|
/** `names` as a sentence lists them: `a, b and c`. */
|
|
9
14
|
const listed = (names) => names.length < 2 ? names.join("") : `${names.slice(0, -1).join(", ")} and ${names[names.length - 1] ?? ""}`;
|
|
10
15
|
/**
|
|
@@ -184,4 +189,4 @@ const withCreatedTypes = (created) => (text) => {
|
|
|
184
189
|
if (created !== true || major >= 22) return text;
|
|
185
190
|
return withValue(text, ["devDependencies", "@types/node"], nodePackages["@types/node"]);
|
|
186
191
|
};
|
|
187
|
-
export { fitted, ignoring, lines, listed, pnpmEntries, pnpmManual, pnpmOverridesOf, served, withCli, withCreatedTypes, withDependencies, withLines, withPnpmOverrides, wroteOf };
|
|
192
|
+
export { fitted, ignoring, importLine, lines, listed, pnpmEntries, pnpmManual, pnpmOverridesOf, served, withCli, withCreatedTypes, withDependencies, withLines, withPnpmOverrides, wroteOf };
|
package/dist/init/git-module.mjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { peerPackages } from "./metadata.mjs";
|
|
2
1
|
import { lines, served } from "./files.mjs";
|
|
2
|
+
import { peerPackages, workerCpuMs } from "./metadata.mjs";
|
|
3
3
|
import { specOf } from "./versions.mjs";
|
|
4
|
+
import * as Predicate from "effect/Predicate";
|
|
4
5
|
import { looseLimits } from "@ref0/git";
|
|
5
6
|
// src/init/git-module.ts
|
|
6
7
|
/**
|
|
7
|
-
* The lines
|
|
8
|
-
*
|
|
8
|
+
* The lines every platform's `src/git.ts` shares, from its imports of Git to its runtime, so each
|
|
9
|
+
* composes Git the same way: Git's features and the drop-in's over `Git.layer`, one runtime.
|
|
9
10
|
*/
|
|
10
11
|
/** Git's packages a setup depends on, at this release. */
|
|
11
12
|
const gitPackages = (choices) => [
|
|
@@ -19,46 +20,102 @@ const gitPackages = (choices) => [
|
|
|
19
20
|
* take at the catalog's version: a project's own `effect` is the one Git's packages run on.
|
|
20
21
|
*/
|
|
21
22
|
const gitDependencies = (choices, vendor) => [...gitPackages(choices).map((each) => [each, specOf(each, vendor)]), ...Object.entries(peerPackages)];
|
|
23
|
+
/** Where a host that serves Git's protocol alone makes its repos: from code, on its runtime. */
|
|
24
|
+
const repoHint = lines("// Nothing here makes a repo over HTTP: make one from code, as", "// `runtime.runPromise(Repos.create({ name: 'acme/app' }))`.");
|
|
22
25
|
/** `src/git.ts`'s first lines: what it serves, on `on`, and whose file it is. */
|
|
23
|
-
const header = (choices, on) => lines(`// Git on ${on}, ${served[choices.serve]}${choices.queue === "on" ? ", with a merge queue on `main`" : ""}. 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" &&
|
|
24
|
-
/** The `@ref0/git`
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
const header = (choices, on) => lines(`// Git on ${on}, ${served[choices.serve]}${choices.queue === "on" ? ", with a merge queue on `main`" : ""}. 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);
|
|
27
|
+
/** The `@ref0/git` names the composition uses, as chosen. */
|
|
28
|
+
const gitNames = (choices) => [
|
|
29
|
+
choices.serve === "github" && "accept",
|
|
30
|
+
"Auth",
|
|
31
|
+
"Git",
|
|
32
|
+
choices.objects === "packs" && "Lfs",
|
|
33
|
+
choices.queue === "on" && "MergeQueue",
|
|
34
|
+
"Merges",
|
|
35
|
+
"Objects",
|
|
36
|
+
"Policy",
|
|
37
|
+
choices.serve !== "git" && "Rest",
|
|
38
|
+
"Tokens"
|
|
39
|
+
].filter(Predicate.isString);
|
|
40
|
+
/** The drop-in's names, under `--serve github`: Releases only beside a bucket. */
|
|
41
|
+
const githubNames = (choices) => [
|
|
42
|
+
"Apps",
|
|
43
|
+
"Deployments",
|
|
44
|
+
"GitHub",
|
|
45
|
+
"GitHubPolicy",
|
|
46
|
+
"Imports",
|
|
47
|
+
"Inbox",
|
|
48
|
+
"People",
|
|
49
|
+
choices.objects === "packs" && "Releases",
|
|
50
|
+
"Search",
|
|
51
|
+
"Streams",
|
|
52
|
+
"Webhooks",
|
|
53
|
+
"defaultPeople"
|
|
54
|
+
].filter(Predicate.isString);
|
|
55
|
+
/** An import of `names` from `from`, as the formatter writes it: on one line where it fits. */
|
|
56
|
+
const namedImport = (names, from) => {
|
|
57
|
+
const line = `import { ${names.join(", ")} } from '${from}';`;
|
|
58
|
+
return line.length <= 100 ? line : `import {\n${names.map((name) => ` ${name},`).join("\n")}\n} from '${from}';`;
|
|
29
59
|
};
|
|
30
60
|
/** Git's imports, from `@ref0/git` to the drop-in. */
|
|
31
|
-
const gitImports = (choices) => lines(
|
|
61
|
+
const gitImports = (choices) => lines(namedImport(gitNames(choices), "@ref0/git"), choices.queue === "on" && "import type { MergeInput, MergePlan } from '@ref0/git';", choices.serve === "github" && lines("import { JoinedCalls } from '@ref0/git/extend';", namedImport(githubNames(choices), "@ref0/github"), "import * as Languages from '@ref0/github/languages';"));
|
|
62
|
+
/** Effect's imports, which the composition is written in. */
|
|
63
|
+
const effectImports = (choices) => lines(choices.serve === "github" && lines("import * as Effect from 'effect/Effect';", "import * as FetchHttpClient from 'effect/http/FetchHttpClient';"), "import * as Layer from 'effect/Layer';", "import * as ManagedRuntime from 'effect/ManagedRuntime';", "import * as Redacted from 'effect/Redacted';");
|
|
32
64
|
/** Who `ADMIN_TOKEN` signs in as. */
|
|
33
65
|
const adminLines = lines("/** Who `ADMIN_TOKEN` signs in as: it makes repos and tokens, and never pushes. */", "const admin = { id: '_admin' };", "");
|
|
34
66
|
/** How the queue writes an entry onto `main`, when there's a queue. */
|
|
35
67
|
const mergeLines = (choices) => choices.queue === "on" && 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,", " },", "});", "");
|
|
36
|
-
/**
|
|
37
|
-
const
|
|
38
|
-
/** What one push may carry into `
|
|
68
|
+
/** Who may do what: the admin's and a visitor's limits, as `Policy` decides them. */
|
|
69
|
+
const policyLines = lines("/**", " * Who may do what: a visitor signs in first, and the admin makes repos and tokens but never", " * pushes.", " */", "const policy = Policy.make(({ caller: { actor }, operation }) => {", " if (actor.anonymous === true) return Policy.reject({ message: 'Sign in first' });", "", " if (actor.id === admin.id && operation.kind === 'push') {", " return Policy.reject({", " message: \"The admin token can't push\",", " hint: 'Make a write token for yourself: npx ref0-git tokens create --help',", " });", " }", "", " return Policy.accept();", "});", "");
|
|
70
|
+
/** What one push may carry into `Objects.layerRecords()`, as `@ref0/git` holds it. */
|
|
39
71
|
const looseSays = `up to ${looseLimits.objects.toLocaleString("en-US")} objects and ${looseLimits.bytes / 1024 / 1024} MiB a push`;
|
|
40
|
-
/**
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
72
|
+
/** What a Worker `init` writes its config whole for: `workerCpuMs`, in `wrangler.jsonc`. */
|
|
73
|
+
const writtenCpu = {
|
|
74
|
+
ms: workerCpuMs,
|
|
75
|
+
file: "wrangler.jsonc"
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* `Lfs.layer`'s line at `indent`, with its comment: on a Worker whose config sets `limits.cpu_ms`,
|
|
79
|
+
* its uploads held to that `cpu`, and elsewhere to what the adapter says its platform gives.
|
|
80
|
+
*/
|
|
81
|
+
const lfsLines = (indent, cpu) => cpu === void 0 ? `${indent}// Git LFS, its objects in the bucket beside the packs.\n${indent}Lfs.layer(),` : lines(`${indent}// Git LFS, its objects in the bucket beside the packs. An upload through the Worker may use`, `${indent}// \`limits.cpu_ms\` from ${cpu.file}: raise both together.`, `${indent}Lfs.layer({ cpuMs: ${cpu.ms.toLocaleString("en-US").replaceAll(",", "_")} }),`);
|
|
48
82
|
/**
|
|
49
83
|
* The queue's line: under the drop-in, a pull request's key merges once, so a push to it after its
|
|
50
84
|
* merge isn't queued again before the drop-in sees the merge.
|
|
51
85
|
*/
|
|
52
|
-
const queueLine = (github) => `
|
|
53
|
-
/**
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
86
|
+
const queueLine = (github) => ` MergeQueue.layer({ target: 'refs/heads/main', keys: '${github ? "once" : "reusable"}', merge }),`;
|
|
87
|
+
/** Git's own features, `features`: REST, Git LFS and the queue as chosen, over tokens and merges. */
|
|
88
|
+
const gitFeatures = (choices, parts) => {
|
|
89
|
+
const each = [
|
|
90
|
+
choices.serve !== "git" && " // Git's REST, beside Git's protocol and sign-in.\n Rest.layer(),",
|
|
91
|
+
choices.objects === "packs" && lfsLines(" ", parts.cpu),
|
|
92
|
+
parts.uploads,
|
|
93
|
+
choices.queue === "on" && queueLine(choices.serve === "github")
|
|
94
|
+
].filter(Predicate.isString);
|
|
95
|
+
const merges = `Layer.provideMerge(Merges.layer(${parts.merges}))`;
|
|
96
|
+
const below = `).pipe(Layer.provideMerge(Tokens.layer()), ${merges});`;
|
|
97
|
+
return lines("/** Git's features, each a line: delete one to turn it off. */", each.length === 0 ? `const features = Tokens.layer().pipe(Layer.provideMerge(Merges.layer(${parts.merges})));` : lines("const features = Layer.mergeAll(", ...each, below.length <= 100 ? below : `).pipe(\n Layer.provideMerge(Tokens.layer()),\n ${merges},\n);`), "");
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* The directive that lets the next line call an unstable Effect API, as the app's `src/git.ts`
|
|
101
|
+
* writes it. Joined as it runs, since its text whole in this file is a directive of this file's.
|
|
102
|
+
*/
|
|
103
|
+
const unstableNextLine = ["// @effect", "diagnostics-next-line unstableApiUsage:off"].join("-");
|
|
104
|
+
/** The drop-in over Git's features, under `--serve github`: each of its features a line too. */
|
|
105
|
+
const githubFeatures = (choices) => lines("/**", " * GitHub's REST, GraphQL, webhooks and Event Streams over Git's, so `gh` and Octokit work, and", " * the drop-in's features, each a line: delete one to turn it off.", " */", "const github = Layer.mergeAll(", " Inbox.layer(),", " Deployments.layer(),", " // Without it, a repo's `language` and `license` answer null.", " Languages.layer(),", " // Repo and user search, and `org:` and `user:` search over an owner's public repos.", " Search.layer(),", " // A repo's and an org's hooks, each delivery a `fetch`, and GitHub Apps, whose hooks they send.", " Layer.provideMerge(Apps.layer(), Webhooks.layer()),", " // GitHub's Event Streams over Git's event feeds.", " Streams.layer(),", " // A repo's import from GitHub, its releases among it.", " Imports.layer(),", ").pipe(", choices.objects === "packs" && " // A release's assets, in the bucket beside the packs.\n Layer.provideMerge(Releases.layer()),", " Layer.provideMerge(GitHub.layer()),", " // The drop-in's own permissions narrow nothing past `policy`'s.", " Layer.provideMerge(GitHubPolicy.layer(GitHubPolicy.make(() => Effect.succeed(accept())))),", " // Who's who, by login, from Git's own records.", " Layer.provideMerge(", " People.layer(", " Effect.map(Effect.service(JoinedCalls), (joined) =>", " defaultPeople({ git: joined.effectHostCalls }),", " ),", " ),", " ),", " Layer.provideMerge(features),", " // A webhook's deliveries and an import's calls to GitHub, each the platform's `fetch`.", ` ${unstableNextLine}`, " Layer.provide(FetchHttpClient.layer),", ");", "");
|
|
106
|
+
/** Git's features, and the drop-in's over them under `--serve github`. */
|
|
107
|
+
const featuresLines = (choices, parts) => lines(gitFeatures(choices, parts), choices.serve === "github" && githubFeatures(choices));
|
|
108
|
+
/**
|
|
109
|
+
* `Git.layer`'s options: Git's URLs under the base path, when there's one, and the platform's
|
|
110
|
+
* `maxDuration`, when it sets one.
|
|
111
|
+
*/
|
|
112
|
+
const gitOptions = (choices, maxDuration) => {
|
|
113
|
+
const options = [choices.basePath !== "/" && `basePath: '${choices.basePath.replace(/\/$/, "")}'`, maxDuration !== void 0 && `maxDuration: '${maxDuration} seconds'`].filter(Predicate.isString);
|
|
114
|
+
return options.length === 0 ? "{}" : `{ ${options.join(", ")} }`;
|
|
115
|
+
};
|
|
59
116
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
117
|
+
* The admin's sign-in, then `export const runtime`: the whole host, Git with its features over the
|
|
118
|
+
* adapter, one runtime that every entry, object and job runner takes.
|
|
62
119
|
*/
|
|
63
|
-
const
|
|
64
|
-
export { adminLines,
|
|
120
|
+
const runtimeLines = (choices, parts) => lines("/** The admin's sign-in: `ADMIN_TOKEN`, as a Bearer token or as Basic's password. */", `const auth = Auth.bearer({ token: Redacted.make(${parts.token}), actor: admin });`, "", "/**", " * The whole host, one runtime that every request and job shares: Git and its features over the", " * adapter, deciding with `policy`, and the admin signing in with `auth`.", parts.jobs !== void 0 && ` * ${parts.jobs}`, " */", "export const runtime = ManagedRuntime.make(", parts.maxDuration !== void 0 && lines(" // The functions' `maxDuration`, from `vercel.json`: a clone that would outrun it ends first,", " // with Git's own message."), ` Git.layer(${gitOptions(choices, parts.maxDuration)}, ${choices.serve === "github" ? "github" : "features"}).pipe(`, " Layer.provide(Policy.layer(policy)),", " Layer.provide(Auth.layer(auth)),", choices.objects === "packs" ? " Layer.provide(Objects.layer())," : ` // Each object a row in its push's commit: no bucket, ${looseSays}.\n Layer.provide(Objects.layerRecords()),`, ` Layer.provideMerge(${parts.adapter}),`, " ),", ");", "");
|
|
121
|
+
export { adminLines, effectImports, featuresLines, gitDependencies, gitImports, gitPackages, header, lfsLines, looseSays, mergeLines, policyLines, queueLine, repoHint, runtimeLines, writtenCpu };
|
package/dist/init/metadata.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/init/metadata.ts
|
|
2
2
|
/** The version `ref0-git`, `create-ref0-git` and Git's packages release at, all at once (Q738). */
|
|
3
|
-
const release = "0.
|
|
3
|
+
const release = "0.8.0";
|
|
4
4
|
/** The packages the app depends on, by their folder in a checkout's `packages/`. */
|
|
5
5
|
const appPackages = [
|
|
6
6
|
"infra",
|
|
@@ -10,19 +10,19 @@ const appPackages = [
|
|
|
10
10
|
];
|
|
11
11
|
/** What every platform's project builds and types with. At the root workspace's catalog. */
|
|
12
12
|
const catalog = {
|
|
13
|
-
"@cloudflare/workers-types": "5.
|
|
13
|
+
"@cloudflare/workers-types": "5.20261123.1",
|
|
14
14
|
typescript: "7.0.2",
|
|
15
|
-
wrangler: "4.
|
|
15
|
+
wrangler: "4.168.0"
|
|
16
16
|
};
|
|
17
17
|
/** What Git on Vercel installs beside Git's packages. At the root workspace's catalog. */
|
|
18
18
|
const vercelPackages = {
|
|
19
|
-
"@types/node": "24.19.
|
|
19
|
+
"@types/node": "24.19.4",
|
|
20
20
|
"@vercel/blob": "2.9.0",
|
|
21
21
|
"@vercel/queue": "0.11.0",
|
|
22
22
|
typescript: "7.0.2"
|
|
23
23
|
};
|
|
24
24
|
/** What Git on Node type-checks with beside the store's client. At the root workspace's catalog. */
|
|
25
|
-
const nodePackages = { "@types/node": "24.19.
|
|
25
|
+
const nodePackages = { "@types/node": "24.19.4" };
|
|
26
26
|
/**
|
|
27
27
|
* What the app on Node builds and reads its people with, beside the store's client (Q-IN14). At the
|
|
28
28
|
* root workspace's catalog.
|
|
@@ -44,11 +44,16 @@ const storePackages = {
|
|
|
44
44
|
* What Git's packages take as peers, which every project installs beside them (Q1086). At the root
|
|
45
45
|
* workspace's catalog.
|
|
46
46
|
*/
|
|
47
|
-
const peerPackages = { effect: "4.1.
|
|
47
|
+
const peerPackages = { effect: "4.1.7" };
|
|
48
48
|
/**
|
|
49
49
|
* What a framework's Node server needs that its create command doesn't write: SvelteKit's
|
|
50
50
|
* adapter-node, in place of `sv create`'s adapter-auto. At the framework fixtures' own catalog,
|
|
51
51
|
* which differs from the root's.
|
|
52
52
|
*/
|
|
53
53
|
const frameworkPackages = { "@sveltejs/adapter-node": "6.0.5" };
|
|
54
|
-
|
|
54
|
+
/**
|
|
55
|
+
* The CPU a Worker's request may use, in ms: the app's and the example's `limits.cpu_ms`, which
|
|
56
|
+
* their `Lfs.layer` takes too.
|
|
57
|
+
*/
|
|
58
|
+
const workerCpuMs = 3e5;
|
|
59
|
+
export { appPackages, catalog, frameworkPackages, nodeAppPackages, nodePackages, peerPackages, release, storePackages, vercelPackages, workerCpuMs };
|