create-efforge 0.0.0-stage → 0.1.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 (237) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +140 -2
  3. package/dist/addon.js +115 -0
  4. package/dist/bin.js +6 -0
  5. package/dist/cli.js +9 -0
  6. package/dist/commands/add.js +440 -0
  7. package/dist/commands/create.js +186 -0
  8. package/dist/diff.js +72 -0
  9. package/dist/exec.js +20 -0
  10. package/dist/generate.js +181 -0
  11. package/dist/manifest.js +14 -0
  12. package/dist/projectName.js +41 -0
  13. package/dist/prompts/flow.js +111 -0
  14. package/dist/prompts/navigable.js +97 -0
  15. package/dist/routeTree.js +7 -0
  16. package/dist/rules.js +24 -0
  17. package/dist/slots.js +96 -0
  18. package/dist/stack.js +68 -0
  19. package/dist/transforms/addAlchemyResource.js +71 -0
  20. package/dist/transforms/addArrayItem.js +31 -0
  21. package/dist/transforms/addAuthPlugin.js +77 -0
  22. package/dist/transforms/addDevVar.js +18 -0
  23. package/dist/transforms/addExport.js +46 -0
  24. package/dist/transforms/addImport.js +11 -0
  25. package/dist/transforms/addLayer.js +31 -0
  26. package/dist/transforms/addServerFnMiddleware.js +62 -0
  27. package/dist/transforms/addWorkflowSecret.js +43 -0
  28. package/dist/transforms/addWranglerBinding.js +61 -0
  29. package/dist/transforms/appendAgentsSection.js +26 -0
  30. package/dist/transforms/errors.js +7 -0
  31. package/dist/transforms/index.js +40 -0
  32. package/dist/transforms/setWranglerValue.js +40 -0
  33. package/dist/transforms/util.js +219 -0
  34. package/dist/tree.js +1 -0
  35. package/dist/versions.js +73 -0
  36. package/dist/write.js +26 -0
  37. package/package.json +63 -4
  38. package/templates/ai/effect-ai-byok/addon.json +619 -0
  39. package/templates/ai/effect-ai-byok/files/core/llm-crypto.test.ts +47 -0
  40. package/templates/ai/effect-ai-byok/files/core/llm-crypto.ts +76 -0
  41. package/templates/ai/effect-ai-byok/files/core/llm-store.ts +21 -0
  42. package/templates/ai/effect-ai-byok/files/core/llm.ts +32 -0
  43. package/templates/ai/effect-ai-byok/files/drizzle/d1/20261018161056_llm_credential/migration.sql +9 -0
  44. package/templates/ai/effect-ai-byok/files/drizzle/d1/20261018161056_llm_credential/snapshot.json +944 -0
  45. package/templates/ai/effect-ai-byok/files/drizzle/pg/20261018161056_llm_credential/migration.sql +10 -0
  46. package/templates/ai/effect-ai-byok/files/drizzle/pg/20261018161056_llm_credential/snapshot.json +1232 -0
  47. package/templates/ai/effect-ai-byok/files/routes/ai.tsx +193 -0
  48. package/templates/ai/effect-ai-byok/files/schema/d1.ts +16 -0
  49. package/templates/ai/effect-ai-byok/files/schema/pg.ts +14 -0
  50. package/templates/ai/effect-ai-byok/files/server/ai-settings.ts +129 -0
  51. package/templates/ai/effect-ai-byok/files/server/ai.ts +25 -0
  52. package/templates/ai/effect-ai-byok/files/server/llm-env.ts +48 -0
  53. package/templates/ai/effect-ai-byok/files/server/llm-orgs.ts +146 -0
  54. package/templates/ai/effect-ai-byok/files/server/llm-provider.ts +56 -0
  55. package/templates/ai/effect-ai-byok/files/server/llm-store-drizzle.ts +48 -0
  56. package/templates/ai/effect-ai-byok/files/server/llm-store-sql-d1.ts +41 -0
  57. package/templates/ai/effect-ai-byok/files/server/llm-store-sql-pg.ts +41 -0
  58. package/templates/ai/effect-ai-byok/files/sql/d1.sql +8 -0
  59. package/templates/ai/effect-ai-byok/files/sql/pg.sql +8 -0
  60. package/templates/auth/better-auth/addon.json +424 -0
  61. package/templates/auth/better-auth/files/core/Auth.ts +18 -0
  62. package/templates/auth/better-auth/files/drizzle/d1/20261018161054_auth/migration.sql +51 -0
  63. package/templates/auth/better-auth/files/drizzle/d1/20261018161054_auth/snapshot.json +522 -0
  64. package/templates/auth/better-auth/files/drizzle/pg/20261018161053_auth/migration.sql +51 -0
  65. package/templates/auth/better-auth/files/drizzle/pg/20261018161053_auth/snapshot.json +680 -0
  66. package/templates/auth/better-auth/files/lib/auth-client.ts +4 -0
  67. package/templates/auth/better-auth/files/routes/app.tsx +54 -0
  68. package/templates/auth/better-auth/files/schema/d1/auth-schema.ts +86 -0
  69. package/templates/auth/better-auth/files/schema/pg/auth-schema.ts +73 -0
  70. package/templates/auth/better-auth/files/server/auth-live.ts +47 -0
  71. package/templates/auth/better-auth/files/server/session.ts +14 -0
  72. package/templates/auth/better-auth/files/shared/components/auth-card.tsx +32 -0
  73. package/templates/auth/better-auth/files/shared/components/user-menu.tsx +44 -0
  74. package/templates/auth/better-auth/files/shared/drizzle/d1/drizzle.config.ts +7 -0
  75. package/templates/auth/better-auth/files/shared/drizzle/pg/drizzle.config.ts +10 -0
  76. package/templates/auth/better-auth/files/shared/lib/form.ts +5 -0
  77. package/templates/auth/better-auth/files/shared/lib/redirect.ts +6 -0
  78. package/templates/auth/better-auth/files/shared/routes/app/index.tsx +54 -0
  79. package/templates/auth/better-auth/files/shared/routes/sign-in.tsx +85 -0
  80. package/templates/auth/better-auth/files/shared/routes/sign-up.tsx +91 -0
  81. package/templates/auth/better-auth/files/shared/server/auth-route.ts +15 -0
  82. package/templates/auth/better-auth/files/shared/server/auth.ts +22 -0
  83. package/templates/auth/better-auth/files/shared/server/db/d1-drizzle.ts +25 -0
  84. package/templates/auth/better-auth/files/shared/server/db/d1-effect-sql.ts +17 -0
  85. package/templates/auth/better-auth/files/shared/server/db/pg-drizzle.ts +32 -0
  86. package/templates/auth/better-auth/files/shared/server/db/pg-effect-sql.ts +29 -0
  87. package/templates/auth/better-auth/files/shared/server/require-session.ts +20 -0
  88. package/templates/auth/better-auth/files/sql/d1/0002_auth.sql +13 -0
  89. package/templates/auth/better-auth/files/sql/pg/0002_auth.sql +13 -0
  90. package/templates/auth/better-auth-orgs/addon.json +463 -0
  91. package/templates/auth/better-auth-orgs/files/components/org-switcher.tsx +65 -0
  92. package/templates/auth/better-auth-orgs/files/core/Auth.ts +20 -0
  93. package/templates/auth/better-auth-orgs/files/drizzle/d1/20261018161055_auth/migration.sql +88 -0
  94. package/templates/auth/better-auth-orgs/files/drizzle/d1/20261018161055_auth/snapshot.json +862 -0
  95. package/templates/auth/better-auth-orgs/files/drizzle/pg/20261018161055_auth/migration.sql +88 -0
  96. package/templates/auth/better-auth-orgs/files/drizzle/pg/20261018161055_auth/snapshot.json +1127 -0
  97. package/templates/auth/better-auth-orgs/files/lib/auth-client.ts +5 -0
  98. package/templates/auth/better-auth-orgs/files/routes/accept-invite.$id.tsx +68 -0
  99. package/templates/auth/better-auth-orgs/files/routes/app/settings/index.tsx +27 -0
  100. package/templates/auth/better-auth-orgs/files/routes/app/settings/members.tsx +198 -0
  101. package/templates/auth/better-auth-orgs/files/routes/app/settings.tsx +30 -0
  102. package/templates/auth/better-auth-orgs/files/routes/app.tsx +58 -0
  103. package/templates/auth/better-auth-orgs/files/routes/onboarding.tsx +66 -0
  104. package/templates/auth/better-auth-orgs/files/schema/d1/auth-schema.ts +139 -0
  105. package/templates/auth/better-auth-orgs/files/schema/pg/auth-schema.ts +124 -0
  106. package/templates/auth/better-auth-orgs/files/server/auth-live.ts +52 -0
  107. package/templates/auth/better-auth-orgs/files/server/session.ts +44 -0
  108. package/templates/auth/better-auth-orgs/files/sql/d1/0002_auth.sql +27 -0
  109. package/templates/auth/better-auth-orgs/files/sql/pg/0002_auth.sql +27 -0
  110. package/templates/base/addon.json +212 -0
  111. package/templates/base/files/AGENTS.md +70 -0
  112. package/templates/base/files/CLAUDE.md +1 -0
  113. package/templates/base/files/README.md +28 -0
  114. package/templates/base/files/core/package.json +13 -0
  115. package/templates/base/files/core/src/index.ts +2 -0
  116. package/templates/base/files/core/test/core.test.ts +4 -0
  117. package/templates/base/files/core/tsconfig.json +6 -0
  118. package/templates/base/files/gitignore +11 -0
  119. package/templates/base/files/pnpm-workspace.yaml +11 -0
  120. package/templates/base/files/root/package.json +16 -0
  121. package/templates/base/files/root/tsconfig.base.json +19 -0
  122. package/templates/base/files/root/turbo.json +9 -0
  123. package/templates/base/files/root/vite.config.ts +61 -0
  124. package/templates/base/files/web/components.json +21 -0
  125. package/templates/base/files/web/package.json +17 -0
  126. package/templates/base/files/web/src/components/theme-provider.tsx +57 -0
  127. package/templates/base/files/web/src/components/theme-toggle.tsx +34 -0
  128. package/templates/base/files/web/src/components/ui/avatar.tsx +93 -0
  129. package/templates/base/files/web/src/components/ui/button.tsx +61 -0
  130. package/templates/base/files/web/src/components/ui/card.tsx +74 -0
  131. package/templates/base/files/web/src/components/ui/dialog.tsx +141 -0
  132. package/templates/base/files/web/src/components/ui/dropdown-menu.tsx +225 -0
  133. package/templates/base/files/web/src/components/ui/input.tsx +20 -0
  134. package/templates/base/files/web/src/components/ui/label.tsx +18 -0
  135. package/templates/base/files/web/src/components/ui/sonner.tsx +45 -0
  136. package/templates/base/files/web/src/components/widgets.tsx +4 -0
  137. package/templates/base/files/web/src/lib/utils.ts +6 -0
  138. package/templates/base/files/web/src/router.tsx +12 -0
  139. package/templates/base/files/web/src/routes/__root.tsx +42 -0
  140. package/templates/base/files/web/src/routes/app/index.tsx +27 -0
  141. package/templates/base/files/web/src/routes/app/settings.tsx +29 -0
  142. package/templates/base/files/web/src/routes/app.tsx +47 -0
  143. package/templates/base/files/web/src/routes/index.tsx +51 -0
  144. package/templates/base/files/web/src/server/greeting.ts +12 -0
  145. package/templates/base/files/web/src/server/layers.ts +10 -0
  146. package/templates/base/files/web/src/server/runtime.ts +5 -0
  147. package/templates/base/files/web/src/styles.css +81 -0
  148. package/templates/base/files/web/tsconfig.json +11 -0
  149. package/templates/base/files/web/vite.config.ts +9 -0
  150. package/templates/database/d1/addon.json +118 -0
  151. package/templates/database/d1/files/package.json +12 -0
  152. package/templates/database/d1/files/tsconfig.json +5 -0
  153. package/templates/database/postgres/addon.json +142 -0
  154. package/templates/database/postgres/files/docker-compose.yml +21 -0
  155. package/templates/database/postgres/files/package.json +12 -0
  156. package/templates/database/postgres/files/runtime.ts +12 -0
  157. package/templates/database/postgres/files/tsconfig.json +5 -0
  158. package/templates/extras/browser/addon.json +173 -0
  159. package/templates/extras/browser/files/BrowserContainer.ts +14 -0
  160. package/templates/extras/browser/files/app/Dockerfile +15 -0
  161. package/templates/extras/browser/files/app/dockerignore +1 -0
  162. package/templates/extras/browser/files/app/package-lock +605 -0
  163. package/templates/extras/browser/files/app/package.json +9 -0
  164. package/templates/extras/browser/files/app/src/server.ts +78 -0
  165. package/templates/extras/browser/files/app/src/url-policy.ts +115 -0
  166. package/templates/extras/browser/files/app/tsconfig.json +6 -0
  167. package/templates/extras/browser/files/browser.ts +34 -0
  168. package/templates/extras/browser/files/core-browser.ts +21 -0
  169. package/templates/extras/browser/files/run-browser.ts +25 -0
  170. package/templates/extras/email/addon.json +182 -0
  171. package/templates/extras/email/files/core-mailer.ts +28 -0
  172. package/templates/extras/email/files/invitation-email.ts +38 -0
  173. package/templates/extras/email/files/mailer.ts +58 -0
  174. package/templates/extras/realtime/addon.json +135 -0
  175. package/templates/extras/realtime/files/Room.ts +46 -0
  176. package/templates/extras/realtime/files/core-realtime.ts +19 -0
  177. package/templates/extras/realtime/files/realtime-demo.tsx +40 -0
  178. package/templates/extras/realtime/files/realtime-limits.test.ts +32 -0
  179. package/templates/extras/realtime/files/realtime-limits.ts +35 -0
  180. package/templates/extras/realtime/files/realtime-route.ts +39 -0
  181. package/templates/extras/realtime/files/realtime.ts +39 -0
  182. package/templates/extras/realtime/files/use-room.ts +67 -0
  183. package/templates/extras/storage/addon.json +132 -0
  184. package/templates/extras/storage/files/core-storage.ts +64 -0
  185. package/templates/extras/storage/files/storage-route.ts +50 -0
  186. package/templates/extras/storage/files/storage-security.test.ts +71 -0
  187. package/templates/extras/storage/files/storage-security.ts +92 -0
  188. package/templates/extras/storage/files/storage.ts +84 -0
  189. package/templates/extras/workflows/addon.json +95 -0
  190. package/templates/extras/workflows/files/Example.ts +42 -0
  191. package/templates/extras/workflows/files/core-jobs.ts +45 -0
  192. package/templates/extras/workflows/files/example-job.ts +36 -0
  193. package/templates/extras/workflows/files/jobs.ts +34 -0
  194. package/templates/infra/alchemy/addon.json +37 -0
  195. package/templates/infra/alchemy/files/README.md +27 -0
  196. package/templates/infra/alchemy/files/alchemy.run.ts +36 -0
  197. package/templates/infra/alchemy/files/github/deploy.yml +63 -0
  198. package/templates/infra/alchemy/files/tsconfig.json +5 -0
  199. package/templates/infra/alchemy/files/vite.config.ts +30 -0
  200. package/templates/orm/drizzle/addon.json +188 -0
  201. package/templates/orm/drizzle/files/d1/Database.ts +7 -0
  202. package/templates/orm/drizzle/files/d1/drizzle/20261018154417_init/migration.sql +10 -0
  203. package/templates/orm/drizzle/files/d1/drizzle/20261018154417_init/snapshot.json +60 -0
  204. package/templates/orm/drizzle/files/d1/drizzle.config.ts +7 -0
  205. package/templates/orm/drizzle/files/d1/layer.ts +13 -0
  206. package/templates/orm/drizzle/files/d1/migrate.ts +37 -0
  207. package/templates/orm/drizzle/files/d1/schema.ts +15 -0
  208. package/templates/orm/drizzle/files/pg/Database.ts +7 -0
  209. package/templates/orm/drizzle/files/pg/drizzle/20261018154416_init/migration.sql +10 -0
  210. package/templates/orm/drizzle/files/pg/drizzle/20261018154416_init/snapshot.json +75 -0
  211. package/templates/orm/drizzle/files/pg/drizzle.config.ts +10 -0
  212. package/templates/orm/drizzle/files/pg/layer.ts +16 -0
  213. package/templates/orm/drizzle/files/pg/migrate.ts +24 -0
  214. package/templates/orm/drizzle/files/pg/schema.ts +11 -0
  215. package/templates/orm/drizzle/files/shared/index.ts +2 -0
  216. package/templates/orm/drizzle/files/shared/notes.ts +15 -0
  217. package/templates/orm/drizzle/files/shared/page.tsx +50 -0
  218. package/templates/orm/effect-sql/addon.json +124 -0
  219. package/templates/orm/effect-sql/files/d1/layer.ts +13 -0
  220. package/templates/orm/effect-sql/files/d1/migrate.ts +20 -0
  221. package/templates/orm/effect-sql/files/d1/schema.ts +7 -0
  222. package/templates/orm/effect-sql/files/d1-sql/0001_init.sql +10 -0
  223. package/templates/orm/effect-sql/files/pg/layer.ts +16 -0
  224. package/templates/orm/effect-sql/files/pg/migrate.ts +66 -0
  225. package/templates/orm/effect-sql/files/pg/schema.ts +7 -0
  226. package/templates/orm/effect-sql/files/pg-sql/0001_init.sql +10 -0
  227. package/templates/orm/effect-sql/files/shared/Database.ts +7 -0
  228. package/templates/orm/effect-sql/files/shared/index.ts +2 -0
  229. package/templates/orm/effect-sql/files/shared/notes.ts +18 -0
  230. package/templates/orm/effect-sql/files/shared/page.tsx +50 -0
  231. package/templates/runtime/cloudflare/addon.json +52 -0
  232. package/templates/runtime/cloudflare/files/cloudflare.ts +10 -0
  233. package/templates/runtime/cloudflare/files/routes.ts +5 -0
  234. package/templates/runtime/cloudflare/files/server.ts +22 -0
  235. package/templates/runtime/cloudflare/files/tsconfig.json +12 -0
  236. package/templates/runtime/cloudflare/files/vite.config.ts +20 -0
  237. package/templates/runtime/cloudflare/files/wrangler.jsonc +8 -0
