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,188 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "orm/drizzle",
|
|
3
|
+
"title": "Drizzle ORM",
|
|
4
|
+
"description": "Drizzle 1.0 with its Effect drivers behind the Database service; migrations come from drizzle-kit.",
|
|
5
|
+
"files": [
|
|
6
|
+
{
|
|
7
|
+
"path": "files/shared/index.ts",
|
|
8
|
+
"target": "packages/db/src/index.ts"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"path": "files/shared/notes.ts",
|
|
12
|
+
"target": "apps/web/src/server/notes.ts"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"path": "files/shared/page.tsx",
|
|
16
|
+
"target": "apps/web/src/routes/app/index.tsx"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"path": "files/pg/layer.ts",
|
|
20
|
+
"target": "packages/db/src/layer.ts",
|
|
21
|
+
"when": {
|
|
22
|
+
"database": [
|
|
23
|
+
"postgres"
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"path": "files/pg/schema.ts",
|
|
29
|
+
"target": "packages/db/src/schema.ts",
|
|
30
|
+
"when": {
|
|
31
|
+
"database": [
|
|
32
|
+
"postgres"
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"path": "files/pg/migrate.ts",
|
|
38
|
+
"target": "packages/db/scripts/migrate.ts",
|
|
39
|
+
"when": {
|
|
40
|
+
"database": [
|
|
41
|
+
"postgres"
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"path": "files/d1/layer.ts",
|
|
47
|
+
"target": "packages/db/src/layer.ts",
|
|
48
|
+
"when": {
|
|
49
|
+
"database": [
|
|
50
|
+
"d1"
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"path": "files/d1/schema.ts",
|
|
56
|
+
"target": "packages/db/src/schema.ts",
|
|
57
|
+
"when": {
|
|
58
|
+
"database": [
|
|
59
|
+
"d1"
|
|
60
|
+
]
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"path": "files/d1/migrate.ts",
|
|
65
|
+
"target": "packages/db/scripts/migrate.ts",
|
|
66
|
+
"when": {
|
|
67
|
+
"database": [
|
|
68
|
+
"d1"
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"path": "files/pg/Database.ts",
|
|
74
|
+
"target": "packages/core/src/Database.ts",
|
|
75
|
+
"when": {
|
|
76
|
+
"database": [
|
|
77
|
+
"postgres"
|
|
78
|
+
]
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"path": "files/pg/drizzle.config.ts",
|
|
83
|
+
"target": "packages/db/drizzle.config.ts",
|
|
84
|
+
"when": {
|
|
85
|
+
"database": [
|
|
86
|
+
"postgres"
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"path": "files/d1/Database.ts",
|
|
92
|
+
"target": "packages/core/src/Database.ts",
|
|
93
|
+
"when": {
|
|
94
|
+
"database": [
|
|
95
|
+
"d1"
|
|
96
|
+
]
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
"path": "files/d1/drizzle.config.ts",
|
|
101
|
+
"target": "packages/db/drizzle.config.ts",
|
|
102
|
+
"when": {
|
|
103
|
+
"database": [
|
|
104
|
+
"d1"
|
|
105
|
+
]
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"path": "files/pg/drizzle/20261018154416_init/migration.sql",
|
|
110
|
+
"target": "packages/db/drizzle/20261018154416_init/migration.sql",
|
|
111
|
+
"when": {
|
|
112
|
+
"database": [
|
|
113
|
+
"postgres"
|
|
114
|
+
]
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
"path": "files/pg/drizzle/20261018154416_init/snapshot.json",
|
|
119
|
+
"target": "packages/db/drizzle/20261018154416_init/snapshot.json",
|
|
120
|
+
"when": {
|
|
121
|
+
"database": [
|
|
122
|
+
"postgres"
|
|
123
|
+
]
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
"path": "files/d1/drizzle/20261018154417_init/migration.sql",
|
|
128
|
+
"target": "packages/db/drizzle/20261018154417_init/migration.sql",
|
|
129
|
+
"when": {
|
|
130
|
+
"database": [
|
|
131
|
+
"d1"
|
|
132
|
+
]
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"path": "files/d1/drizzle/20261018154417_init/snapshot.json",
|
|
137
|
+
"target": "packages/db/drizzle/20261018154417_init/snapshot.json",
|
|
138
|
+
"when": {
|
|
139
|
+
"database": [
|
|
140
|
+
"d1"
|
|
141
|
+
]
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
],
|
|
145
|
+
"dependencies": {
|
|
146
|
+
"apps/web": [
|
|
147
|
+
"drizzle-orm"
|
|
148
|
+
],
|
|
149
|
+
"packages/core": [
|
|
150
|
+
"drizzle-orm"
|
|
151
|
+
],
|
|
152
|
+
"packages/db": [
|
|
153
|
+
"drizzle-orm"
|
|
154
|
+
]
|
|
155
|
+
},
|
|
156
|
+
"devDependencies": {
|
|
157
|
+
"packages/db": [
|
|
158
|
+
"drizzle-kit"
|
|
159
|
+
]
|
|
160
|
+
},
|
|
161
|
+
"scripts": {
|
|
162
|
+
"packages/db": {
|
|
163
|
+
"db:generate": "drizzle-kit generate"
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
"envVars": [],
|
|
167
|
+
"requires": [],
|
|
168
|
+
"conflicts": [],
|
|
169
|
+
"transforms": [
|
|
170
|
+
{
|
|
171
|
+
"name": "addImport",
|
|
172
|
+
"args": {
|
|
173
|
+
"file": "apps/web/src/server/layers.ts",
|
|
174
|
+
"import": "WorkerEnvLive",
|
|
175
|
+
"from": "./cloudflare"
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
"name": "addLayer",
|
|
180
|
+
"args": {
|
|
181
|
+
"file": "apps/web/src/server/layers.ts",
|
|
182
|
+
"import": "DatabaseLayer",
|
|
183
|
+
"from": "@repo/db",
|
|
184
|
+
"layer": "DatabaseLayer.pipe(Layer.provide(WorkerEnvLive))"
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
]
|
|
188
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { EffectSQLiteD1Database } from "drizzle-orm/effect-d1"
|
|
2
|
+
import { Context } from "effect"
|
|
3
|
+
|
|
4
|
+
/** The app's database, as a Drizzle client whose queries are Effects. */
|
|
5
|
+
export class Database extends Context.Service<Database, { readonly db: EffectSQLiteD1Database }>()(
|
|
6
|
+
"@repo/core/Database",
|
|
7
|
+
) {}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
CREATE TABLE `note` (
|
|
2
|
+
`id` text PRIMARY KEY,
|
|
3
|
+
`org_id` text,
|
|
4
|
+
`title` text NOT NULL,
|
|
5
|
+
`created_at` integer NOT NULL
|
|
6
|
+
);
|
|
7
|
+
--> statement-breakpoint
|
|
8
|
+
INSERT INTO `note` (`id`, `title`, `created_at`) VALUES
|
|
9
|
+
('seed-1', 'Welcome to your new app', unixepoch() * 1000),
|
|
10
|
+
('seed-2', 'Notes are read through the Database service', unixepoch() * 1000);
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "7",
|
|
3
|
+
"dialect": "sqlite",
|
|
4
|
+
"id": "968d9e91-9cdc-4049-a188-fcc34553861c",
|
|
5
|
+
"prevIds": ["00000000-0000-0000-0000-000000000000"],
|
|
6
|
+
"ddl": [
|
|
7
|
+
{
|
|
8
|
+
"name": "note",
|
|
9
|
+
"entityType": "tables"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"type": "text",
|
|
13
|
+
"notNull": false,
|
|
14
|
+
"autoincrement": false,
|
|
15
|
+
"default": null,
|
|
16
|
+
"generated": null,
|
|
17
|
+
"name": "id",
|
|
18
|
+
"entityType": "columns",
|
|
19
|
+
"table": "note"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"type": "text",
|
|
23
|
+
"notNull": false,
|
|
24
|
+
"autoincrement": false,
|
|
25
|
+
"default": null,
|
|
26
|
+
"generated": null,
|
|
27
|
+
"name": "org_id",
|
|
28
|
+
"entityType": "columns",
|
|
29
|
+
"table": "note"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"type": "text",
|
|
33
|
+
"notNull": true,
|
|
34
|
+
"autoincrement": false,
|
|
35
|
+
"default": null,
|
|
36
|
+
"generated": null,
|
|
37
|
+
"name": "title",
|
|
38
|
+
"entityType": "columns",
|
|
39
|
+
"table": "note"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"type": "integer",
|
|
43
|
+
"notNull": true,
|
|
44
|
+
"autoincrement": false,
|
|
45
|
+
"default": null,
|
|
46
|
+
"generated": null,
|
|
47
|
+
"name": "created_at",
|
|
48
|
+
"entityType": "columns",
|
|
49
|
+
"table": "note"
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"columns": ["id"],
|
|
53
|
+
"nameExplicit": false,
|
|
54
|
+
"name": "note_pk",
|
|
55
|
+
"table": "note",
|
|
56
|
+
"entityType": "pks"
|
|
57
|
+
}
|
|
58
|
+
],
|
|
59
|
+
"renames": []
|
|
60
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Database } from "@repo/core/Database"
|
|
2
|
+
import * as D1Drizzle from "drizzle-orm/effect-d1"
|
|
3
|
+
import { Effect, Layer } from "effect"
|
|
4
|
+
import { D1 } from "effect-cf"
|
|
5
|
+
|
|
6
|
+
/** The `DB` binding from wrangler.jsonc. */
|
|
7
|
+
class AppD1 extends D1.Service<AppD1>()("AppD1", { binding: "DB" }) {}
|
|
8
|
+
|
|
9
|
+
/** Provides `Database`. Needs effect-cf's `WorkerEnvironment` (see apps/web/src/server/cloudflare.ts). */
|
|
10
|
+
export const DatabaseLayer = Layer.effect(
|
|
11
|
+
Database,
|
|
12
|
+
Effect.map(D1Drizzle.makeWithDefaults({}), (db) => ({ db })),
|
|
13
|
+
).pipe(Layer.provide(AppD1.sqlLayer()))
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process"
|
|
2
|
+
import { copyFileSync, existsSync, mkdirSync, readdirSync } from "node:fs"
|
|
3
|
+
|
|
4
|
+
// `pnpm db:migrate`: wrangler applies a flat directory of NNNN_name.sql files, but drizzle-kit
|
|
5
|
+
// writes one folder per migration. Flatten drizzle/<id>/migration.sql into migrations/, then
|
|
6
|
+
// apply to the local D1 database. Extra arguments go to wrangler (e.g. `--remote`).
|
|
7
|
+
const root = new URL("..", import.meta.url).pathname
|
|
8
|
+
const source = `${root}drizzle`
|
|
9
|
+
const target = `${root}migrations`
|
|
10
|
+
|
|
11
|
+
mkdirSync(target, { recursive: true })
|
|
12
|
+
readdirSync(source)
|
|
13
|
+
.filter((dir) => existsSync(`${source}/${dir}/migration.sql`))
|
|
14
|
+
.toSorted()
|
|
15
|
+
.forEach((dir, index) => {
|
|
16
|
+
const name = dir.replace(/^\d+_/, "")
|
|
17
|
+
copyFileSync(
|
|
18
|
+
`${source}/${dir}/migration.sql`,
|
|
19
|
+
`${target}/${String(index + 1).padStart(4, "0")}_${name}.sql`,
|
|
20
|
+
)
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
const result = spawnSync(
|
|
24
|
+
"wrangler",
|
|
25
|
+
[
|
|
26
|
+
"d1",
|
|
27
|
+
"migrations",
|
|
28
|
+
"apply",
|
|
29
|
+
"DB",
|
|
30
|
+
"--local",
|
|
31
|
+
"--config",
|
|
32
|
+
`${root}../../wrangler.jsonc`,
|
|
33
|
+
...process.argv.slice(2),
|
|
34
|
+
],
|
|
35
|
+
{ stdio: "inherit" },
|
|
36
|
+
)
|
|
37
|
+
process.exit(result.status ?? 1)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core"
|
|
2
|
+
|
|
3
|
+
/** Example table. `orgId` is null until you scope notes to an organization. */
|
|
4
|
+
export const note = sqliteTable("note", {
|
|
5
|
+
id: text()
|
|
6
|
+
.primaryKey()
|
|
7
|
+
.$defaultFn(() => crypto.randomUUID()),
|
|
8
|
+
orgId: text("org_id"),
|
|
9
|
+
title: text().notNull(),
|
|
10
|
+
createdAt: integer("created_at", { mode: "timestamp_ms" })
|
|
11
|
+
.notNull()
|
|
12
|
+
.$defaultFn(() => new Date()),
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
export type Note = typeof note.$inferSelect
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { EffectPgDatabase } from "drizzle-orm/effect-postgres"
|
|
2
|
+
import { Context } from "effect"
|
|
3
|
+
|
|
4
|
+
/** The app's database, as a Drizzle client whose queries are Effects. */
|
|
5
|
+
export class Database extends Context.Service<Database, { readonly db: EffectPgDatabase }>()(
|
|
6
|
+
"@repo/core/Database",
|
|
7
|
+
) {}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
CREATE TABLE "note" (
|
|
2
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
3
|
+
"org_id" text,
|
|
4
|
+
"title" text NOT NULL,
|
|
5
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
6
|
+
);
|
|
7
|
+
--> statement-breakpoint
|
|
8
|
+
INSERT INTO "note" ("title") VALUES
|
|
9
|
+
('Welcome to your new app'),
|
|
10
|
+
('Notes are read through the Database service');
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "8",
|
|
3
|
+
"dialect": "postgres",
|
|
4
|
+
"id": "667d2c3b-3819-4efd-98e5-4035d041970c",
|
|
5
|
+
"prevIds": ["00000000-0000-0000-0000-000000000000"],
|
|
6
|
+
"ddl": [
|
|
7
|
+
{
|
|
8
|
+
"isRlsEnabled": false,
|
|
9
|
+
"name": "note",
|
|
10
|
+
"entityType": "tables",
|
|
11
|
+
"schema": "public"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"type": "uuid",
|
|
15
|
+
"typeSchema": null,
|
|
16
|
+
"notNull": true,
|
|
17
|
+
"dimensions": 0,
|
|
18
|
+
"default": "gen_random_uuid()",
|
|
19
|
+
"generated": null,
|
|
20
|
+
"identity": null,
|
|
21
|
+
"name": "id",
|
|
22
|
+
"entityType": "columns",
|
|
23
|
+
"schema": "public",
|
|
24
|
+
"table": "note"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"type": "text",
|
|
28
|
+
"typeSchema": null,
|
|
29
|
+
"notNull": false,
|
|
30
|
+
"dimensions": 0,
|
|
31
|
+
"default": null,
|
|
32
|
+
"generated": null,
|
|
33
|
+
"identity": null,
|
|
34
|
+
"name": "org_id",
|
|
35
|
+
"entityType": "columns",
|
|
36
|
+
"schema": "public",
|
|
37
|
+
"table": "note"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"type": "text",
|
|
41
|
+
"typeSchema": null,
|
|
42
|
+
"notNull": true,
|
|
43
|
+
"dimensions": 0,
|
|
44
|
+
"default": null,
|
|
45
|
+
"generated": null,
|
|
46
|
+
"identity": null,
|
|
47
|
+
"name": "title",
|
|
48
|
+
"entityType": "columns",
|
|
49
|
+
"schema": "public",
|
|
50
|
+
"table": "note"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"type": "timestamp with time zone",
|
|
54
|
+
"typeSchema": null,
|
|
55
|
+
"notNull": true,
|
|
56
|
+
"dimensions": 0,
|
|
57
|
+
"default": "now()",
|
|
58
|
+
"generated": null,
|
|
59
|
+
"identity": null,
|
|
60
|
+
"name": "created_at",
|
|
61
|
+
"entityType": "columns",
|
|
62
|
+
"schema": "public",
|
|
63
|
+
"table": "note"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"columns": ["id"],
|
|
67
|
+
"nameExplicit": false,
|
|
68
|
+
"name": "note_pkey",
|
|
69
|
+
"schema": "public",
|
|
70
|
+
"table": "note",
|
|
71
|
+
"entityType": "pks"
|
|
72
|
+
}
|
|
73
|
+
],
|
|
74
|
+
"renames": []
|
|
75
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { defineConfig } from "drizzle-kit"
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
dialect: "postgresql",
|
|
5
|
+
schema: "./src/*schema.ts",
|
|
6
|
+
out: "./drizzle",
|
|
7
|
+
dbCredentials: {
|
|
8
|
+
url: process.env.DATABASE_URL ?? "postgres://postgres:postgres@localhost:5432/app",
|
|
9
|
+
},
|
|
10
|
+
})
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Database } from "@repo/core/Database"
|
|
2
|
+
import * as PgDrizzle from "drizzle-orm/effect-postgres"
|
|
3
|
+
import { Effect, Layer } from "effect"
|
|
4
|
+
import { Hyperdrive } from "effect-cf"
|
|
5
|
+
import { layer as hyperdrivePg } from "effect-cf/hyperdrive-pg"
|
|
6
|
+
|
|
7
|
+
/** The `HYPERDRIVE` binding from wrangler.jsonc; its connection string feeds the pg client. */
|
|
8
|
+
class AppHyperdrive extends Hyperdrive.Tag<AppHyperdrive>()("AppHyperdrive") {}
|
|
9
|
+
|
|
10
|
+
const PgLive = hyperdrivePg(AppHyperdrive, { binding: "HYPERDRIVE" })
|
|
11
|
+
|
|
12
|
+
/** Provides `Database`. Needs effect-cf's `WorkerEnvironment` (see apps/web/src/server/cloudflare.ts). */
|
|
13
|
+
export const DatabaseLayer = Layer.effect(
|
|
14
|
+
Database,
|
|
15
|
+
Effect.map(PgDrizzle.makeWithDefaults(), (db) => ({ db })),
|
|
16
|
+
).pipe(Layer.provide(PgLive))
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { PgClient } from "@effect/sql-pg"
|
|
2
|
+
import * as PgDrizzle from "drizzle-orm/effect-postgres"
|
|
3
|
+
import { migrate } from "drizzle-orm/effect-postgres/migrator"
|
|
4
|
+
import { Config, Effect, Redacted } from "effect"
|
|
5
|
+
|
|
6
|
+
// `pnpm db:migrate`: applies packages/db/drizzle/* to DATABASE_URL (default: the docker-compose database).
|
|
7
|
+
const url = Config.Redacted("DATABASE_URL").pipe(
|
|
8
|
+
Config.withDefault(Redacted.make("postgres://postgres:postgres@localhost:5432/app")),
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
const program = Effect.gen(function* () {
|
|
12
|
+
const db = yield* PgDrizzle.makeWithDefaults()
|
|
13
|
+
// drizzle types the migrator's error as `unknown`; any failure here should abort the script
|
|
14
|
+
// oxlint-disable-next-line effecttsgo/any-unknown-in-error-context
|
|
15
|
+
yield* migrate(db, { migrationsFolder: new URL("../drizzle", import.meta.url).pathname }).pipe(
|
|
16
|
+
Effect.orDie,
|
|
17
|
+
)
|
|
18
|
+
yield* Effect.log("migrations applied")
|
|
19
|
+
}).pipe(Effect.provide(PgClient.layerConfig({ url })))
|
|
20
|
+
|
|
21
|
+
Effect.runPromise(program).catch((error) => {
|
|
22
|
+
console.error(error)
|
|
23
|
+
process.exit(1)
|
|
24
|
+
})
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core"
|
|
2
|
+
|
|
3
|
+
/** Example table. `orgId` is null until you scope notes to an organization. */
|
|
4
|
+
export const note = pgTable("note", {
|
|
5
|
+
id: uuid().primaryKey().defaultRandom(),
|
|
6
|
+
orgId: text("org_id"),
|
|
7
|
+
title: text().notNull(),
|
|
8
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
export type Note = typeof note.$inferSelect
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Database } from "@repo/core/Database"
|
|
2
|
+
import { note } from "@repo/db"
|
|
3
|
+
import { createServerFn } from "@tanstack/react-start"
|
|
4
|
+
import { desc } from "drizzle-orm"
|
|
5
|
+
import { Effect } from "effect"
|
|
6
|
+
import { runtime } from "./runtime"
|
|
7
|
+
|
|
8
|
+
export const listNotes = createServerFn({ method: "GET" }).handler(() =>
|
|
9
|
+
runtime.runPromise(
|
|
10
|
+
Effect.gen(function* () {
|
|
11
|
+
const { db } = yield* Database
|
|
12
|
+
return yield* db.select().from(note).orderBy(desc(note.createdAt))
|
|
13
|
+
}),
|
|
14
|
+
),
|
|
15
|
+
)
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createFileRoute } from "@tanstack/react-router"
|
|
2
|
+
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
|
3
|
+
import { getGreeting } from "@/server/greeting"
|
|
4
|
+
import { listNotes } from "@/server/notes"
|
|
5
|
+
|
|
6
|
+
export const Route = createFileRoute("/app/")({
|
|
7
|
+
loader: async () => ({ greeting: await getGreeting(), notes: await listNotes() }),
|
|
8
|
+
component: Dashboard,
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
function Dashboard() {
|
|
12
|
+
const { greeting, notes } = Route.useLoaderData()
|
|
13
|
+
return (
|
|
14
|
+
<div className="space-y-6">
|
|
15
|
+
<h1 className="text-2xl font-semibold">Dashboard</h1>
|
|
16
|
+
<Card>
|
|
17
|
+
<CardHeader>
|
|
18
|
+
<CardTitle>{greeting}</CardTitle>
|
|
19
|
+
<CardDescription>
|
|
20
|
+
This text came from a server function running an Effect on the app runtime.
|
|
21
|
+
</CardDescription>
|
|
22
|
+
</CardHeader>
|
|
23
|
+
</Card>
|
|
24
|
+
<Card>
|
|
25
|
+
<CardHeader>
|
|
26
|
+
<CardTitle>Notes</CardTitle>
|
|
27
|
+
<CardDescription>
|
|
28
|
+
Rows from the <code>note</code> table, read through the <code>Database</code> service.
|
|
29
|
+
</CardDescription>
|
|
30
|
+
</CardHeader>
|
|
31
|
+
<CardContent>
|
|
32
|
+
{notes.length === 0 ? (
|
|
33
|
+
<p className="text-sm text-muted-foreground">No notes yet.</p>
|
|
34
|
+
) : (
|
|
35
|
+
<ul className="space-y-2">
|
|
36
|
+
{notes.map((note) => (
|
|
37
|
+
<li key={note.id} className="flex items-baseline justify-between gap-4 text-sm">
|
|
38
|
+
<span>{note.title}</span>
|
|
39
|
+
<time className="text-muted-foreground">
|
|
40
|
+
{new Date(note.createdAt).toLocaleDateString()}
|
|
41
|
+
</time>
|
|
42
|
+
</li>
|
|
43
|
+
))}
|
|
44
|
+
</ul>
|
|
45
|
+
)}
|
|
46
|
+
</CardContent>
|
|
47
|
+
</Card>
|
|
48
|
+
</div>
|
|
49
|
+
)
|
|
50
|
+
}
|