ref0-git 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/app/apps/github/README.md +3 -7
  2. package/app/apps/github/generated/git-rest.ts +17 -20
  3. package/app/apps/github/src/clients/allowed.ts +7 -9
  4. package/app/apps/github/src/clients/avatars.ts +5 -3
  5. package/app/apps/github/src/clients/graphql.ts +12 -2
  6. package/app/apps/github/src/clients/host-calls.ts +2 -1
  7. package/app/apps/github/src/clients/transfers.ts +56 -19
  8. package/app/apps/github/src/components/signin/device-card.tsx +2 -2
  9. package/app/apps/github/src/context/context.ts +5 -5
  10. package/app/apps/github/src/context/host.ts +115 -0
  11. package/app/apps/github/src/ingress.ts +28 -0
  12. package/app/apps/github/src/policy.ts +113 -78
  13. package/app/apps/github/src/private-repos.ts +7 -7
  14. package/app/apps/github/src/pulls/review.ts +2 -1
  15. package/app/apps/github/src/releases/release-form.tsx +40 -4
  16. package/app/apps/github/src/releases/releases.ts +148 -22
  17. package/app/apps/github/src/routes/uploads/$owner/$repo/$release.tsx +9 -2
  18. package/app/apps/github/src/seed/seed.ts +68 -38
  19. package/app/apps/github/src/server.ts +28 -11
  20. package/app/apps/github/src/signin/approval.ts +20 -15
  21. package/app/apps/github/src/signin/attempts.ts +306 -0
  22. package/app/apps/github/src/signin/auth.ts +9 -0
  23. package/app/apps/github/src/signin/device-code.ts +2 -2
  24. package/app/apps/github/src/signin/device-prompt.ts +6 -6
  25. package/app/apps/github/src/signin/host-session.ts +30 -18
  26. package/app/apps/github/src/signin/limits.ts +35 -0
  27. package/app/pnpm-workspace.yaml +39 -38
  28. package/dist/cli/events.mjs +10 -13
  29. package/dist/cli/failure.mjs +4 -10
  30. package/dist/cli/hosts.mjs +2 -2
  31. package/dist/cli/queue.mjs +14 -23
  32. package/dist/cli/repos.mjs +10 -19
  33. package/dist/cli/resources.mjs +2 -2
  34. package/dist/cli/setup.mjs +33 -40
  35. package/dist/cli/sign-in.mjs +4 -4
  36. package/dist/cli/tokens.mjs +7 -11
  37. package/dist/cli/vendor.mjs +21 -1
  38. package/dist/init/app.mjs +45 -23
  39. package/dist/init/astro.mjs +2 -2
  40. package/dist/init/cloudflare.mjs +100 -51
  41. package/dist/init/create.mjs +1 -1
  42. package/dist/init/detect.mjs +7 -5
  43. package/dist/init/files.mjs +6 -1
  44. package/dist/init/git-module.mjs +89 -32
  45. package/dist/init/metadata.mjs +12 -7
  46. package/dist/init/mounts.mjs +12 -20
  47. package/dist/init/next.mjs +1 -1
  48. package/dist/init/node-app.mjs +5 -2
  49. package/dist/init/node.mjs +24 -35
  50. package/dist/init/nuxt.mjs +6 -7
  51. package/dist/init/react-router.mjs +2 -2
  52. package/dist/init/routes.mjs +13 -22
  53. package/dist/init/stores.mjs +3 -2
  54. package/dist/init/sveltekit.mjs +3 -3
  55. package/dist/init/template.mjs +14 -15
  56. package/dist/init/templates.mjs +76 -81
  57. package/dist/init/vercel.mjs +18 -22
  58. package/dist/init/versions.mjs +32 -4
  59. package/package.json +13 -13
@@ -7,6 +7,7 @@ import { pnpmManual, withPnpmOverrides, wroteOf } from "../init/files.mjs";
7
7
  import { keepsData, mainOrigin, nodeNeeds, routed, routedFindings } from "../init/node.mjs";
8
8
  import { detect } from "../init/detect.mjs";
9
9
  import { outputOf as outputOf$1, secretFilesOf } from "../init/output.mjs";
10
+ import { appPackages, peerPackages, release } from "../init/metadata.mjs";
10
11
  import { detectFrameworks, frameworkFor, newFramework, othersRow } from "../init/frameworks.mjs";
11
12
  import { creatable, createCommand, createFailed, createPlatforms, created, creatorFolder, creators } from "../init/create.mjs";
12
13
  import { nuxtFindings, nuxtJobsPlugin } from "../init/nuxt.mjs";
@@ -15,13 +16,13 @@ import { svelteBodyLimit, svelteStart } from "../init/sveltekit.mjs";
15
16
  import { variablesOf, vercelProblems } from "../init/vercel.mjs";
16
17
  import { addedTo, plan } from "../init/plan.mjs";
17
18
  import { dropInPrefixes } from "../init/routes.mjs";