package/dist/diff.js ADDED
@@ -0,0 +1,72 @@
1
+ const CONTEXT = 3;
2
+ const lines = (text) => {
3
+ if (text === "")
4
+ return [];
5
+ const parts = text.split("\n");
6
+ if (parts.at(-1) === "")
7
+ parts.pop();
8
+ return parts;
9
+ };
10
+ /** Line-level edit script via a longest-common-subsequence table (files here are small). */
11
+ const script = (a, b) => {
12
+ const n = a.length;
13
+ const m = b.length;
14
+ const table = Array.from({ length: n + 1 }, () => Array.from({ length: m + 1 }).fill(0));
15
+ for (let i = n - 1; i >= 0; i--)
16
+ for (let j = m - 1; j >= 0; j--)
17
+ table[i][j] =
18
+ a[i] === b[j]
19
+ ? table[i + 1][j + 1] + 1
20
+ : Math.max(table[i + 1][j], table[i][j + 1]);
21
+ const ops = [];
22
+ let i = 0;
23
+ let j = 0;
24
+ while (i < n && j < m) {
25
+ if (a[i] === b[j]) {
26
+ ops.push({ kind: " ", line: a[i] });
27
+ i++;
28
+ j++;
29
+ }
30
+ else if (table[i + 1][j] >= table[i][j + 1]) {
31
+ ops.push({ kind: "-", line: a[i++] });
32
+ }
33
+ else {
34
+ ops.push({ kind: "+", line: b[j++] });
35
+ }
36
+ }
37
+ while (i < n)
38
+ ops.push({ kind: "-", line: a[i++] });
39
+ while (j < m)
40
+ ops.push({ kind: "+", line: b[j++] });
41
+ return ops;
42
+ };
43
+ /** Unified diff of `before` -> `after` with 3 lines of context; empty string when equal. */
44
+ export const unifiedDiff = (file, before, after, labels = { before: "on disk", after: "efforge" }) => {
45
+ const ops = script(lines(before), lines(after));
46
+ const changed = ops.flatMap((op, i) => (op.kind === " " ? [] : [i]));
47
+ if (changed.length === 0)
48
+ return "";
49
+ // group changes whose context windows touch into hunks
50
+ const ranges = [];
51
+ for (const idx of changed) {
52
+ const start = Math.max(0, idx - CONTEXT);
53
+ const end = Math.min(ops.length, idx + CONTEXT + 1);
54
+ const last = ranges.at(-1);
55
+ if (last !== undefined && start <= last[1])
56
+ last[1] = Math.max(last[1], end);
57
+ else
58
+ ranges.push([start, end]);
59
+ }
60
+ const out = [`--- ${file} (${labels.before})`, `+++ ${file} (${labels.after})`];
61
+ for (const [start, end] of ranges) {
62
+ const slice = ops.slice(start, end);
63
+ const before0 = ops.slice(0, start).filter((o) => o.kind !== "+").length;
64
+ const after0 = ops.slice(0, start).filter((o) => o.kind !== "-").length;
65
+ const bCount = slice.filter((o) => o.kind !== "+").length;
66
+ const aCount = slice.filter((o) => o.kind !== "-").length;
67
+ out.push(`@@ -${bCount === 0 ? before0 : before0 + 1},${bCount} +${aCount === 0 ? after0 : after0 + 1},${aCount} @@`);
68
+ for (const op of slice)
69
+ out.push(`${op.kind}${op.line}`);
70
+ }
71
+ return `${out.join("\n")}\n`;
72
+ };
package/dist/exec.js ADDED
@@ -0,0 +1,20 @@
1
+ import { Effect, Schema, Stream } from "effect";
2
+ import { ChildProcess, ChildProcessSpawner } from "effect/process";
3
+ export class CommandFailed extends Schema.TaggedError()("CommandFailed", {
4
+ command: Schema.String,
5
+ exitCode: Schema.optionalKey(Schema.Number),
6
+ output: Schema.String,
7
+ }) {
8
+ }
9
+ /** Runs `cmd args` in `cwd`, returning combined output; a non-zero exit fails with `CommandFailed`. */
10
+ export const exec = (cmd, args, cwd) => {
11
+ const command = [cmd, ...args].join(" ");
12
+ return Effect.gen(function* () {
13
+ const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
14
+ const handle = yield* spawner.spawn(ChildProcess.make(cmd, [...args], { cwd }));
15
+ const [output, code] = yield* Effect.all([handle.all.pipe(Stream.decodeText(), Stream.mkString), handle.exitCode], { concurrency: 2 });
16
+ if (code !== 0)
17
+ return yield* new CommandFailed({ command, exitCode: code, output });
18
+ return output;
19
+ }).pipe(Effect.scoped, Effect.catchTag("PlatformError", (e) => new CommandFailed({ command, output: e.message })));
20
+ };
@@ -0,0 +1,181 @@
1
+ import { Effect, FileSystem, Path, Schema } from "effect";
2
+ import { parse, stringify } from "yaml";
3
+ import { addonIdsFor } from "./addon.js";
4
+ import { hash, renderManifest } from "./manifest.js";
5
+ import { applyProjectName } from "./projectName.js";
6
+ import { SlotId, toCommand } from "./stack.js";
7
+ import { runTransform, } from "./transforms/index.js";
8
+ import { efforgeVersion, versions } from "./versions.js";
9
+ export class GenerateError extends Schema.TaggedError()("GenerateError", {
10
+ reason: Schema.Literals([
11
+ "unsafe-path",
12
+ "unpinned",
13
+ "missing-package-json",
14
+ "invalid-json",
15
+ "unknown-addon",
16
+ "io",
17
+ ]),
18
+ package: Schema.optionalKey(Schema.String),
19
+ path: Schema.optionalKey(Schema.String),
20
+ message: Schema.String,
21
+ }) {
22
+ }
23
+ /** Every listed slot must match; for `extras`, at least one chosen extra must be listed. */
24
+ export const matches = (when, config) => {
25
+ if (when === undefined)
26
+ return true;
27
+ return SlotId.literals.every((slot) => {
28
+ const allowed = when[slot];
29
+ if (allowed === undefined)
30
+ return true;
31
+ return slot === "extras"
32
+ ? config.extras.some((e) => allowed.includes(e))
33
+ : allowed.includes(config[slot]);
34
+ });
35
+ };
36
+ /** `packageManager` goes last, where the formatter (and sort-package-json) puts it. */
37
+ const json = (value) => {
38
+ const { packageManager, ...rest } = value;
39
+ const ordered = packageManager === undefined ? value : { ...rest, packageManager };
40
+ return `${JSON.stringify(ordered, null, 2)}\n`;
41
+ };
42
+ const sortKeys = (o) => Object.fromEntries(Object.entries(o).toSorted(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)));
43
+ const computedNames = new Set(["pnpm-workspace.yaml", ".env.example", "efforge.jsonc"]);
44
+ export const isComputed = (target) => computedNames.has(target) || target === "package.json" || target.endsWith("/package.json");
45
+ /** Packages of the generated monorepo (`@repo/*`) link via `workspace:*`; they have no pinned version. */
46
+ const isWorkspace = (name) => name.startsWith("@repo/");
47
+ const DEFAULT_PACKAGES = ["apps/*", "packages/*"];
48
+ /** Builds the project tree for `config` from the loaded add-ons. Pure apart from reading add-on files. */
49
+ export const generate = (config, addons) => Effect.gen(function* () {
50
+ const fs = yield* FileSystem.FileSystem;
51
+ const path = yield* Path.Path;
52
+ let tree = new Map();
53
+ const overlay = new Set();
54
+ const seams = new Set();
55
+ const used = new Set();
56
+ const env = new Map();
57
+ const seenEnv = new Set();
58
+ const loaded = [];
59
+ for (const id of addonIdsFor(config)) {
60
+ const addon = addons.get(id);
61
+ if (addon === undefined)
62
+ return yield* new GenerateError({
63
+ reason: "unknown-addon",
64
+ message: `add-on "${id}" is not loaded`,
65
+ });
66
+ loaded.push(addon);
67
+ }
68
+ // 1. every overlay, in add-on order, so a later overlay can never clobber an earlier edit
69
+ for (const { manifest, dir } of loaded) {
70
+ for (const f of manifest.files) {
71
+ if (!matches(f.when, config))
72
+ continue;
73
+ const content = yield* fs
74
+ .readFileString(path.join(dir, f.path))
75
+ .pipe(Effect.mapError((e) => new GenerateError({ reason: "io", path: f.path, message: e.message })));
76
+ tree = new Map(tree).set(f.target, content);
77
+ overlay.add(f.target);
78
+ }
79
+ }
80
+ // 2. dependencies and env vars
81
+ for (const { manifest } of loaded) {
82
+ const editPackage = (pkgDir, edit) => Effect.gen(function* () {
83
+ const target = pkgDir === "." ? "package.json" : `${pkgDir}/package.json`;
84
+ const text = tree.get(target);
85
+ if (text === undefined)
86
+ return yield* new GenerateError({
87
+ reason: "missing-package-json",
88
+ path: target,
89
+ message: `${manifest.id} adds dependencies or scripts to ${target}, which does not exist`,
90
+ });
91
+ const pkg = yield* Effect.try({
92
+ try: () => JSON.parse(text),
93
+ catch: (e) => new GenerateError({
94
+ reason: "invalid-json",
95
+ path: target,
96
+ message: `${target} is not valid JSON: ${String(e)}`,
97
+ }),
98
+ });
99
+ edit(pkg);
100
+ tree = new Map(tree).set(target, json(pkg));
101
+ });
102
+ for (const [key, section] of [
103
+ ["dependencies", manifest.dependencies],
104
+ ["devDependencies", manifest.devDependencies],
105
+ ]) {
106
+ for (const [pkgDir, names] of Object.entries(section)) {
107
+ const unpinned = names.find((name) => !isWorkspace(name) && versions[name] === undefined);
108
+ if (unpinned !== undefined)
109
+ return yield* new GenerateError({
110
+ reason: "unpinned",
111
+ package: unpinned,
112
+ message: `${manifest.id} uses "${unpinned}", which has no entry in versions.ts`,
113
+ });
114
+ // a Docker build context can't see the root catalog, so such a package pins exact versions
115
+ const standalone = tree.has(`${pkgDir === "." ? "" : `${pkgDir}/`}Dockerfile`);
116
+ yield* editPackage(pkgDir, (pkg) => {
117
+ const deps = { ...pkg[key] };
118
+ for (const name of names) {
119
+ if (isWorkspace(name)) {
120
+ deps[name] = "workspace:*";
121
+ }
122
+ else if (standalone) {
123
+ deps[name] = versions[name];
124
+ }
125
+ else {
126
+ deps[name] = "catalog:";
127
+ used.add(name);
128
+ }
129
+ }
130
+ pkg[key] = sortKeys(deps);
131
+ });
132
+ }
133
+ }
134
+ for (const [pkgDir, scripts] of Object.entries(manifest.scripts ?? {}))
135
+ yield* editPackage(pkgDir, (pkg) => {
136
+ pkg.scripts = {
137
+ ...pkg.scripts,
138
+ ...scripts,
139
+ };
140
+ });
141
+ for (const v of manifest.envVars) {
142
+ if (!matches(v.when, config))
143
+ continue;
144
+ if (seenEnv.has(v.name))
145
+ continue;
146
+ seenEnv.add(v.name);
147
+ const group = env.get(manifest.id) ?? { title: manifest.title, vars: [] };
148
+ group.vars.push(`${v.name}=${v.example}`);
149
+ env.set(manifest.id, group);
150
+ }
151
+ }
152
+ // 3. every transform, in add-on order
153
+ for (const { manifest } of loaded) {
154
+ for (const t of manifest.transforms) {
155
+ if (!matches(t.when, config))
156
+ continue;
157
+ const before = tree;
158
+ tree = yield* runTransform(tree, t);
159
+ // seam files are always re-edited by transforms, never hash-checked by `add`
160
+ for (const [file, content] of tree)
161
+ if (before.get(file) !== content)
162
+ seams.add(file);
163
+ }
164
+ }
165
+ // Built-in post-step, after transforms and before hashing, so manifest hashes cover the
166
+ // final (named) content and `add` sees an unedited README/wrangler.jsonc as unchanged.
167
+ const out = new Map(applyProjectName(tree, config.name));
168
+ const workspace = out.get("pnpm-workspace.yaml");
169
+ const { packages = DEFAULT_PACKAGES, ...rest } = workspace === undefined ? {} : (parse(workspace) ?? {});
170
+ const catalog = Object.fromEntries([...used].toSorted().map((n) => [n, versions[n]]));
171
+ // keep the template's other keys (e.g. `allowBuilds`); `catalog` is always computed
172
+ out.set("pnpm-workspace.yaml", stringify({ packages, ...rest, catalog }));
173
+ if (env.size > 0)
174
+ out.set(".env.example", `${[...env.values()].map((g) => `# ${g.title}\n${g.vars.join("\n")}`).join("\n\n")}\n`);
175
+ const files = Object.fromEntries([...overlay]
176
+ .filter((t) => !isComputed(t) && !seams.has(t) && out.has(t))
177
+ .toSorted()
178
+ .map((t) => [t, hash(out.get(t))]));
179
+ out.set("efforge.jsonc", renderManifest({ efforgeVersion, stack: config, command: toCommand(config), files }));
180
+ return new Map([...out].toSorted(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)));
181
+ });
@@ -0,0 +1,14 @@
1
+ import { createHash } from "node:crypto";
2
+ import { Schema } from "effect";
3
+ import { StackConfig } from "./stack.js";
4
+ /** sha256 hex, first 16 characters. */
5
+ export const hash = (content) => createHash("sha256").update(content).digest("hex").slice(0, 16);
6
+ export const EfforgeManifest = Schema.Struct({
7
+ efforgeVersion: Schema.String,
8
+ stack: StackConfig,
9
+ command: Schema.String,
10
+ /** overlay target -> hash(content) */
11
+ files: Schema.Record(Schema.String, Schema.String),
12
+ });
13
+ export const manifestHeader = "// Generated by efforge. Used by `efforge add`.\n";
14
+ export const renderManifest = (m) => `${manifestHeader}${JSON.stringify(m, null, 2)}\n`;
@@ -0,0 +1,41 @@
1
+ import { applyEdits, modify, parse } from "jsonc-parser";
2
+ const formattingOptions = { insertSpaces: true, tabSize: 2 };
3
+ const ALCHEMY_RUN = "infra/alchemy.run.ts";
4
+ /** Stack names end up in Cloudflare resource names: lowercase letters, digits and dashes. */
5
+ const slug = (name) => name
6
+ .toLowerCase()
7
+ .replace(/[^a-z0-9]+/g, "-")
8
+ .replace(/^-+|-+$/g, "") || "app";
9
+ /** The directory name a project is created in: the last segment of a scoped name. */
10
+ export const projectDirName = (name) => name.split("/").pop() ?? name;
11
+ /**
12
+ * Built-in post-step: names the generated project. Sets the root `package.json` (`<name>-monorepo`, so it can never clash with a workspace package called `<name>`) and
13
+ * `wrangler.jsonc` `name`, the Alchemy stack name and the README's first heading. Files that are absent, or lack
14
+ * the field, are left alone; running it twice changes nothing.
15
+ */
16
+ export const applyProjectName = (tree, name) => {
17
+ const out = new Map(tree);
18
+ const dir = projectDirName(name);
19
+ const pkg = out.get("package.json");
20
+ if (pkg !== undefined) {
21
+ try {
22
+ const parsed = JSON.parse(pkg);
23
+ out.set("package.json", `${JSON.stringify({ ...parsed, name: `${dir}-monorepo` }, null, 2)}\n`);
24
+ }
25
+ catch { }
26
+ }
27
+ const wrangler = out.get("wrangler.jsonc");
28
+ if (wrangler !== undefined) {
29
+ const errors = [];
30
+ const doc = parse(wrangler, errors, { allowTrailingComma: true });
31
+ if (errors.length === 0 && typeof doc?.name === "string")
32
+ out.set("wrangler.jsonc", applyEdits(wrangler, modify(wrangler, ["name"], dir, { formattingOptions })));
33
+ }
34
+ const readme = out.get("README.md");
35
+ if (readme !== undefined)
36
+ out.set("README.md", readme.replace(/^# .*$/m, `# ${dir}`));
37
+ const alchemy = out.get(ALCHEMY_RUN);
38
+ if (alchemy !== undefined)
39
+ out.set(ALCHEMY_RUN, alchemy.replace(/(Alchemy\.Stack\(\s*)"[^"]*"/, `$1"${slug(dir)}"`));
40
+ return out;
41
+ };
@@ -0,0 +1,111 @@
1
+ import { Effect, Schema } from "effect";
2
+ import { IncompatibleStack, validate } from "../rules.js";
3
+ import { available, slots } from "../slots.js";
4
+ import { ProjectName } from "../stack.js";
5
+ import { GoBack } from "./navigable.js";
6
+ export class InvalidProjectName extends Schema.TaggedError()("InvalidProjectName", { name: Schema.String, message: Schema.String }) {
7
+ }
8
+ export const DEFAULT_NAME = "my-app";
9
+ const nameError = (name) => {
10
+ const r = Schema.decodeUnknownExit(ProjectName)(name);
11
+ return r._tag === "Success"
12
+ ? undefined
13
+ : "Use a valid npm package name: lowercase letters, digits, - . _ ~ (optionally @scope/name), no '..'";
14
+ };
15
+ const defaultFor = (slot, options) => {
16
+ if (slot.multi)
17
+ return [];
18
+ const wanted = slot.default;
19
+ return options.some((o) => o.id === wanted) ? wanted : (options[0]?.id ?? wanted);
20
+ };
21
+ /**
22
+ * Walks the slots in order. Flags skip their prompt but are validated against the
23
+ * answers so far; a slot with a single available option is chosen silently.
24
+ * `GoBack` returns to the previous slot that was actually prompted.
25
+ */
26
+ export const askStack = (flags, io, opts = {}) => Effect.gen(function* () {
27
+ // 1. name
28
+ let name = flags.name;
29
+ if (name === undefined) {
30
+ if (opts.yes)
31
+ name = DEFAULT_NAME;
32
+ else {
33
+ const answer = yield* io.text({
34
+ id: "name",
35
+ message: "Project name",
36
+ placeholder: DEFAULT_NAME,
37
+ defaultValue: DEFAULT_NAME,
38
+ validate: nameError,
39
+ });
40
+ name = answer === GoBack ? DEFAULT_NAME : answer;
41
+ }
42
+ }
43
+ const invalid = nameError(name);
44
+ if (invalid !== undefined)
45
+ return yield* new InvalidProjectName({ name, message: invalid });
46
+ // 2. slots
47
+ const draft = {};
48
+ const previous = {};
49
+ const history = [];
50
+ let section;
51
+ let i = 0;
52
+ while (i < slots.length) {
53
+ const slot = slots[i];
54
+ const options = available(slot.id, draft);
55
+ const ids = options.map((o) => o.id);
56
+ const flag = flags[slot.id];
57
+ if (flag !== undefined) {
58
+ const values = typeof flag === "string" ? [flag] : flag;
59
+ for (const value of values) {
60
+ if (!ids.includes(value)) {
61
+ return yield* new IncompatibleStack({ slot: slot.id, value, allowed: ids });
62
+ }
63
+ }
64
+ draft[slot.id] = slot.multi ? values : flag;
65
+ i++;
66
+ continue;
67
+ }
68
+ if (opts.yes || (!slot.multi && options.length <= 1)) {
69
+ draft[slot.id] = defaultFor(slot, options);
70
+ i++;
71
+ continue;
72
+ }
73
+ if (section !== slot.section) {
74
+ section = slot.section;
75
+ yield* io.section(slot.section);
76
+ }
77
+ const choices = options.map((o) => ({ value: o.id, label: o.label, hint: o.hint }));
78
+ const canGoBack = history.length > 0;
79
+ const prev = previous[slot.id];
80
+ const answer = slot.multi
81
+ ? yield* io.multiselect({
82
+ id: slot.id,
83
+ message: slot.title,
84
+ options: choices,
85
+ initial: prev ?? slot.default,
86
+ canGoBack,
87
+ })
88
+ : yield* io.select({
89
+ id: slot.id,
90
+ message: slot.title,
91
+ options: choices,
92
+ initial: prev ?? defaultFor(slot, options),
93
+ canGoBack,
94
+ });
95
+ if (answer === GoBack) {
96
+ const back = history.pop();
97
+ if (back === undefined)
98
+ continue; // cannot happen: first prompt has no Back; re-ask
99
+ for (let j = back; j < slots.length; j++)
100
+ delete draft[slots[j].id];
101
+ section = undefined;
102
+ i = back;
103
+ continue;
104
+ }
105
+ draft[slot.id] = answer;
106
+ previous[slot.id] = answer;
107
+ history.push(i);
108
+ i++;
109
+ }
110
+ return yield* validate({ name, ...draft });
111
+ });
@@ -0,0 +1,97 @@
1
+ import * as p from "@clack/prompts";
2
+ import { Context, Effect, Layer, Schema } from "effect";
3
+ import pc from "picocolors";
4
+ /** Returned by a prompt when the user picked "Back". */
5
+ export const GoBack = Symbol.for("efforge/GoBack");
6
+ export class Cancelled extends Schema.TaggedError()("Cancelled", {}) {
7
+ }
8
+ export class PromptIO extends Context.Service()("efforge/PromptIO") {
9
+ }
10
+ const BACK = "\u0000back";
11
+ const backChoice = { value: BACK, label: pc.dim("← Back") };
12
+ const ask = (run) => Effect.promise(run).pipe(Effect.flatMap((v) => (p.isCancel(v) ? Effect.fail(new Cancelled()) : Effect.succeed(v))));
13
+ const toOption = (c) => (c.hint === undefined
14
+ ? { value: c.value, label: c.label }
15
+ : { value: c.value, label: c.label, hint: c.hint });
16
+ /**
17
+ * clack 1.8.1 has no back/escape signal, so "go back" is a synthetic "← Back"
18
+ * entry: last in a select, and in a multiselect (picking it alone goes back).
19
+ */
20
+ export const livePromptIO = {
21
+ select: (o) => ask(() => p.select({
22
+ message: o.message,
23
+ options: [...o.options.map(toOption), ...(o.canGoBack ? [backChoice] : [])],
24
+ ...(o.initial === undefined ? {} : { initialValue: o.initial }),
25
+ })).pipe(Effect.map((v) => (v === BACK ? GoBack : v))),
26
+ multiselect: (o) => ask(() => p.multiselect({
27
+ message: o.canGoBack
28
+ ? `${o.message} ${pc.dim("(select Back alone to go back)")}`
29
+ : o.message,
30
+ options: [...o.options.map(toOption), ...(o.canGoBack ? [backChoice] : [])],
31
+ initialValues: [...(o.initial ?? [])],
32
+ required: false,
33
+ })).pipe(Effect.map((v) => v.includes(BACK) && v.length === 1 ? GoBack : v.filter((x) => x !== BACK))),
34
+ text: (o) => ask(() => p.text({
35
+ message: o.message,
36
+ ...(o.placeholder === undefined ? {} : { placeholder: o.placeholder }),
37
+ ...(o.defaultValue === undefined ? {} : { defaultValue: o.defaultValue }),
38
+ ...(o.validate === undefined
39
+ ? {}
40
+ : { validate: (v) => o.validate?.(v ?? o.defaultValue ?? "") }),
41
+ })),
42
+ confirm: (o) => ask(() => p.confirm({
43
+ message: o.message,
44
+ ...(o.initial === undefined ? {} : { initialValue: o.initial }),
45
+ })),
46
+ intro: (title) => Effect.sync(() => p.intro(title)),
47
+ section: (title) => Effect.sync(() => p.log.step(pc.bold(title))),
48
+ info: (message) => Effect.sync(() => p.log.info(message)),
49
+ note: (body, title) => Effect.sync(() => p.note(body, title)),
50
+ outro: (message) => Effect.sync(() => p.outro(message)),
51
+ step: (label, eff) => Effect.acquireUseRelease(Effect.sync(() => {
52
+ const s = p.spinner();
53
+ s.start(label);
54
+ return s;
55
+ }), () => eff, (s, exit) => Effect.sync(() => exit._tag === "Success"
56
+ ? s.stop(`${pc.green("✓")} ${label}`)
57
+ : s.error(`${label} failed`))),
58
+ };
59
+ export const PromptIOLive = Layer.succeed(PromptIO, livePromptIO);
60
+ // --- scripted layer (tests) ---------------------------------------------------
61
+ export const CANCEL = Symbol.for("efforge/Cancel");
62
+ /** Answers are consumed in order; running out of answers is a test bug and dies. */
63
+ export const scriptedPromptIO = (answers) => {
64
+ const shown = [];
65
+ const output = [];
66
+ let next = 0;
67
+ const take = (s) => {
68
+ shown.push(s);
69
+ if (next >= answers.length)
70
+ return Effect.die(`scripted PromptIO: no answer left for "${s.id}"`);
71
+ const a = answers[next++];
72
+ return a === CANCEL ? Effect.fail(new Cancelled()) : Effect.succeed(a);
73
+ };
74
+ const io = {
75
+ select: (o) => take({
76
+ kind: "select",
77
+ id: o.id,
78
+ options: o.options.map((c) => c.value),
79
+ canGoBack: o.canGoBack,
80
+ }),
81
+ multiselect: (o) => take({
82
+ kind: "multiselect",
83
+ id: o.id,
84
+ options: o.options.map((c) => c.value),
85
+ canGoBack: o.canGoBack,
86
+ }),
87
+ text: (o) => take({ kind: "text", id: o.id, options: [], canGoBack: false }),
88
+ confirm: (o) => take({ kind: "confirm", id: o.id, options: [], canGoBack: false }),
89
+ intro: (t) => Effect.sync(() => void output.push(`intro: ${t}`)),
90
+ section: (t) => Effect.sync(() => void output.push(`section: ${t}`)),
91
+ info: (m) => Effect.sync(() => void output.push(`info: ${m}`)),
92
+ note: (b, t) => Effect.sync(() => void output.push(`note ${t}: ${b}`)),
93
+ outro: (m) => Effect.sync(() => void output.push(`outro: ${m}`)),
94
+ step: (label, eff) => Effect.sync(() => void output.push(`step: ${label}`)).pipe(Effect.andThen(eff)),
95
+ };
96
+ return { layer: Layer.succeed(PromptIO, io), shown, output };
97
+ };
@@ -0,0 +1,7 @@
1
+ import { exec } from "./exec.js";
2
+ /** Generated projects don't commit `routeTree.gen.ts`; this writes it (TanStack Router's generator). */
3
+ export const ROUTE_TREE_ARGS = ["--filter", "web", "exec", "tsr", "generate"];
4
+ /** The same command as one shell string, for scripts and the e2e helper. */
5
+ export const ROUTE_TREE_COMMAND = ["pnpm", ...ROUTE_TREE_ARGS].join(" ");
6
+ /** Runs after `pnpm install` (the generator is a dev dependency) and before the first format. */
7
+ export const generateRouteTree = (dir) => exec("pnpm", [...ROUTE_TREE_ARGS], dir);
package/dist/rules.js ADDED
@@ -0,0 +1,24 @@
1
+ import { Effect, Schema } from "effect";
2
+ import { available, slots } from "./slots.js";
3
+ import { SlotId } from "./stack.js";
4
+ export class IncompatibleStack extends Schema.TaggedError()("IncompatibleStack", {
5
+ slot: SlotId,
6
+ value: Schema.String,
7
+ allowed: Schema.Array(Schema.String),
8
+ /** extra explanation (e.g. why `add` can't change a slot) */
9
+ reason: Schema.optionalKey(Schema.String),
10
+ }) {
11
+ }
12
+ /** Checks every slot value against `available` given the other choices. */
13
+ export const validate = (config) => Effect.gen(function* () {
14
+ for (const slot of slots) {
15
+ const allowed = available(slot.id, config).map((o) => o.id);
16
+ const values = slot.id === "extras" ? config.extras : [config[slot.id]];
17
+ for (const value of values) {
18
+ if (!allowed.includes(value)) {
19
+ return yield* new IncompatibleStack({ slot: slot.id, value, allowed });
20
+ }
21
+ }
22
+ }
23
+ return config;
24
+ });
package/dist/slots.js ADDED
@@ -0,0 +1,96 @@
1
+ const opt = (slot, id, label, hint) => hint === undefined ? { id, label, slot } : { id, label, hint, slot };
2
+ export const slots = [
3
+ {
4
+ id: "runtime",
5
+ title: "Runtime",
6
+ section: "Platform",
7
+ multi: false,
8
+ default: "cloudflare",
9
+ options: [opt("runtime", "cloudflare", "Cloudflare Workers")],
10
+ },
11
+ {
12
+ id: "database",
13
+ title: "Database",
14
+ section: "Data",
15
+ multi: false,
16
+ default: "postgres",
17
+ options: [
18
+ opt("database", "postgres", "Postgres", "via Hyperdrive"),
19
+ opt("database", "d1", "Cloudflare D1", "SQLite at the edge"),
20
+ opt("database", "none", "None"),
21
+ ],
22
+ },
23
+ {
24
+ id: "orm",
25
+ title: "ORM",
26
+ section: "Data",
27
+ multi: false,
28
+ default: "drizzle",
29
+ options: [
30
+ opt("orm", "drizzle", "Drizzle"),
31
+ opt("orm", "effect-sql", "Effect SQL", "@effect/sql"),
32
+ opt("orm", "none", "None"),
33
+ ],
34
+ },
35
+ {
36
+ id: "auth",
37
+ title: "Auth",
38
+ section: "Data",
39
+ multi: false,
40
+ default: "better-auth-orgs",
41
+ options: [
42
+ opt("auth", "better-auth-orgs", "Better Auth + organizations"),
43
+ opt("auth", "better-auth", "Better Auth"),
44
+ opt("auth", "none", "None"),
45
+ ],
46
+ },
47
+ {
48
+ id: "infra",
49
+ title: "Infrastructure as code",
50
+ section: "Platform",
51
+ multi: false,
52
+ default: "none",
53
+ options: [opt("infra", "none", "None", "wrangler.jsonc"), opt("infra", "alchemy", "Alchemy")],
54
+ },
55
+ {
56
+ id: "ai",
57
+ title: "AI",
58
+ section: "Features",
59
+ multi: false,
60
+ default: "none",
61
+ options: [
62
+ opt("ai", "none", "None"),
63
+ opt("ai", "effect-ai-byok", "Effect AI (bring your own key)"),
64
+ ],
65
+ },
66
+ {
67
+ id: "extras",
68
+ title: "Extras",
69
+ section: "Features",
70
+ multi: true,
71
+ default: [],
72
+ options: [
73
+ opt("extras", "workflows", "Workflows"),
74
+ opt("extras", "realtime", "Realtime"),
75
+ opt("extras", "browser", "Browser rendering"),
76
+ opt("extras", "storage", "Storage"),
77
+ opt("extras", "email", "Email"),
78
+ ],
79
+ },
80
+ ];
81
+ const cloudflareOnly = new Set(["d1", "workflows", "realtime", "browser"]);
82
+ /** Options of `slot` that are compatible with the choices already made in `partial`. */
83
+ export const available = (slot, partial) => {
84
+ const options = slots.find((s) => s.id === slot)?.options ?? [];
85
+ return options.filter((o) => {
86
+ if (cloudflareOnly.has(o.id) &&
87
+ partial.runtime !== undefined &&
88
+ partial.runtime !== "cloudflare")
89
+ return false;
90
+ if (slot === "orm")
91
+ return (partial.database === "none") === (o.id === "none") || partial.database === undefined;
92
+ if (slot === "auth")
93
+ return partial.database !== "none" || o.id === "none";
94
+ return true;
95
+ });
96
+ };