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.
- package/LICENSE +21 -0
- package/README.md +140 -2
- package/dist/addon.js +115 -0
- package/dist/bin.js +6 -0
- package/dist/cli.js +9 -0
- package/dist/commands/add.js +440 -0
- package/dist/commands/create.js +186 -0
- package/dist/diff.js +72 -0
- package/dist/exec.js +20 -0
- package/dist/generate.js +181 -0
- package/dist/manifest.js +14 -0
- package/dist/projectName.js +41 -0
- package/dist/prompts/flow.js +111 -0
- package/dist/prompts/navigable.js +97 -0
- package/dist/routeTree.js +7 -0
- package/dist/rules.js +24 -0
- package/dist/slots.js +96 -0
- package/dist/stack.js +68 -0
- package/dist/transforms/addAlchemyResource.js +71 -0
- package/dist/transforms/addArrayItem.js +31 -0
- package/dist/transforms/addAuthPlugin.js +77 -0
- package/dist/transforms/addDevVar.js +18 -0
- package/dist/transforms/addExport.js +46 -0
- package/dist/transforms/addImport.js +11 -0
- package/dist/transforms/addLayer.js +31 -0
- package/dist/transforms/addServerFnMiddleware.js +62 -0
- package/dist/transforms/addWorkflowSecret.js +43 -0
- package/dist/transforms/addWranglerBinding.js +61 -0
- package/dist/transforms/appendAgentsSection.js +26 -0
- package/dist/transforms/errors.js +7 -0
- package/dist/transforms/index.js +40 -0
- package/dist/transforms/setWranglerValue.js +40 -0
- package/dist/transforms/util.js +219 -0
- package/dist/tree.js +1 -0
- package/dist/versions.js +73 -0
- package/dist/write.js +26 -0
- package/package.json +63 -4
- package/templates/ai/effect-ai-byok/addon.json +619 -0
- package/templates/ai/effect-ai-byok/files/core/llm-crypto.test.ts +47 -0
- package/templates/ai/effect-ai-byok/files/core/llm-crypto.ts +76 -0
- package/templates/ai/effect-ai-byok/files/core/llm-store.ts +21 -0
- package/templates/ai/effect-ai-byok/files/core/llm.ts +32 -0
- package/templates/ai/effect-ai-byok/files/drizzle/d1/20261018161056_llm_credential/migration.sql +9 -0
- package/templates/ai/effect-ai-byok/files/drizzle/d1/20261018161056_llm_credential/snapshot.json +944 -0
- package/templates/ai/effect-ai-byok/files/drizzle/pg/20261018161056_llm_credential/migration.sql +10 -0
- package/templates/ai/effect-ai-byok/files/drizzle/pg/20261018161056_llm_credential/snapshot.json +1232 -0
- package/templates/ai/effect-ai-byok/files/routes/ai.tsx +193 -0
- package/templates/ai/effect-ai-byok/files/schema/d1.ts +16 -0
- package/templates/ai/effect-ai-byok/files/schema/pg.ts +14 -0
- package/templates/ai/effect-ai-byok/files/server/ai-settings.ts +129 -0
- package/templates/ai/effect-ai-byok/files/server/ai.ts +25 -0
- package/templates/ai/effect-ai-byok/files/server/llm-env.ts +48 -0
- package/templates/ai/effect-ai-byok/files/server/llm-orgs.ts +146 -0
- package/templates/ai/effect-ai-byok/files/server/llm-provider.ts +56 -0
- package/templates/ai/effect-ai-byok/files/server/llm-store-drizzle.ts +48 -0
- package/templates/ai/effect-ai-byok/files/server/llm-store-sql-d1.ts +41 -0
- package/templates/ai/effect-ai-byok/files/server/llm-store-sql-pg.ts +41 -0
- package/templates/ai/effect-ai-byok/files/sql/d1.sql +8 -0
- package/templates/ai/effect-ai-byok/files/sql/pg.sql +8 -0
- package/templates/auth/better-auth/addon.json +424 -0
- package/templates/auth/better-auth/files/core/Auth.ts +18 -0
- package/templates/auth/better-auth/files/drizzle/d1/20261018161054_auth/migration.sql +51 -0
- package/templates/auth/better-auth/files/drizzle/d1/20261018161054_auth/snapshot.json +522 -0
- package/templates/auth/better-auth/files/drizzle/pg/20261018161053_auth/migration.sql +51 -0
- package/templates/auth/better-auth/files/drizzle/pg/20261018161053_auth/snapshot.json +680 -0
- package/templates/auth/better-auth/files/lib/auth-client.ts +4 -0
- package/templates/auth/better-auth/files/routes/app.tsx +54 -0
- package/templates/auth/better-auth/files/schema/d1/auth-schema.ts +86 -0
- package/templates/auth/better-auth/files/schema/pg/auth-schema.ts +73 -0
- package/templates/auth/better-auth/files/server/auth-live.ts +47 -0
- package/templates/auth/better-auth/files/server/session.ts +14 -0
- package/templates/auth/better-auth/files/shared/components/auth-card.tsx +32 -0
- package/templates/auth/better-auth/files/shared/components/user-menu.tsx +44 -0
- package/templates/auth/better-auth/files/shared/drizzle/d1/drizzle.config.ts +7 -0
- package/templates/auth/better-auth/files/shared/drizzle/pg/drizzle.config.ts +10 -0
- package/templates/auth/better-auth/files/shared/lib/form.ts +5 -0
- package/templates/auth/better-auth/files/shared/lib/redirect.ts +6 -0
- package/templates/auth/better-auth/files/shared/routes/app/index.tsx +54 -0
- package/templates/auth/better-auth/files/shared/routes/sign-in.tsx +85 -0
- package/templates/auth/better-auth/files/shared/routes/sign-up.tsx +91 -0
- package/templates/auth/better-auth/files/shared/server/auth-route.ts +15 -0
- package/templates/auth/better-auth/files/shared/server/auth.ts +22 -0
- package/templates/auth/better-auth/files/shared/server/db/d1-drizzle.ts +25 -0
- package/templates/auth/better-auth/files/shared/server/db/d1-effect-sql.ts +17 -0
- package/templates/auth/better-auth/files/shared/server/db/pg-drizzle.ts +32 -0
- package/templates/auth/better-auth/files/shared/server/db/pg-effect-sql.ts +29 -0
- package/templates/auth/better-auth/files/shared/server/require-session.ts +20 -0
- package/templates/auth/better-auth/files/sql/d1/0002_auth.sql +13 -0
- package/templates/auth/better-auth/files/sql/pg/0002_auth.sql +13 -0
- package/templates/auth/better-auth-orgs/addon.json +463 -0
- package/templates/auth/better-auth-orgs/files/components/org-switcher.tsx +65 -0
- package/templates/auth/better-auth-orgs/files/core/Auth.ts +20 -0
- package/templates/auth/better-auth-orgs/files/drizzle/d1/20261018161055_auth/migration.sql +88 -0
- package/templates/auth/better-auth-orgs/files/drizzle/d1/20261018161055_auth/snapshot.json +862 -0
- package/templates/auth/better-auth-orgs/files/drizzle/pg/20261018161055_auth/migration.sql +88 -0
- package/templates/auth/better-auth-orgs/files/drizzle/pg/20261018161055_auth/snapshot.json +1127 -0
- package/templates/auth/better-auth-orgs/files/lib/auth-client.ts +5 -0
- package/templates/auth/better-auth-orgs/files/routes/accept-invite.$id.tsx +68 -0
- package/templates/auth/better-auth-orgs/files/routes/app/settings/index.tsx +27 -0
- package/templates/auth/better-auth-orgs/files/routes/app/settings/members.tsx +198 -0
- package/templates/auth/better-auth-orgs/files/routes/app/settings.tsx +30 -0
- package/templates/auth/better-auth-orgs/files/routes/app.tsx +58 -0
- package/templates/auth/better-auth-orgs/files/routes/onboarding.tsx +66 -0
- package/templates/auth/better-auth-orgs/files/schema/d1/auth-schema.ts +139 -0
- package/templates/auth/better-auth-orgs/files/schema/pg/auth-schema.ts +124 -0
- package/templates/auth/better-auth-orgs/files/server/auth-live.ts +52 -0
- package/templates/auth/better-auth-orgs/files/server/session.ts +44 -0
- package/templates/auth/better-auth-orgs/files/sql/d1/0002_auth.sql +27 -0
- package/templates/auth/better-auth-orgs/files/sql/pg/0002_auth.sql +27 -0
- package/templates/base/addon.json +212 -0
- package/templates/base/files/AGENTS.md +70 -0
- package/templates/base/files/CLAUDE.md +1 -0
- package/templates/base/files/README.md +28 -0
- package/templates/base/files/core/package.json +13 -0
- package/templates/base/files/core/src/index.ts +2 -0
- package/templates/base/files/core/test/core.test.ts +4 -0
- package/templates/base/files/core/tsconfig.json +6 -0
- package/templates/base/files/gitignore +11 -0
- package/templates/base/files/pnpm-workspace.yaml +11 -0
- package/templates/base/files/root/package.json +16 -0
- package/templates/base/files/root/tsconfig.base.json +19 -0
- package/templates/base/files/root/turbo.json +9 -0
- package/templates/base/files/root/vite.config.ts +61 -0
- package/templates/base/files/web/components.json +21 -0
- package/templates/base/files/web/package.json +17 -0
- package/templates/base/files/web/src/components/theme-provider.tsx +57 -0
- package/templates/base/files/web/src/components/theme-toggle.tsx +34 -0
- package/templates/base/files/web/src/components/ui/avatar.tsx +93 -0
- package/templates/base/files/web/src/components/ui/button.tsx +61 -0
- package/templates/base/files/web/src/components/ui/card.tsx +74 -0
- package/templates/base/files/web/src/components/ui/dialog.tsx +141 -0
- package/templates/base/files/web/src/components/ui/dropdown-menu.tsx +225 -0
- package/templates/base/files/web/src/components/ui/input.tsx +20 -0
- package/templates/base/files/web/src/components/ui/label.tsx +18 -0
- package/templates/base/files/web/src/components/ui/sonner.tsx +45 -0
- package/templates/base/files/web/src/components/widgets.tsx +4 -0
- package/templates/base/files/web/src/lib/utils.ts +6 -0
- package/templates/base/files/web/src/router.tsx +12 -0
- package/templates/base/files/web/src/routes/__root.tsx +42 -0
- package/templates/base/files/web/src/routes/app/index.tsx +27 -0
- package/templates/base/files/web/src/routes/app/settings.tsx +29 -0
- package/templates/base/files/web/src/routes/app.tsx +47 -0
- package/templates/base/files/web/src/routes/index.tsx +51 -0
- package/templates/base/files/web/src/server/greeting.ts +12 -0
- package/templates/base/files/web/src/server/layers.ts +10 -0
- package/templates/base/files/web/src/server/runtime.ts +5 -0
- package/templates/base/files/web/src/styles.css +81 -0
- package/templates/base/files/web/tsconfig.json +11 -0
- package/templates/base/files/web/vite.config.ts +9 -0
- package/templates/database/d1/addon.json +118 -0
- package/templates/database/d1/files/package.json +12 -0
- package/templates/database/d1/files/tsconfig.json +5 -0
- package/templates/database/postgres/addon.json +142 -0
- package/templates/database/postgres/files/docker-compose.yml +21 -0
- package/templates/database/postgres/files/package.json +12 -0
- package/templates/database/postgres/files/runtime.ts +12 -0
- package/templates/database/postgres/files/tsconfig.json +5 -0
- package/templates/extras/browser/addon.json +173 -0
- package/templates/extras/browser/files/BrowserContainer.ts +14 -0
- package/templates/extras/browser/files/app/Dockerfile +15 -0
- package/templates/extras/browser/files/app/dockerignore +1 -0
- package/templates/extras/browser/files/app/package-lock +605 -0
- package/templates/extras/browser/files/app/package.json +9 -0
- package/templates/extras/browser/files/app/src/server.ts +78 -0
- package/templates/extras/browser/files/app/src/url-policy.ts +115 -0
- package/templates/extras/browser/files/app/tsconfig.json +6 -0
- package/templates/extras/browser/files/browser.ts +34 -0
- package/templates/extras/browser/files/core-browser.ts +21 -0
- package/templates/extras/browser/files/run-browser.ts +25 -0
- package/templates/extras/email/addon.json +182 -0
- package/templates/extras/email/files/core-mailer.ts +28 -0
- package/templates/extras/email/files/invitation-email.ts +38 -0
- package/templates/extras/email/files/mailer.ts +58 -0
- package/templates/extras/realtime/addon.json +135 -0
- package/templates/extras/realtime/files/Room.ts +46 -0
- package/templates/extras/realtime/files/core-realtime.ts +19 -0
- package/templates/extras/realtime/files/realtime-demo.tsx +40 -0
- package/templates/extras/realtime/files/realtime-limits.test.ts +32 -0
- package/templates/extras/realtime/files/realtime-limits.ts +35 -0
- package/templates/extras/realtime/files/realtime-route.ts +39 -0
- package/templates/extras/realtime/files/realtime.ts +39 -0
- package/templates/extras/realtime/files/use-room.ts +67 -0
- package/templates/extras/storage/addon.json +132 -0
- package/templates/extras/storage/files/core-storage.ts +64 -0
- package/templates/extras/storage/files/storage-route.ts +50 -0
- package/templates/extras/storage/files/storage-security.test.ts +71 -0
- package/templates/extras/storage/files/storage-security.ts +92 -0
- package/templates/extras/storage/files/storage.ts +84 -0
- package/templates/extras/workflows/addon.json +95 -0
- package/templates/extras/workflows/files/Example.ts +42 -0
- package/templates/extras/workflows/files/core-jobs.ts +45 -0
- package/templates/extras/workflows/files/example-job.ts +36 -0
- package/templates/extras/workflows/files/jobs.ts +34 -0
- package/templates/infra/alchemy/addon.json +37 -0
- package/templates/infra/alchemy/files/README.md +27 -0
- package/templates/infra/alchemy/files/alchemy.run.ts +36 -0
- package/templates/infra/alchemy/files/github/deploy.yml +63 -0
- package/templates/infra/alchemy/files/tsconfig.json +5 -0
- package/templates/infra/alchemy/files/vite.config.ts +30 -0
- package/templates/orm/drizzle/addon.json +188 -0
- package/templates/orm/drizzle/files/d1/Database.ts +7 -0
- package/templates/orm/drizzle/files/d1/drizzle/20261018154417_init/migration.sql +10 -0
- package/templates/orm/drizzle/files/d1/drizzle/20261018154417_init/snapshot.json +60 -0
- package/templates/orm/drizzle/files/d1/drizzle.config.ts +7 -0
- package/templates/orm/drizzle/files/d1/layer.ts +13 -0
- package/templates/orm/drizzle/files/d1/migrate.ts +37 -0
- package/templates/orm/drizzle/files/d1/schema.ts +15 -0
- package/templates/orm/drizzle/files/pg/Database.ts +7 -0
- package/templates/orm/drizzle/files/pg/drizzle/20261018154416_init/migration.sql +10 -0
- package/templates/orm/drizzle/files/pg/drizzle/20261018154416_init/snapshot.json +75 -0
- package/templates/orm/drizzle/files/pg/drizzle.config.ts +10 -0
- package/templates/orm/drizzle/files/pg/layer.ts +16 -0
- package/templates/orm/drizzle/files/pg/migrate.ts +24 -0
- package/templates/orm/drizzle/files/pg/schema.ts +11 -0
- package/templates/orm/drizzle/files/shared/index.ts +2 -0
- package/templates/orm/drizzle/files/shared/notes.ts +15 -0
- package/templates/orm/drizzle/files/shared/page.tsx +50 -0
- package/templates/orm/effect-sql/addon.json +124 -0
- package/templates/orm/effect-sql/files/d1/layer.ts +13 -0
- package/templates/orm/effect-sql/files/d1/migrate.ts +20 -0
- package/templates/orm/effect-sql/files/d1/schema.ts +7 -0
- package/templates/orm/effect-sql/files/d1-sql/0001_init.sql +10 -0
- package/templates/orm/effect-sql/files/pg/layer.ts +16 -0
- package/templates/orm/effect-sql/files/pg/migrate.ts +66 -0
- package/templates/orm/effect-sql/files/pg/schema.ts +7 -0
- package/templates/orm/effect-sql/files/pg-sql/0001_init.sql +10 -0
- package/templates/orm/effect-sql/files/shared/Database.ts +7 -0
- package/templates/orm/effect-sql/files/shared/index.ts +2 -0
- package/templates/orm/effect-sql/files/shared/notes.ts +18 -0
- package/templates/orm/effect-sql/files/shared/page.tsx +50 -0
- package/templates/runtime/cloudflare/addon.json +52 -0
- package/templates/runtime/cloudflare/files/cloudflare.ts +10 -0
- package/templates/runtime/cloudflare/files/routes.ts +5 -0
- package/templates/runtime/cloudflare/files/server.ts +22 -0
- package/templates/runtime/cloudflare/files/tsconfig.json +12 -0
- package/templates/runtime/cloudflare/files/vite.config.ts +20 -0
- package/templates/runtime/cloudflare/files/wrangler.jsonc +8 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "database/d1",
|
|
3
|
+
"title": "Cloudflare D1",
|
|
4
|
+
"description": "A D1 binding (SQLite on Cloudflare) and the `@repo/db` package.",
|
|
5
|
+
"files": [
|
|
6
|
+
{
|
|
7
|
+
"path": "files/package.json",
|
|
8
|
+
"target": "packages/db/package.json"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"path": "files/tsconfig.json",
|
|
12
|
+
"target": "packages/db/tsconfig.json"
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"apps/web": [
|
|
17
|
+
"@repo/db"
|
|
18
|
+
],
|
|
19
|
+
"packages/db": [
|
|
20
|
+
"@repo/core",
|
|
21
|
+
"@effect/sql-d1",
|
|
22
|
+
"effect",
|
|
23
|
+
"effect-cf"
|
|
24
|
+
],
|
|
25
|
+
"packages/core": [
|
|
26
|
+
"@effect/sql-d1"
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"packages/db": [
|
|
31
|
+
"@cloudflare/workers-types",
|
|
32
|
+
"@types/node",
|
|
33
|
+
"typescript",
|
|
34
|
+
"wrangler"
|
|
35
|
+
],
|
|
36
|
+
"packages/core": [
|
|
37
|
+
"@cloudflare/workers-types"
|
|
38
|
+
]
|
|
39
|
+
},
|
|
40
|
+
"envVars": [],
|
|
41
|
+
"requires": [],
|
|
42
|
+
"conflicts": [],
|
|
43
|
+
"transforms": [
|
|
44
|
+
{
|
|
45
|
+
"name": "addWranglerBinding",
|
|
46
|
+
"args": {
|
|
47
|
+
"key": "d1_databases",
|
|
48
|
+
"value": "{\"binding\": \"DB\", \"database_name\": \"app\", \"database_id\": \"00000000-0000-0000-0000-000000000000\", \"migrations_dir\": \"packages/db/migrations\"}"
|
|
49
|
+
},
|
|
50
|
+
"when": {
|
|
51
|
+
"infra": [
|
|
52
|
+
"none"
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"name": "addAlchemyResource",
|
|
58
|
+
"args": {
|
|
59
|
+
"name": "database",
|
|
60
|
+
"code": "const database = yield* Cloudflare.D1.Database(\"Database\", {\n migrations: \"packages/db/drizzle\",\n})",
|
|
61
|
+
"binding": "DB"
|
|
62
|
+
},
|
|
63
|
+
"when": {
|
|
64
|
+
"infra": [
|
|
65
|
+
"alchemy"
|
|
66
|
+
],
|
|
67
|
+
"orm": [
|
|
68
|
+
"drizzle"
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"name": "addAlchemyResource",
|
|
74
|
+
"args": {
|
|
75
|
+
"name": "database",
|
|
76
|
+
"code": "const database = yield* Cloudflare.D1.Database(\"Database\", {\n migrations: \"packages/db/migrations\",\n})",
|
|
77
|
+
"binding": "DB"
|
|
78
|
+
},
|
|
79
|
+
"when": {
|
|
80
|
+
"infra": [
|
|
81
|
+
"alchemy"
|
|
82
|
+
],
|
|
83
|
+
"orm": [
|
|
84
|
+
"effect-sql"
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
"name": "appendAgentsSection",
|
|
90
|
+
"args": {
|
|
91
|
+
"id": "database",
|
|
92
|
+
"content": "## Database (D1, Drizzle)\n\n- Tables live in `packages/db/src/schema.ts`; queries go through the `Database` service from `@repo/core`.\n- Change the schema, then run `pnpm --filter @repo/db db:generate` to write a migration to `packages/db/drizzle/`, then `pnpm db:migrate` (flattens them into `packages/db/migrations/` and applies them locally).\n- Never edit files under `packages/db/drizzle/` or `packages/db/migrations/` by hand; they are generated."
|
|
93
|
+
},
|
|
94
|
+
"when": {
|
|
95
|
+
"orm": [
|
|
96
|
+
"drizzle"
|
|
97
|
+
]
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"name": "appendAgentsSection",
|
|
102
|
+
"args": {
|
|
103
|
+
"id": "database",
|
|
104
|
+
"content": "## Database (D1, effect-sql)\n\n- Migrations are plain SQL files in `packages/db/migrations/`, named `NNNN_name.sql` and applied in order by `pnpm db:migrate` (wrangler, local D1).\n- Add a new file for every schema change; never edit one that has already been applied.\n- Queries go through the `Database` service from `@repo/core`."
|
|
105
|
+
},
|
|
106
|
+
"when": {
|
|
107
|
+
"orm": [
|
|
108
|
+
"effect-sql"
|
|
109
|
+
]
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
],
|
|
113
|
+
"scripts": {
|
|
114
|
+
".": {
|
|
115
|
+
"db:migrate": "pnpm --filter @repo/db db:migrate"
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "database/postgres",
|
|
3
|
+
"title": "Postgres",
|
|
4
|
+
"description": "Postgres reached through a Hyperdrive binding on Workers, with a local docker-compose database and the `@repo/db` package.",
|
|
5
|
+
"files": [
|
|
6
|
+
{
|
|
7
|
+
"path": "files/docker-compose.yml",
|
|
8
|
+
"target": "docker-compose.yml"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"path": "files/package.json",
|
|
12
|
+
"target": "packages/db/package.json"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"path": "files/tsconfig.json",
|
|
16
|
+
"target": "packages/db/tsconfig.json"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"path": "files/runtime.ts",
|
|
20
|
+
"target": "apps/web/src/server/runtime.ts"
|
|
21
|
+
}
|
|
22
|
+
],
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"apps/web": [
|
|
25
|
+
"@repo/db",
|
|
26
|
+
"pg"
|
|
27
|
+
],
|
|
28
|
+
"packages/db": [
|
|
29
|
+
"@repo/core",
|
|
30
|
+
"@effect/sql-pg",
|
|
31
|
+
"effect",
|
|
32
|
+
"effect-cf"
|
|
33
|
+
],
|
|
34
|
+
"packages/core": [
|
|
35
|
+
"@effect/sql-pg"
|
|
36
|
+
]
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"packages/db": [
|
|
40
|
+
"@cloudflare/workers-types",
|
|
41
|
+
"@types/node",
|
|
42
|
+
"typescript"
|
|
43
|
+
],
|
|
44
|
+
"packages/core": [
|
|
45
|
+
"@cloudflare/workers-types"
|
|
46
|
+
],
|
|
47
|
+
"apps/web": [
|
|
48
|
+
"@types/pg"
|
|
49
|
+
]
|
|
50
|
+
},
|
|
51
|
+
"envVars": [
|
|
52
|
+
{
|
|
53
|
+
"name": "DATABASE_URL",
|
|
54
|
+
"example": "postgres://postgres:postgres@localhost:5432/app",
|
|
55
|
+
"description": "Used by `pnpm db:migrate` and drizzle-kit; the running app connects through the HYPERDRIVE binding."
|
|
56
|
+
}
|
|
57
|
+
],
|
|
58
|
+
"requires": [],
|
|
59
|
+
"conflicts": [],
|
|
60
|
+
"transforms": [
|
|
61
|
+
{
|
|
62
|
+
"name": "addWranglerBinding",
|
|
63
|
+
"args": {
|
|
64
|
+
"key": "hyperdrive",
|
|
65
|
+
"value": "{\"binding\": \"HYPERDRIVE\", \"id\": \"00000000000000000000000000000000\", \"localConnectionString\": \"postgres://postgres:postgres@localhost:5432/app\"}"
|
|
66
|
+
},
|
|
67
|
+
"when": {
|
|
68
|
+
"infra": [
|
|
69
|
+
"none"
|
|
70
|
+
]
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"name": "addImport",
|
|
75
|
+
"args": {
|
|
76
|
+
"file": "infra/alchemy.run.ts",
|
|
77
|
+
"import": "* as Config",
|
|
78
|
+
"from": "effect/Config"
|
|
79
|
+
},
|
|
80
|
+
"when": {
|
|
81
|
+
"infra": [
|
|
82
|
+
"alchemy"
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"name": "addImport",
|
|
88
|
+
"args": {
|
|
89
|
+
"file": "infra/alchemy.run.ts",
|
|
90
|
+
"import": "* as Redacted",
|
|
91
|
+
"from": "effect/Redacted"
|
|
92
|
+
},
|
|
93
|
+
"when": {
|
|
94
|
+
"infra": [
|
|
95
|
+
"alchemy"
|
|
96
|
+
]
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
"name": "addAlchemyResource",
|
|
101
|
+
"args": {
|
|
102
|
+
"name": "hyperdrive",
|
|
103
|
+
"code": "const databaseUrl = new URL(Redacted.value(yield* Config.Redacted(\"DATABASE_URL\")))\nconst hyperdrive = yield* Cloudflare.Hyperdrive.Connection(\"Hyperdrive\", {\n origin: {\n scheme: \"postgres\",\n host: databaseUrl.hostname,\n port: Number(databaseUrl.port || 5432),\n database: databaseUrl.pathname.slice(1),\n user: decodeURIComponent(databaseUrl.username),\n password: Redacted.make(decodeURIComponent(databaseUrl.password)),\n },\n // writes must be visible to the next read, so only pool connections, don't cache queries\n caching: { disabled: true },\n})",
|
|
104
|
+
"binding": "HYPERDRIVE"
|
|
105
|
+
},
|
|
106
|
+
"when": {
|
|
107
|
+
"infra": [
|
|
108
|
+
"alchemy"
|
|
109
|
+
]
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
"name": "appendAgentsSection",
|
|
114
|
+
"args": {
|
|
115
|
+
"id": "database",
|
|
116
|
+
"content": "## Database (Postgres, Drizzle)\n\n- Tables live in `packages/db/src/schema.ts`; queries go through the `Database` service from `@repo/core`.\n- Change the schema, then run `pnpm --filter @repo/db db:generate` to write a migration to `packages/db/drizzle/`, then `pnpm db:migrate`.\n- Never edit files under `packages/db/drizzle/` by hand; they are generated.\n- Start the local database with `docker compose up -d`."
|
|
117
|
+
},
|
|
118
|
+
"when": {
|
|
119
|
+
"orm": [
|
|
120
|
+
"drizzle"
|
|
121
|
+
]
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
"name": "appendAgentsSection",
|
|
126
|
+
"args": {
|
|
127
|
+
"id": "database",
|
|
128
|
+
"content": "## Database (Postgres, effect-sql)\n\n- Migrations are plain SQL files in `packages/db/migrations/`, named `NNNN_name.sql` and applied in order by `pnpm db:migrate`.\n- Add a new file for every schema change; never edit one that has already been applied.\n- Put one statement per `;` and keep string literals free of `;` (the runner splits on it).\n- Queries go through the `Database` service from `@repo/core`. Start the local database with `docker compose up -d`."
|
|
129
|
+
},
|
|
130
|
+
"when": {
|
|
131
|
+
"orm": [
|
|
132
|
+
"effect-sql"
|
|
133
|
+
]
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
],
|
|
137
|
+
"scripts": {
|
|
138
|
+
".": {
|
|
139
|
+
"db:migrate": "pnpm --filter @repo/db db:migrate"
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Local Postgres for development: `docker compose up -d`, then `pnpm db:migrate`.
|
|
2
|
+
services:
|
|
3
|
+
postgres:
|
|
4
|
+
image: postgres:17
|
|
5
|
+
restart: unless-stopped
|
|
6
|
+
environment:
|
|
7
|
+
POSTGRES_USER: postgres
|
|
8
|
+
POSTGRES_PASSWORD: postgres
|
|
9
|
+
POSTGRES_DB: app
|
|
10
|
+
ports:
|
|
11
|
+
- "5432:5432"
|
|
12
|
+
volumes:
|
|
13
|
+
- postgres-data:/var/lib/postgresql/data
|
|
14
|
+
healthcheck:
|
|
15
|
+
test: ["CMD-SHELL", "pg_isready -U postgres -d app"]
|
|
16
|
+
interval: 5s
|
|
17
|
+
timeout: 3s
|
|
18
|
+
retries: 10
|
|
19
|
+
|
|
20
|
+
volumes:
|
|
21
|
+
postgres-data:
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Effect, type Layer } from "effect"
|
|
2
|
+
import { AppLayer } from "./layers"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Server functions run their Effects through here. Workers must not reuse I/O (such as a
|
|
6
|
+
* Postgres socket) across requests, so unlike a `ManagedRuntime` this builds `AppLayer` for each
|
|
7
|
+
* call and closes it afterwards; Hyperdrive pools the connections behind it.
|
|
8
|
+
*/
|
|
9
|
+
export const runtime = {
|
|
10
|
+
runPromise: <A, E>(effect: Effect.Effect<A, E, Layer.Success<typeof AppLayer>>): Promise<A> =>
|
|
11
|
+
Effect.runPromise(Effect.provide(effect, AppLayer)),
|
|
12
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "extras/browser",
|
|
3
|
+
"title": "Browser",
|
|
4
|
+
"description": "A headless browser: a Browser service on a Cloudflare Container that runs Playwright (apps/browser).",
|
|
5
|
+
"files": [
|
|
6
|
+
{
|
|
7
|
+
"path": "files/core-browser.ts",
|
|
8
|
+
"target": "packages/core/src/browser.ts"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"path": "files/BrowserContainer.ts",
|
|
12
|
+
"target": "apps/web/src/browser/BrowserContainer.ts"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"path": "files/browser.ts",
|
|
16
|
+
"target": "apps/web/src/server/browser.ts"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"path": "files/run-browser.ts",
|
|
20
|
+
"target": "apps/web/src/server/run-browser.ts"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"path": "files/app/Dockerfile",
|
|
24
|
+
"target": "apps/browser/Dockerfile"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"path": "files/app/dockerignore",
|
|
28
|
+
"target": "apps/browser/.dockerignore"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"path": "files/app/package.json",
|
|
32
|
+
"target": "apps/browser/package.json"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"path": "files/app/tsconfig.json",
|
|
36
|
+
"target": "apps/browser/tsconfig.json"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"path": "files/app/package-lock",
|
|
40
|
+
"target": "apps/browser/package-lock.json"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"path": "files/app/src/url-policy.ts",
|
|
44
|
+
"target": "apps/browser/src/url-policy.ts"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"path": "files/app/src/server.ts",
|
|
48
|
+
"target": "apps/browser/src/server.ts"
|
|
49
|
+
}
|
|
50
|
+
],
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"apps/web": [
|
|
53
|
+
"@cloudflare/containers"
|
|
54
|
+
],
|
|
55
|
+
"apps/browser": [
|
|
56
|
+
"@effect/platform-node",
|
|
57
|
+
"effect",
|
|
58
|
+
"playwright"
|
|
59
|
+
]
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"apps/browser": [
|
|
63
|
+
"@types/node",
|
|
64
|
+
"typescript"
|
|
65
|
+
]
|
|
66
|
+
},
|
|
67
|
+
"envVars": [],
|
|
68
|
+
"requires": [],
|
|
69
|
+
"conflicts": [],
|
|
70
|
+
"transforms": [
|
|
71
|
+
{
|
|
72
|
+
"name": "addExport",
|
|
73
|
+
"args": {
|
|
74
|
+
"file": "packages/core/src/index.ts",
|
|
75
|
+
"export": "*",
|
|
76
|
+
"from": "./browser"
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"name": "addExport",
|
|
81
|
+
"args": {
|
|
82
|
+
"file": "apps/web/src/server.ts",
|
|
83
|
+
"export": "BrowserContainer",
|
|
84
|
+
"from": "./browser/BrowserContainer"
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
"name": "addLayer",
|
|
89
|
+
"args": {
|
|
90
|
+
"file": "apps/web/src/server/layers.ts",
|
|
91
|
+
"import": "BrowserLive",
|
|
92
|
+
"from": "./browser",
|
|
93
|
+
"layer": "BrowserLive"
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"name": "addWranglerBinding",
|
|
98
|
+
"args": {
|
|
99
|
+
"key": "durable_objects.bindings",
|
|
100
|
+
"value": "{\"name\":\"BROWSER\",\"class_name\":\"BrowserContainer\"}"
|
|
101
|
+
},
|
|
102
|
+
"when": {
|
|
103
|
+
"infra": [
|
|
104
|
+
"none"
|
|
105
|
+
]
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"name": "addWranglerBinding",
|
|
110
|
+
"args": {
|
|
111
|
+
"key": "migrations",
|
|
112
|
+
"value": "{\"tag\":\"browser-v1\",\"new_sqlite_classes\":[\"BrowserContainer\"]}"
|
|
113
|
+
},
|
|
114
|
+
"when": {
|
|
115
|
+
"infra": [
|
|
116
|
+
"none"
|
|
117
|
+
]
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"name": "addWranglerBinding",
|
|
122
|
+
"args": {
|
|
123
|
+
"key": "containers",
|
|
124
|
+
"value": "{\"class_name\":\"BrowserContainer\",\"image\":\"./apps/browser/Dockerfile\",\"max_instances\":2}"
|
|
125
|
+
},
|
|
126
|
+
"when": {
|
|
127
|
+
"infra": [
|
|
128
|
+
"none"
|
|
129
|
+
]
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
"name": "setWranglerValue",
|
|
134
|
+
"args": {
|
|
135
|
+
"key": "dev.enable_containers",
|
|
136
|
+
"value": "false"
|
|
137
|
+
},
|
|
138
|
+
"when": {
|
|
139
|
+
"infra": [
|
|
140
|
+
"none"
|
|
141
|
+
]
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
"name": "addAlchemyResource",
|
|
146
|
+
"args": {
|
|
147
|
+
"name": "browser",
|
|
148
|
+
"code": "const browser = Cloudflare.Container(\"Browser\", {\n className: \"BrowserContainer\",\n context: \"apps/browser\",\n maxInstances: 2,\n})",
|
|
149
|
+
"binding": "BROWSER"
|
|
150
|
+
},
|
|
151
|
+
"when": {
|
|
152
|
+
"infra": [
|
|
153
|
+
"alchemy"
|
|
154
|
+
]
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
"name": "addServerFnMiddleware",
|
|
159
|
+
"args": {
|
|
160
|
+
"file": "apps/web/src/server/run-browser.ts",
|
|
161
|
+
"middleware": "requireSession",
|
|
162
|
+
"import": "requireSession",
|
|
163
|
+
"from": "./require-session"
|
|
164
|
+
},
|
|
165
|
+
"when": {
|
|
166
|
+
"auth": [
|
|
167
|
+
"better-auth",
|
|
168
|
+
"better-auth-orgs"
|
|
169
|
+
]
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
]
|
|
173
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Container } from "@cloudflare/containers"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Runs the image built from `apps/browser/Dockerfile`. Cloudflare starts it on the first request
|
|
5
|
+
* and stops it after `sleepAfter` without traffic. Bound as BROWSER (wrangler.jsonc or infra/alchemy.run.ts) and exported
|
|
6
|
+
* from `src/server.ts`.
|
|
7
|
+
*
|
|
8
|
+
* `pnpm dev` doesn't start containers (`dev.enable_containers` is false in wrangler.jsonc), so it
|
|
9
|
+
* works without Docker and Browser calls fail locally. Set it to true to run the image locally.
|
|
10
|
+
*/
|
|
11
|
+
export class BrowserContainer extends Container {
|
|
12
|
+
defaultPort = 8080
|
|
13
|
+
sleepAfter = "5m"
|
|
14
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Keep this tag in step with the `playwright` version in package.json: the image ships matching browsers.
|
|
2
|
+
FROM mcr.microsoft.com/playwright:v1.64.1-noble
|
|
3
|
+
|
|
4
|
+
WORKDIR /app
|
|
5
|
+
# package-lock.json pins the whole dependency tree: `npm ci` fails instead of drifting when it
|
|
6
|
+
# disagrees with package.json. After changing a dependency, run `npm install --package-lock-only`.
|
|
7
|
+
COPY --chown=pwuser:pwuser package.json package-lock.json ./
|
|
8
|
+
RUN npm ci --omit=dev --no-audit --no-fund && chown -R pwuser:pwuser /app
|
|
9
|
+
COPY --chown=pwuser:pwuser src ./src
|
|
10
|
+
|
|
11
|
+
# the image ships an unprivileged user; Chromium runs with --no-sandbox because containers can't nest sandboxes
|
|
12
|
+
USER pwuser
|
|
13
|
+
ENV PORT=8080
|
|
14
|
+
EXPOSE 8080
|
|
15
|
+
CMD ["node", "--experimental-strip-types", "src/server.ts"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
node_modules
|