18
- import { appPackages, peerPackages, release } from "../init/metadata.mjs";
19
+ import { contentNamed, published, unpacked } from "../init/versions.mjs";
19
20
  import { catalogOf } from "../init/workspace.mjs";
20
21
  import { doctorJson, initJson, verifyJson } from "./documents.mjs";
21
22
  import { CliFailure, cancelled, diskFailed, failure, leftBehind, refused, usageFailure } from "./failure.mjs";
22
23
  import { chosenHost, hostFlag, remoteOf } from "./hosts.mjs";
23
24
  import { runChild, stopMs } from "./child.mjs";
24
- import { vendored } from "./vendor.mjs";
25
+ import { outdated, vendored } from "./vendor.mjs";
25
26
  import { Folders } from "./folders.mjs";
26
27
  import { gitRun } from "./git.mjs";
27
28
  import { node } from "./node.mjs";
@@ -38,8 +39,8 @@ import * as Option from "effect/Option";
38
39
  import * as Command from "effect/cli/Command";
39
40
  import * as Schema from "effect/Schema";
40
41
  import * as Flag from "effect/cli/Flag";
41
- import * as Argument from "effect/cli/Argument";
42
42
  import { shortTarget } from "@ref0/git";
43
+ import * as Argument from "effect/cli/Argument";
43
44
  import * as Clock from "effect/Clock";
44
45
  import * as FileSystem from "effect/FileSystem";
45
46
  import * as Path from "effect/Path";
@@ -234,11 +235,6 @@ const sourceOf = /* @__PURE__ */ Effect.fnUntraced(function* (fromCheckout, appC
234
235
  checkout: void 0
235
236
  };
236
237
  });
237
- /**
238
- * A version npm publishes: semver 2.0.0's own, `MAJOR.MINOR.PATCH` with an optional prerelease and
239
- * build, no leading `v` or `=` and no space, as `semver.valid` takes one without `loose`.
240
- */
241
- const published = /^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(?:\+[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*)?$/u;
242
238
  /** The tarball `pnpm pack --json` says it made: its package's name and version, and its file. */
243
239
  const readPacked = /* @__PURE__ */ Schema.decodeUnknownEffect(Schema.fromJsonString(Schema.Struct({
244
240
  name: Schema.String,
@@ -257,7 +253,8 @@ const lastObject = (printed) => {
257
253
  const readVersion = /* @__PURE__ */ Schema.decodeUnknownEffect(Schema.fromJsonString(Schema.Struct({ version: Schema.String })));
258
254
  /**
259
255
  * The tarballs a pack of `checkout` would make, from its own manifests' versions, named as `pnpm
260
- * pack` names them: what a dry run, which packs nothing, says `init` would write.
256
+ * pack` names them, with `unpacked` for the hash of bytes it never made: what a dry run, which packs
257
+ * nothing, says `init` would write.
261
258
  */
262
259
  const plannedVendor = /* @__PURE__ */ Effect.fnUntraced(function* (checkout) {
263
260
  const fs = yield* FileSystem.FileSystem;
@@ -265,7 +262,8 @@ const plannedVendor = /* @__PURE__ */ Effect.fnUntraced(function* (checkout) {
265
262
  for (const each of vendorPacks) {
266
263
  const at = `${checkout}/packages/${each.folder}/package.json`;
267
264
  const { version } = yield* readVersion(yield* fs.readFileString(at)).pipe(Effect.mapError(() => usageFailure("invalid_manifest", `${printable(at)} has no version init can read`)));
268
- vendor.set(each.name, `${each.into}/${each.name.replace("@", "").replace("/", "-")}-${version}.tgz`);
265
+ const file = `${each.name.replace("@", "").replace("/", "-")}-${version}.tgz`;
266
+ vendor.set(each.name, `${each.into}/${contentNamed(file, unpacked)}`);
269
267
  }
270
268
  return vendor;
271
269
  }, (reading, checkout) => Effect.catchTag(reading, "PlatformError", (error) => Effect.fail(diskFailed(`read the package manifests in ${printable(checkout)}`)(error))));
@@ -357,7 +355,11 @@ const packedInto = /* @__PURE__ */ Effect.fnUntraced(function* (checkout, folder
357
355
  kind: "failed",
358
356
  why: `pnpm pack in ${where} made ${file} at version ${made.value.version}, which isn't a version npm publishes: npm takes semver's MAJOR.MINOR.PATCH, with no leading v or =`
359
357
  };
360
- vendor.set(each.name, `${each.into}/${file}`);
358
+ const bytes = yield* fs.readFile(`${destination}/${file}`).pipe(Effect.mapError(diskFailed(`read ${printable(`${destination}/${file}`)}`)));
359
+ const sha256 = yield* Effect.promise(() => crypto.subtle.digest("SHA-256", new Uint8Array(bytes)));
360
+ const named = contentNamed(file, new Uint8Array(sha256));
361
+ yield* fs.rename(`${destination}/${file}`, `${destination}/${named}`).pipe(Effect.mapError(diskFailed(`name ${printable(`${destination}/${file}`)}`)));
362
+ vendor.set(each.name, `${each.into}/${named}`);
361
363
  }
362
364
  return {
363
365
  kind: "packed",
@@ -564,6 +566,7 @@ const finish = /* @__PURE__ */ Effect.fnUntraced(function* (flags, folder, proje
564
566
  run: [asRun()]
565
567
  });
566
568
  const wrote = yield* written(folder.path, steps);
569
+ if (packed !== void 0) yield* outdated(packed, folder.path);
567
570
  const kept = wroteOf(wrote, settled.app.value === "ref0");
568
571
  const installStep = {
569
572
  says: `Run \`${manager} install\` in ${printable(folder.path)}, then check it`,
@@ -862,7 +865,8 @@ const init = Command.make("init", {
862
865
  }, made.project, source, vendor, pnpm);
863
866
  const steps = plan(output.files, held?.files, made.view.read);
864
867
  const links = [];
865
- for (const step of steps) if (yield* linked(folder.path, step.path)) links.push(step.path);
868
+ const vendorFolders = new Set([...vendor?.values() ?? []].map((at) => at.slice(0, at.lastIndexOf("/"))));
869
+ for (const at of [...steps.map((step) => step.path), ...vendorFolders]) if (yield* linked(folder.path, at)) links.push(at);
866
870
  if (links.length > 0) return yield* failure("file_is_link", `${links.join(", ")} ${links.length === 1 ? "is a link" : "are links"}, and init reads and writes only the folder's own files`, {
867
871
  says: "Replace each with the file itself, then run init again",
868
872
  run: [asRun()]
@@ -890,11 +894,10 @@ const leftoversShown = 50;
890
894
  * leaves, so a host that's run `--verify` often still names what's left. The check has passed by
891
895
  * the time it lists them, so a listing that fails is said, not the run's failure.
892
896
  */
893
- const leftovers = (host, client) => cutAnswer(host, (signal) => client.repos.list({
897
+ const leftovers = (host, client) => cutAnswer(host, client.repos.list({
894
898
  prefix: scratchPrefix,
895
899
  order: "newest",
896
- page: { limit: leftoversShown },
897
- signal
900
+ page: { limit: leftoversShown }
898
901
  })).pipe(Effect.match({
899
902
  onSuccess: (page) => {
900
903
  const names = page.items.map(printable);
@@ -931,17 +934,14 @@ const leftoversRow = (host, found) => {
931
934
  };
932
935
  /**
933
936
  * The host's answer to `call`, given up after `callMs` on Effect's `Clock` as well as on the
934
- * run's cancel, or its failure as the CLI's: a cut interrupts `tryPromise` (aborting `signal`) and
935
- * fails `deadline_exceeded`, a refusal is the host's own, and any other failure `unreachable`, so
936
- * every `--verify` call says a stalled host in the same words.
937
+ * run's cancel, or its failure as the CLI's: a cut interrupts the call and fails
938
+ * `deadline_exceeded`, a refusal is the host's own, and a defect `unreachable`, so every
939
+ * `--verify` call says a stalled host in the same words.
937
940
  */
938
- const cutAnswer = (host, call) => Effect.tryPromise({
939
- try: (signal) => call(signal),
940
- catch: () => failure("unreachable", `Couldn't reach ${host}`)
941
- }).pipe(Effect.timeoutOrElse({
941
+ const cutAnswer = (host, call) => call.pipe(Effect.mapError((error) => refused(error, host)), Effect.catchDefect(() => Effect.fail(failure("unreachable", `Couldn't reach ${host}`))), Effect.timeoutOrElse({
942
942
  duration: callMs,
943
943
  orElse: () => Effect.fail(failure("deadline_exceeded", `${host} didn't answer in ${callMs / 1e3}s`))
944
- }), Effect.flatMap((answer) => answer.kind === "error" ? Effect.fail(refused(answer.error, host)) : Effect.succeed(answer.value)));
944
+ }));
945
945
  /** A create's failures that don't say the host made nothing: no answer, or its own failure. */
946
946
  const unsettled = /^(unreachable|unavailable|deadline_exceeded|internal|data_loss)$/;
947
947
  /**
@@ -971,18 +971,14 @@ const verify = /* @__PURE__ */ Effect.fnUntraced(function* (hostOption) {
971
971
  }), (ran) => ran.status === 0 ? Effect.succeed(ran.stdout) : Effect.fail(failure("verify_git", `git ${args[0] ?? ""} failed against ${host}`)));
972
972
  const work = Effect.gen(function* () {
973
973
  made.repo = true;
974
- const created = yield* cutAnswer(host, (signal) => client.repos.create({
975
- name: repo,
976
- signal
977
- })).pipe(Effect.tapError((failed) => Effect.sync(() => made.repo = unsettled.test(failed.reason))));
974
+ const created = yield* cutAnswer(host, client.repos.create({ name: repo })).pipe(Effect.tapError((failed) => Effect.sync(() => made.repo = unsettled.test(failed.reason))));
978
975
  made.created = true;
979
976
  steps.push("Created");
980
977
  made.tokenSent = true;
981
- const token = yield* cutAnswer(host, (signal) => client.tokens.create(repo, {
978
+ const token = yield* cutAnswer(host, client.tokens.create(repo, {
982
979
  scope: "write",
983
980
  subject: { id: "ref0-git-verify" },
984
- expiresAt: now + 36e5,
985
- signal
981
+ expiresAt: now + 36e5
986
982
  })).pipe(Effect.tapError((failed) => Effect.sync(() => made.tokenSent = unsettled.test(failed.reason))));
987
983
  made.token = token.id;
988
984
  secrets.hide(token.secret);
@@ -1042,10 +1038,7 @@ const verify = /* @__PURE__ */ Effect.fnUntraced(function* (hostOption) {
1042
1038
  "rev-parse",
1043
1039
  "HEAD"
1044
1040
  ])).trim();
1045
- const read = yield* cutAnswer(host, (signal) => client.refs.get(repo, {
1046
- ref: target,
1047
- signal
1048
- }));
1041
+ const read = yield* cutAnswer(host, client.refs.get(repo, { ref: target }));
1049
1042
  if (read.oid !== head) return yield* failure("verify_read", `${host} read back ${printable(read.oid)}, not the pushed ${head}`);
1050
1043
  steps.push("read");
1051
1044
  yield* run([
@@ -1064,19 +1057,19 @@ const verify = /* @__PURE__ */ Effect.fnUntraced(function* (hostOption) {
1064
1057
  steps.push("cloned");
1065
1058
  });
1066
1059
  /** Whether `call` removed `what` in time, or found it gone where `gone` says that's settled. */
1067
- const removed = (what, call, gone = true) => Effect.tryPromise((signal) => call(signal)).pipe(Effect.map((done) => done.kind === "success" || gone && done.error.code === "NOT_FOUND"), Effect.timeoutOrElse({
1060
+ const removed = (what, call, gone = true) => call.pipe(Effect.as(true), Effect.catch((error) => Effect.succeed(gone && error.code === "NOT_FOUND")), Effect.catchDefect(() => Effect.succeed(false)), Effect.timeoutOrElse({
1068
1061
  duration: callMs,
1069
1062
  orElse: () => Effect.succeed(false)
1070
- }), Effect.orElseSucceed(() => false), Effect.tap((done) => done ? Effect.void : Effect.sync(() => left.push(what))));
1063
+ }), Effect.tap((done) => done ? Effect.void : Effect.sync(() => left.push(what))));
1071
1064
  const cleanUpFailed = (headline) => failure("cleanup_failed", `${headline}, and may have left ${left.join(" and ")}`, {
1072
1065
  says: `Check ${host} for it: a later \`doctor --verify\` lists scratch repos under Leftovers`,
1073
1066
  run: []
1074
1067
  });
1075
1068
  const cleanUp = Effect.gen(function* () {
1076
1069
  const token = made.token;
1077
- if (token !== "") yield* removed(`token ${token}`, (signal) => client.tokens.revoke(token, { signal }));
1070
+ if (token !== "") yield* removed(`token ${token}`, client.tokens.revoke(token, {}));
1078
1071
  else if (made.tokenSent) left.push(`the token on ${repo}, which ends within the hour`);
1079
- const deleted = (signal) => client.repos.delete(repo, { signal });
1072
+ const deleted = client.repos.delete(repo, {});
1080
1073
  if (made.repo && (yield* removed(repo, deleted, made.created))) steps.push("deleted");
1081
1074
  yield* fs.remove(folder, {
1082
1075
  recursive: true,
@@ -1258,7 +1251,7 @@ const nodeFindings = (view, project, chosen, disk, source) => {
1258
1251
  const { sources } = disk;
1259
1252
  const entry = sources.find((file) => {
1260
1253
  const text = file === "git.ts" ? "" : view.read(`src/${file}`) ?? "";
1261
- return /from ['"]\.\/git\.ts['"]/.test(text) && /\b(?:toNode(?:Handler|Middleware)|(?:serve|rest|git)\.fetch)\(/.test(text) && /\btoJobRunner\(/.test(text);
1254
+ return /from ['"]\.\/git\.ts['"]/.test(text) && /\b(?:toNode(?:Handler|Middleware)|toFetch)\(/.test(text) && /\btoJobRunner\(/.test(text);
1262
1255
  });
1263
1256
  const framework = project.framework;
1264
1257
  const starter = framework === void 0 ? void 0 : startersOf(framework);
@@ -1402,7 +1395,7 @@ const findingsOf = (view, project, chosen, disk, source) => {
1402
1395
  const classesBound = gitClasses.every((each) => bindings.includes(each.name) && made.includes(each.class_name));
1403
1396
  const entry = main === void 0 ? "" : view.read(main) ?? "";
1404
1397
  const exported = gitClasses.every(({ class_name: name }) => new RegExp(`export\\s+(const|class|\\{[^}]*)\\s*\\b${name}\\b`).test(entry));
1405
- const routed = /from ['"]\.\/git\.ts['"]/.test(entry) && /\b(github|rest|git)\.(route|fetch)\b/.test(entry);
1398
+ const routed = /from ['"]\.\/git\.ts['"]/.test(entry) && /\bGit\.(?:toFetch|route)\(|\bingressOf\(\{[^}]*\bgit\b/.test(entry);
1406
1399
  const packs = chosen.objects === "packs";
1407
1400
  const bucketBound = buckets.includes("PACKS");
1408
1401
  const vars = devVars(view);
@@ -14,7 +14,7 @@ import * as Schema from "effect/Schema";
14
14
  import * as Duration from "effect/Duration";
15
15
  import * as DateTime from "effect/DateTime";
16
16
  import * as Flag from "effect/cli/Flag";
17
- import { createRestClient } from "@ref0/git/rest";
17
+ import { RestClient } from "@ref0/git";
18
18
  import * as Argument from "effect/cli/Argument";
19
19
  import * as Clock from "effect/Clock";
20
20
  import * as Result from "effect/Result";
@@ -127,10 +127,10 @@ const tokenFromStdin = /* @__PURE__ */ Effect.fnUntraced(function* (host) {
127
127
  return Result.isSuccess(read) ? read.success : yield* usageFailure("token_unreadable", read.failure.message, "Pipe in one token, on one line");
128
128
  });
129
129
  /** Who `token` signs in on the host, as `GET /me` answers. */
130
- const meWith = (host, token) => answered(hostName(host), (signal) => createRestClient({
130
+ const meWith = (host, token) => answered(hostName(host), Effect.flatMap(RestClient.make({
131
131
  url: host.endpoint,
132
132
  credentials: { token: Redacted.value(token) }
133
- }).me({ signal }));
133
+ }), (client) => client.me()));
134
134
  /** A token's coverage and scope, as a person reads it. */
135
135
  const coverage = (token) => token.repo !== void 0 ? `${token.scope} on ${printable(token.repo)}` : token.prefix === "" ? `${token.scope} on every repo` : `${token.scope} on ${printable(token.prefix)}*`;
136
136
  /** The sign-in group's commands, at the top of the tree. */
@@ -185,7 +185,7 @@ const signInCommands = [
185
185
  })).pipe(Command.withDescription("Remove the stored token (experimental)")),
186
186
  Command.make("whoami", { host: hostFlag }, /* @__PURE__ */ Effect.fnUntraced(function* ({ host }) {
187
187
  const remote = yield* remoteOf(yield* chosenHost(host));
188
- const me = yield* answered(remote.host, (signal) => remote.client.me({ signal }));
188
+ const me = yield* answered(remote.host, remote.client.me());
189
189
  if ((yield* CliModes).json) return yield* document(me);
190
190
  const token = me.token;
191
191
  const rows = [
@@ -7,7 +7,7 @@ import * as Redacted from "effect/Redacted";
7
7
  import * as Option from "effect/Option";
8
8
  import * as Command from "effect/cli/Command";
9
9
  import * as Flag from "effect/cli/Flag";
10
- import { tokenScopes, tokenStates } from "@ref0/git/rest";
10
+ import { tokenScopes, tokenStates } from "@ref0/git";
11
11
  import * as Argument from "effect/cli/Argument";
12
12
  import * as Clock from "effect/Clock";
13
13
  // src/cli/tokens.ts
@@ -32,7 +32,7 @@ const create = Command.make("create", {
32
32
  ...coverageFlags,
33
33
  host: hostFlag,
34
34
  subject: Flag.String("subject").pipe(Flag.withDescription("Who the token is for: the actor it signs in as"), Flag.withMetavar("ID")),
35
- scope: Flag.Literals("scope", tokenScopes).pipe(Flag.withDescription("What it may do: read, report a check, or write"), Flag.withDefault("read")),
35
+ scope: Flag.Literals("scope", tokenScopes).pipe(Flag.withDescription("What it may do: read, report a check, write, or admin, every repo with --prefix ''"), Flag.withDefault("read")),
36
36
  expires: Flag.String("expires").pipe(Flag.withDescription("How long until it expires, as 12h or 90d"), Flag.withMetavar("DURATION"), Flag.withDefault("30d")),
37
37
  showToken: Flag.Boolean("show-token").pipe(Flag.withDescription("Print the token on stdout, the only way to get it"), Flag.withDefault(false))
38
38
  }, /* @__PURE__ */ Effect.fnUntraced(function* (flags) {
@@ -65,11 +65,10 @@ const create = Command.make("create", {
65
65
  });
66
66
  }
67
67
  const now = yield* Clock.currentTimeMillis;
68
- const made = yield* called(flags.host, (client, signal) => client.tokens.create(target, {
68
+ const made = yield* called(flags.host, (client) => client.tokens.create(target, {
69
69
  scope: flags.scope,
70
70
  expiresAt: now + lasts,
71
- subject: { id: flags.subject },
72
- signal
71
+ subject: { id: flags.subject }
73
72
  }));
74
73
  const { secret: received, ...record } = made.value;
75
74
  const secret = Redacted.make(received);
@@ -111,11 +110,8 @@ const list = Command.make("list", {
111
110
  ...["--host", host],
112
111
  ...state === void 0 ? [] : ["--state", state]
113
112
  ];
114
- const read = yield* pagesOf(flags.host, flags, command, tokenLine, (client, page, signal) => {
115
- const input = {
116
- page,
117
- signal
118
- };
113
+ const read = yield* pagesOf(flags.host, flags, command, tokenLine, (client, page) => {
114
+ const input = { page };
119
115
  if (state !== void 0) input.state = state;
120
116
  return client.tokens.list(target, input);
121
117
  });
@@ -130,7 +126,7 @@ const revoke = Command.make("revoke", {
130
126
  token: Argument.String("TOKEN").pipe(Argument.withDescription("The token's ID, as tokens list prints it")),
131
127
  host: hostFlag
132
128
  }, /* @__PURE__ */ Effect.fnUntraced(function* (flags) {
133
- const done = yield* called(flags.host, (client, signal) => client.tokens.revoke(flags.token, { signal }));
129
+ const done = yield* called(flags.host, (client) => client.tokens.revoke(flags.token, {}));
134
130
  yield* changed({}, flags.token, { done: `Revoked token ${printable(flags.token)} on ${done.host}` });
135
131
  })).pipe(Command.withDescription("Revoke a token, so it signs nothing in again"));
136
132
  const tokensCommand = Command.make("tokens").pipe(Command.withDescription("The host's tokens (experimental)"), Command.withSubcommands([
@@ -1,3 +1,4 @@
1
+ import { initPacked } from "../init/versions.mjs";
1
2
  import { forget, leftBehind, notPutBack } from "./failure.mjs";
2
3
  import * as Effect from "effect/Effect";
3
4
  import * as Predicate from "effect/Predicate";
@@ -120,4 +121,23 @@ const vendored = /* @__PURE__ */ Effect.fnUntraced(function* (packed, folder, ta
120
121
  yield* removed(own).pipe(Effect.catch((error) => leftBehind(own, error)));
121
122
  return { kind: "placed" };
122
123
  }, Effect.uninterruptible);
123
- export { vendored };
124
+ /**
125
+ * Removes each tarball in `folder`'s `vendor/` and `vendor/cli/` that `init` wrote for one of
126
+ * `packed`'s packages, by `initPacked`'s names, other than `packed`'s own: once `package.json` names
127
+ * this run's, an older run's are no one's, and a rerun leaves none of them behind. One it can't
128
+ * remove is recorded as left, for the run's end to name.
129
+ */
130
+ const outdated = /* @__PURE__ */ Effect.fnUntraced(function* (packed, folder) {
131
+ const fs = yield* FileSystem.FileSystem;
132
+ const names = [...packed.vendor.keys()];
133
+ const kept = new Set(packed.vendor.values());
134
+ for (const under of ["vendor", "vendor/cli"]) {
135
+ const entries = yield* fs.readDirectory(`${folder}/${under}`).pipe(Effect.orElseSucceed(() => []));
136
+ for (const entry of entries) {
137
+ const at = `${under}/${entry}`;
138
+ if (kept.has(at) || !names.some((name) => initPacked(name, at))) continue;
139
+ yield* fs.remove(`${folder}/${at}`).pipe(Effect.catch((error) => leftBehind(`${folder}/${at}`, error)));
140
+ }
141
+ }
142
+ });
143
+ export { outdated, vendored };
package/dist/init/app.mjs CHANGED
@@ -1,8 +1,8 @@
1
- import { bucketLine, bucketName, devVars, looseAdapter, looseInfraImport, mergePackage, secretFiles } from "./cloudflare.mjs";
2
- import { ignoring, lines, listed, withCli } from "./files.mjs";
1
+ import { bucketLine, bucketName, devVars, limitsLine, looseInfraImport, mergePackage, secretFiles } from "./cloudflare.mjs";
2
+ import { ignoring, importLine, lines, listed, withCli } from "./files.mjs";
3
3
  import { bucketLines, firstImports, infraImports, partsOf, storeLines } from "./node.mjs";
4
4
  import { specOf } from "./versions.mjs";
5
- import { looseObjects } from "./git-module.mjs";
5
+ import { lfsLines, looseSays, writtenCpu } from "./git-module.mjs";
6
6
  import { jsonString, manifestText } from "./jsonc.mjs";
7
7
  import { filled, platforms, templates, unless } from "./template.mjs";
8
8
  import { blockOf, catalogOf } from "./workspace.mjs";
@@ -86,37 +86,56 @@ const appManifest = (source, name, vendor, platform = {}) => {
86
86
  };
87
87
  return withCli(`${manifestText(made)}\n`, vendor);
88
88
  };
89
- /** The `@ref0/git` import of the app's `src/git.ts`, naming what the store and the queue use. */
90
- const gitServerImport = (choices) => `import { ${[
91
- "createGitServer",
92
- choices.objects === "packs" && "lfs",
93
- choices.objects !== "packs" && "loose",
94
- choices.queue === "on" && "mergeQueue",
95
- choices.objects === "packs" && "packs",
96
- "RepoRecords"
97
- ].filter(Predicate.isString).join(", ")} } from '@ref0/git';`;
89
+ /** The `@ref0/git` import of the app's `src/git.ts`, naming the Layers the store and the queue use. */
90
+ const gitImport = (choices) => importLine([
91
+ "Git",
92
+ choices.objects === "packs" && "Lfs",
93
+ "Merges",
94
+ choices.queue === "on" && "MergeQueue",
95
+ "Objects",
96
+ "RepoRecords",
97
+ "Rest",
98
+ "SignIn",
99
+ "Tokens"
100
+ ].filter(Predicate.isString), "@ref0/git");
101
+ /** The `@ref0/github` import of the app's `src/git.ts`: `Releases` only beside a bucket. */
102
+ const githubImport = (choices) => importLine([
103
+ "Apps",
104
+ "Deployments",
105
+ "GitHub",
106
+ "Inbox",
107
+ choices.objects === "packs" && "Releases",
108
+ "Search",
109
+ "Streams",
110
+ "Webhooks"
111
+ ].filter(Predicate.isString), "@ref0/github");
112
+ /** Git's objects with no bucket: each a row in its push's commit, and what a push may carry. */
113
+ const looseObjects = `/** Git's objects, each a row in its push's commit: no bucket, ${looseSays}. */\nconst objects = Objects.layerRecords();`;
98
114
  /** The slots both platforms' `src/git.ts` fill alike: the queue's, and the store's past the head. */
99
- const bodySlots = (choices, uploads) => {
115
+ const bodySlots = (choices) => {
100
116
  const queue = choices.queue === "on";
117
+ const packs = choices.objects === "packs";
101
118
  return {
102
119
  queueMerge: unless(queue, ""),
103
120
  queue: unless(queue, ""),
104
- objects: unless(choices.objects === "packs", looseObjects),
105
- lfs: unless(choices.objects === "packs", ""),
106
- uploads: unless(uploads, "")
121
+ objects: unless(packs, looseObjects),
122
+ releases: unless(packs, "")
107
123
  };
108
124
  };
109
125
  /** The app's `src/git.ts` on Cloudflare: `apps/github`'s own, its store's and queue's slots filled. */
110
126
  const cloudflareGit = (choices) => {
111
127
  const packs = choices.objects === "packs";
112
128
  return filled(templates.appGit, {
113
- gitImport: gitServerImport(choices),
129
+ gitImport: gitImport(choices),
114
130
  queueTypes: unless(choices.queue === "on", ""),
131
+ githubImport: githubImport(choices),
115
132
  infraImport: unless(packs, looseInfraImport),
116
133
  safety: unless(packs, "binds the objects, and D1"),
117
134
  bucket: unless(packs, ""),
118
- adapter: unless(packs, looseAdapter),
119
- ...bodySlots(choices, packs)
135
+ adapter: unless(packs, "/** The records and job objects. */\nconst adapter = layer({ records: env.RECORDS, jobs: env.JOBS });"),
136
+ uploads: unless(packs, ""),
137
+ lfs: packs ? `${lfsLines(" ", writtenCpu)}\n` : "",
138
+ ...bodySlots(choices)
120
139
  });
121
140
  };
122
141
  /** Better Auth's database on Node, beside the records `--records` chose (init.md's table). */
@@ -137,17 +156,19 @@ const dialectOn = {
137
156
  const nodeHead = (choices) => {
138
157
  const queue = choices.queue === "on";
139
158
  const dialect = dialectOn[choices.records];
140
- return lines(firstImports(choices, false), dialect !== false && `${dialect}\n`, gitServerImport(choices), queue && "import type { MergeInput, MergePlan } from '@ref0/git';", "import { tokens } from '@ref0/git/auth';", "import { createRestHandler } from '@ref0/git/rest';", "import { createGitHubHandler } from '@ref0/github';", infraImports(choices), "import { xdiff } from '@ref0/xdiff-wasm/node';", "", `import { env${partsOf(choices).length > 0 ? ", need" : ""} } from './env.ts';`, "import { admin, approvalPage, hostPolicy, hostRules, type Identify } from './policy.ts';", "import { privateReposOf } from './private-repos.ts';", "import { readyAdapter, readyAuth, starterAuth } from './signin/auth.ts';", "import { avatars } from './signin/avatars.ts';", "import { clientIpHeader } from './signin/client-ip.ts';", "import { appAuth } from './signin/host-session.ts';", "import { orgsOver } from './signin/orgs.ts';", "import { sealKey } from './signin/seal.ts';", "", "/** What the app reads from `.env`, as the server's entry reads it here. */", "export { env };", "", storeLines(choices), bucketLines(choices), "", peopleOn[choices.records], "");
159
+ return lines(firstImports(choices, false), dialect !== false && `${dialect}\n`, gitImport(choices), queue && "import type { MergeInput, MergePlan } from '@ref0/git';", githubImport(choices), "import * as Languages from '@ref0/github/languages';", infraImports(choices), "import { xdiff } from '@ref0/xdiff-wasm/node';", "import * as FetchHttpClient from 'effect/http/FetchHttpClient';", "import * as Layer from 'effect/Layer';", "import * as ManagedRuntime from 'effect/ManagedRuntime';", "", "import { hostLayer, peopleOver, repoListOn, runOn, tokenCallsOn } from './context/host.ts';", `import { env${partsOf(choices).length > 0 ? ", need" : ""} } from './env.ts';`, "import { admin, approvalPage, hostPolicy, hostRules, type Identify } from './policy.ts';", "import { privateReposOf } from './private-repos.ts';", "import { readyAdapter, readyAuth, starterAuth } from './signin/auth.ts';", "import { avatars } from './signin/avatars.ts';", "import { clientIpHeader } from './signin/client-ip.ts';", "import { appAuth } from './signin/host-session.ts';", "import { orgsOver } from './signin/orgs.ts';", "import { sealKey } from './signin/seal.ts';", "", "/** What the app reads from `.env`, as the server's entry reads it here. */", "export { env };", "", storeLines(choices), bucketLines(choices), "", peopleOn[choices.records], "");
141
160
  };
142
161
  /** The app's `src/git.ts` on Node: `apps/github`'s own past its head, Node's head and parts in Cloudflare's place. */
143
162
  const nodeGit = (choices) => filled(templates.appGitNode, {
144
163
  head: `${nodeHead(choices)}\n`,
145
- adapter: ` adapter: ${choices.objects === "packs" ? "[store, bucket]" : "store"},`,
146
- xdiff: " xdiff: await xdiff(),",
164
+ lfs: choices.objects === "packs" ? `${lfsLines(" ", void 0)}\n` : "",
165
+ adapter: choices.objects === "packs" ? "/** The records, the jobs and the bucket. */\nconst adapter = Layer.merge(store, bucket);" : "/** The records and the jobs. */\nconst adapter = store;",
166
+ uploads: choices.bucket === "s3" ? lines(" // A push past 64 MiB may upload its pack, once the bucket signs parts.", " Layer.provide(Git.layerUploads({ above: 64 * 1024 * 1024 }), bucket),", "") : "",
167
+ xdiff: " Layer.provideMerge(Merges.layer({ xdiff: await xdiff() })),",
147
168
  database: " database: people,",
148
169
  ipHeader: lines(" // The server's own, which `src/server.ts` sets from the caller's address on every request.", " ipHeader: clientIpHeader,", ""),
149
170
  classes: "",
150
- ...bodySlots(choices, choices.bucket === "s3")
171
+ ...bodySlots(choices)
151
172
  });
152
173
  /** The app's `src/git.ts`: Git, the drop-in and Better Auth over the host's policy. */
153
174
  const appGitModule = (choices) => choices.platform === "node" ? nodeGit(choices) : cloudflareGit(choices);
@@ -171,6 +192,7 @@ const appWrangler = (choices, name) => {
171
192
  name: ` "name": ${jsonString(name)},`,
172
193
  vars: packs ? ` "vars": { "APP_ORIGIN": "${devOrigin}", "PACKS_BUCKET": "${bucketName(name)}" },` : ` "vars": { "APP_ORIGIN": "${devOrigin}" },`,
173
194
  bucket: bucketLine(choices, name),
195
+ limits: limitsLine,
174
196
  database: ` { "binding": "AUTH_DB", "database_name": "${name}-auth", "migrations_dir": "migrations/sql" },`
175
197
  });
176
198
  };
@@ -1,5 +1,5 @@
1
1
  import { lines } from "./files.mjs";
2
- import { fileRoutes, matcherImport, routeHandler } from "./routes.mjs";
2
+ import { fileRoutes, routeHandler, routeImports } from "./routes.mjs";
3
3
  // src/init/astro.ts
4
4
  /**
5
5
  * What `init` writes in an Astro project on Node: an endpoint for each route, rendered on request
@@ -24,7 +24,7 @@ const endpoint = (choices, route, module) => {
24
24
  return {
25
25
  path,
26
26
  kind: "whole",
27
- text: lines(`// ${route.says} Written by \`ref0-git init\`.`, "import type { APIRoute } from 'astro';", "", matcherImport(choices), "", "// Loaded on the first request, so `astro build` opens no database and needs no secret.", ...routeHandler(choices, path, module), "", "export const prerender = false;", "", "export const ALL: APIRoute = ({ request }) => git(request);", "")
27
+ text: lines(`// ${route.says} Written by \`ref0-git init\`.`, "import type { APIRoute } from 'astro';", "", ...routeImports(choices), "", "// Loaded on the first request, so `astro build` opens no database and needs no secret.", ...routeHandler(choices, path, module), "", "export const prerender = false;", "", "export const ALL: APIRoute = ({ request }) => git(request);", "")
28
28
  };
29
29
  };
30
30
  /** Astro's endpoints for `choices`, over `framework`'s server module. */