create-fate 0.0.0 → 1.0.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 +24 -0
- package/bin/create-fate.mjs +412 -0
- package/package.json +26 -3
- package/templates/fate/README.md +8 -0
- package/templates/fate/drizzle/.github/workflows/push.yml +27 -0
- package/templates/fate/drizzle/.oxfmtrc.jsonc +23 -0
- package/templates/fate/drizzle/.vite-hooks/pre-commit +1 -0
- package/templates/fate/drizzle/.vscode/extensions.json +12 -0
- package/templates/fate/drizzle/.vscode/settings.json +25 -0
- package/templates/fate/drizzle/AGENTS.md +55 -0
- package/templates/fate/drizzle/README.md +112 -0
- package/templates/fate/drizzle/_gitignore +20 -0
- package/templates/fate/drizzle/client/package.json +58 -0
- package/templates/fate/drizzle/client/pages/index.tsx +96 -0
- package/templates/fate/drizzle/client/pages/layout.tsx +104 -0
- package/templates/fate/drizzle/client/pages/login.tsx +107 -0
- package/templates/fate/drizzle/client/pages/post/[id].tsx +22 -0
- package/templates/fate/drizzle/client/pages/search.tsx +95 -0
- package/templates/fate/drizzle/client/public/icon.svg +1 -0
- package/templates/fate/drizzle/client/src/App.css +153 -0
- package/templates/fate/drizzle/client/src/lib/AvailableLanguages.tsx +5 -0
- package/templates/fate/drizzle/client/src/lib/cx.tsx +6 -0
- package/templates/fate/drizzle/client/src/lib/env.tsx +5 -0
- package/templates/fate/drizzle/client/src/ui/Badge.tsx +31 -0
- package/templates/fate/drizzle/client/src/ui/Button.tsx +108 -0
- package/templates/fate/drizzle/client/src/ui/Card.tsx +32 -0
- package/templates/fate/drizzle/client/src/ui/CommentCard.tsx +75 -0
- package/templates/fate/drizzle/client/src/ui/Error.tsx +19 -0
- package/templates/fate/drizzle/client/src/ui/H2.tsx +15 -0
- package/templates/fate/drizzle/client/src/ui/H3.tsx +20 -0
- package/templates/fate/drizzle/client/src/ui/Header.tsx +96 -0
- package/templates/fate/drizzle/client/src/ui/Input.tsx +17 -0
- package/templates/fate/drizzle/client/src/ui/Link.tsx +11 -0
- package/templates/fate/drizzle/client/src/ui/LocaleSwitcher.tsx +52 -0
- package/templates/fate/drizzle/client/src/ui/PostCard.tsx +284 -0
- package/templates/fate/drizzle/client/src/ui/Section.tsx +23 -0
- package/templates/fate/drizzle/client/src/ui/UserCard.tsx +131 -0
- package/templates/fate/drizzle/client/src/user/AuthClient.tsx +6 -0
- package/templates/fate/drizzle/client/translations/de_DE.json +689 -0
- package/templates/fate/drizzle/client/translations/ja_JP.json +689 -0
- package/templates/fate/drizzle/client/vite.config.ts +39 -0
- package/templates/fate/drizzle/client/void.json +29 -0
- package/templates/fate/drizzle/docker-compose.yml +11 -0
- package/templates/fate/drizzle/package.json +46 -0
- package/templates/fate/drizzle/pnpm-workspace.yaml +36 -0
- package/templates/fate/drizzle/public/fate-logo-dark.svg +4 -0
- package/templates/fate/drizzle/public/fate-logo.svg +4 -0
- package/templates/fate/drizzle/server/.env.example +5 -0
- package/templates/fate/drizzle/server/drizzle.config.ts +11 -0
- package/templates/fate/drizzle/server/package.json +48 -0
- package/templates/fate/drizzle/server/src/__tests__/index.test.tsx +5 -0
- package/templates/fate/drizzle/server/src/app.tsx +44 -0
- package/templates/fate/drizzle/server/src/drizzle/db.ts +25 -0
- package/templates/fate/drizzle/server/src/drizzle/queries.ts +89 -0
- package/templates/fate/drizzle/server/src/drizzle/schema.ts +174 -0
- package/templates/fate/drizzle/server/src/drizzle/seed.tsx +77 -0
- package/templates/fate/drizzle/server/src/drizzle/seedData.ts +205 -0
- package/templates/fate/drizzle/server/src/index.tsx +24 -0
- package/templates/fate/drizzle/server/src/lib/auth.ts +33 -0
- package/templates/fate/drizzle/server/src/lib/env.ts +3 -0
- package/templates/fate/drizzle/server/src/lib/origins.ts +18 -0
- package/templates/fate/drizzle/server/src/router.ts +15 -0
- package/templates/fate/drizzle/server/src/trpc/connection.ts +4 -0
- package/templates/fate/drizzle/server/src/trpc/context.ts +22 -0
- package/templates/fate/drizzle/server/src/trpc/init.ts +51 -0
- package/templates/fate/drizzle/server/src/trpc/routers/comment.ts +146 -0
- package/templates/fate/drizzle/server/src/trpc/routers/post.ts +99 -0
- package/templates/fate/drizzle/server/src/trpc/routers/user.ts +68 -0
- package/templates/fate/drizzle/server/src/trpc/views.ts +75 -0
- package/templates/fate/drizzle/server/src/user/SessionUser.tsx +17 -0
- package/templates/fate/drizzle/server/vite.config.ts +8 -0
- package/templates/fate/drizzle/tsconfig.json +33 -0
- package/templates/fate/drizzle/vite.config.ts +71 -0
- package/templates/fate/http/.github/workflows/push.yml +27 -0
- package/templates/fate/http/.oxfmtrc.jsonc +23 -0
- package/templates/fate/http/.vite-hooks/pre-commit +1 -0
- package/templates/fate/http/.vscode/extensions.json +12 -0
- package/templates/fate/http/.vscode/settings.json +25 -0
- package/templates/fate/http/AGENTS.md +55 -0
- package/templates/fate/http/README.md +112 -0
- package/templates/fate/http/_gitignore +20 -0
- package/templates/fate/http/client/package.json +56 -0
- package/templates/fate/http/client/pages/index.tsx +96 -0
- package/templates/fate/http/client/pages/layout.tsx +89 -0
- package/templates/fate/http/client/pages/login.tsx +107 -0
- package/templates/fate/http/client/pages/post/[id].tsx +22 -0
- package/templates/fate/http/client/pages/search.tsx +95 -0
- package/templates/fate/http/client/public/icon.svg +1 -0
- package/templates/fate/http/client/src/App.css +153 -0
- package/templates/fate/http/client/src/lib/AvailableLanguages.tsx +5 -0
- package/templates/fate/http/client/src/lib/cx.tsx +6 -0
- package/templates/fate/http/client/src/lib/env.tsx +5 -0
- package/templates/fate/http/client/src/ui/Badge.tsx +31 -0
- package/templates/fate/http/client/src/ui/Button.tsx +108 -0
- package/templates/fate/http/client/src/ui/Card.tsx +32 -0
- package/templates/fate/http/client/src/ui/CommentCard.tsx +75 -0
- package/templates/fate/http/client/src/ui/Error.tsx +19 -0
- package/templates/fate/http/client/src/ui/H2.tsx +15 -0
- package/templates/fate/http/client/src/ui/H3.tsx +20 -0
- package/templates/fate/http/client/src/ui/Header.tsx +96 -0
- package/templates/fate/http/client/src/ui/Input.tsx +17 -0
- package/templates/fate/http/client/src/ui/Link.tsx +11 -0
- package/templates/fate/http/client/src/ui/LocaleSwitcher.tsx +52 -0
- package/templates/fate/http/client/src/ui/PostCard.tsx +281 -0
- package/templates/fate/http/client/src/ui/Section.tsx +23 -0
- package/templates/fate/http/client/src/ui/UserCard.tsx +131 -0
- package/templates/fate/http/client/src/user/AuthClient.tsx +6 -0
- package/templates/fate/http/client/translations/de_DE.json +689 -0
- package/templates/fate/http/client/translations/ja_JP.json +689 -0
- package/templates/fate/http/client/vite.config.ts +40 -0
- package/templates/fate/http/client/void.json +29 -0
- package/templates/fate/http/docker-compose.yml +11 -0
- package/templates/fate/http/package.json +46 -0
- package/templates/fate/http/pnpm-workspace.yaml +36 -0
- package/templates/fate/http/public/fate-logo-dark.svg +4 -0
- package/templates/fate/http/public/fate-logo.svg +4 -0
- package/templates/fate/http/server/.env.example +5 -0
- package/templates/fate/http/server/drizzle.config.ts +11 -0
- package/templates/fate/http/server/package.json +46 -0
- package/templates/fate/http/server/src/__tests__/index.test.tsx +5 -0
- package/templates/fate/http/server/src/app.tsx +36 -0
- package/templates/fate/http/server/src/drizzle/db.ts +25 -0
- package/templates/fate/http/server/src/drizzle/queries.ts +89 -0
- package/templates/fate/http/server/src/drizzle/schema.ts +174 -0
- package/templates/fate/http/server/src/drizzle/seed.tsx +77 -0
- package/templates/fate/http/server/src/drizzle/seedData.ts +205 -0
- package/templates/fate/http/server/src/fate/context.ts +20 -0
- package/templates/fate/http/server/src/fate/server.ts +285 -0
- package/templates/fate/http/server/src/fate/views.ts +75 -0
- package/templates/fate/http/server/src/index.tsx +24 -0
- package/templates/fate/http/server/src/lib/auth.ts +33 -0
- package/templates/fate/http/server/src/lib/env.ts +3 -0
- package/templates/fate/http/server/src/lib/origins.ts +18 -0
- package/templates/fate/http/server/src/router.ts +2 -0
- package/templates/fate/http/server/src/user/SessionUser.tsx +17 -0
- package/templates/fate/http/server/vite.config.ts +8 -0
- package/templates/fate/http/tsconfig.json +33 -0
- package/templates/fate/http/vite.config.ts +71 -0
- package/templates/fate/prisma/.github/workflows/push.yml +27 -0
- package/templates/fate/prisma/.oxfmtrc.jsonc +23 -0
- package/templates/fate/prisma/.vite-hooks/pre-commit +1 -0
- package/templates/fate/prisma/.vscode/extensions.json +12 -0
- package/templates/fate/prisma/.vscode/settings.json +25 -0
- package/templates/fate/prisma/AGENTS.md +55 -0
- package/templates/fate/prisma/README.md +126 -0
- package/templates/fate/prisma/_gitignore +20 -0
- package/templates/fate/prisma/client/package.json +58 -0
- package/templates/fate/prisma/client/pages/index.tsx +96 -0
- package/templates/fate/prisma/client/pages/layout.tsx +94 -0
- package/templates/fate/prisma/client/pages/login.tsx +107 -0
- package/templates/fate/prisma/client/pages/post/[id].tsx +22 -0
- package/templates/fate/prisma/client/pages/search.tsx +95 -0
- package/templates/fate/prisma/client/public/icon.svg +1 -0
- package/templates/fate/prisma/client/src/App.css +153 -0
- package/templates/fate/prisma/client/src/lib/AvailableLanguages.tsx +5 -0
- package/templates/fate/prisma/client/src/lib/cx.tsx +6 -0
- package/templates/fate/prisma/client/src/lib/env.tsx +5 -0
- package/templates/fate/prisma/client/src/ui/Badge.tsx +31 -0
- package/templates/fate/prisma/client/src/ui/Button.tsx +108 -0
- package/templates/fate/prisma/client/src/ui/Card.tsx +32 -0
- package/templates/fate/prisma/client/src/ui/CommentCard.tsx +75 -0
- package/templates/fate/prisma/client/src/ui/Error.tsx +19 -0
- package/templates/fate/prisma/client/src/ui/H2.tsx +15 -0
- package/templates/fate/prisma/client/src/ui/H3.tsx +20 -0
- package/templates/fate/prisma/client/src/ui/Header.tsx +96 -0
- package/templates/fate/prisma/client/src/ui/Input.tsx +17 -0
- package/templates/fate/prisma/client/src/ui/Link.tsx +11 -0
- package/templates/fate/prisma/client/src/ui/LocaleSwitcher.tsx +52 -0
- package/templates/fate/prisma/client/src/ui/PostCard.tsx +281 -0
- package/templates/fate/prisma/client/src/ui/Section.tsx +23 -0
- package/templates/fate/prisma/client/src/ui/UserCard.tsx +131 -0
- package/templates/fate/prisma/client/src/user/AuthClient.tsx +6 -0
- package/templates/fate/prisma/client/translations/de_DE.json +689 -0
- package/templates/fate/prisma/client/translations/ja_JP.json +689 -0
- package/templates/fate/prisma/client/vite.config.ts +39 -0
- package/templates/fate/prisma/client/void.json +29 -0
- package/templates/fate/prisma/docker-compose.yml +11 -0
- package/templates/fate/prisma/package.json +47 -0
- package/templates/fate/prisma/pnpm-workspace.yaml +39 -0
- package/templates/fate/prisma/public/fate-logo-dark.svg +4 -0
- package/templates/fate/prisma/public/fate-logo.svg +4 -0
- package/templates/fate/prisma/server/.env.example +5 -0
- package/templates/fate/prisma/server/package.json +42 -0
- package/templates/fate/prisma/server/prisma.config.ts +21 -0
- package/templates/fate/prisma/server/src/__tests__/index.test.tsx +5 -0
- package/templates/fate/prisma/server/src/app.tsx +40 -0
- package/templates/fate/prisma/server/src/index.tsx +24 -0
- package/templates/fate/prisma/server/src/lib/auth.ts +31 -0
- package/templates/fate/prisma/server/src/lib/env.ts +3 -0
- package/templates/fate/prisma/server/src/lib/origins.ts +18 -0
- package/templates/fate/prisma/server/src/prisma/prisma.ts +9 -0
- package/templates/fate/prisma/server/src/prisma/schema.prisma +98 -0
- package/templates/fate/prisma/server/src/prisma/seed.tsx +71 -0
- package/templates/fate/prisma/server/src/prisma/seedData.ts +205 -0
- package/templates/fate/prisma/server/src/router.ts +14 -0
- package/templates/fate/prisma/server/src/trpc/connection.ts +4 -0
- package/templates/fate/prisma/server/src/trpc/context.ts +22 -0
- package/templates/fate/prisma/server/src/trpc/init.ts +8 -0
- package/templates/fate/prisma/server/src/trpc/routers/comment.ts +176 -0
- package/templates/fate/prisma/server/src/trpc/routers/post.ts +154 -0
- package/templates/fate/prisma/server/src/trpc/routers/user.ts +71 -0
- package/templates/fate/prisma/server/src/trpc/views.ts +77 -0
- package/templates/fate/prisma/server/src/user/SessionUser.tsx +17 -0
- package/templates/fate/prisma/server/vite.config.ts +8 -0
- package/templates/fate/prisma/tsconfig.json +33 -0
- package/templates/fate/prisma/vite.config.ts +72 -0
- package/templates/fate/void/.oxfmtrc.jsonc +14 -0
- package/templates/fate/void/README.md +55 -0
- package/templates/fate/void/auth.ts +22 -0
- package/templates/fate/void/db/migrations/20260508073357_initial_schema.sql +133 -0
- package/templates/fate/void/db/migrations/20260508120500_seed_void_demo.sql +170 -0
- package/templates/fate/void/db/migrations/meta/20260508073357_snapshot.json +868 -0
- package/templates/fate/void/db/migrations/meta/_journal.json +20 -0
- package/templates/fate/void/db/queries.ts +211 -0
- package/templates/fate/void/db/schema.ts +325 -0
- package/templates/fate/void/db/seed-auth.ts +31 -0
- package/templates/fate/void/db/seed.ts +163 -0
- package/templates/fate/void/middleware/01.shared.ts +29 -0
- package/templates/fate/void/package.json +65 -0
- package/templates/fate/void/pages/category/[id].tsx +23 -0
- package/templates/fate/void/pages/index.tsx +153 -0
- package/templates/fate/void/pages/layout.tsx +46 -0
- package/templates/fate/void/pages/login.tsx +103 -0
- package/templates/fate/void/pages/post/[id].tsx +20 -0
- package/templates/fate/void/pages/search.tsx +81 -0
- package/templates/fate/void/pnpm-workspace.yaml +31 -0
- package/templates/fate/void/public/.assetsignore +1 -0
- package/templates/fate/void/public/icon.svg +1 -0
- package/templates/fate/void/routes/fate-live.ts +8 -0
- package/templates/fate/void/routes/fate.ts +8 -0
- package/templates/fate/void/seedData.ts +535 -0
- package/templates/fate/void/src/App.css +130 -0
- package/templates/fate/void/src/fate/__tests__/commentPermissions.test.ts +31 -0
- package/templates/fate/void/src/fate/commentPermissions.ts +17 -0
- package/templates/fate/void/src/fate/context.ts +15 -0
- package/templates/fate/void/src/fate/live.ts +6 -0
- package/templates/fate/void/src/fate/server.ts +401 -0
- package/templates/fate/void/src/fate/views.ts +164 -0
- package/templates/fate/void/src/lib/cx.tsx +6 -0
- package/templates/fate/void/src/lib/formatLabel.tsx +6 -0
- package/templates/fate/void/src/lib/shared.ts +10 -0
- package/templates/fate/void/src/ui/Badge.tsx +31 -0
- package/templates/fate/void/src/ui/Button.tsx +92 -0
- package/templates/fate/void/src/ui/Card.tsx +29 -0
- package/templates/fate/void/src/ui/CategoryCard.tsx +105 -0
- package/templates/fate/void/src/ui/CommentCard.tsx +80 -0
- package/templates/fate/void/src/ui/CreatePost.tsx +111 -0
- package/templates/fate/void/src/ui/Error.tsx +19 -0
- package/templates/fate/void/src/ui/EventCard.tsx +152 -0
- package/templates/fate/void/src/ui/H2.tsx +15 -0
- package/templates/fate/void/src/ui/H3.tsx +20 -0
- package/templates/fate/void/src/ui/Header.tsx +96 -0
- package/templates/fate/void/src/ui/Input.tsx +33 -0
- package/templates/fate/void/src/ui/Link.tsx +11 -0
- package/templates/fate/void/src/ui/Number.tsx +5 -0
- package/templates/fate/void/src/ui/PostCard.tsx +294 -0
- package/templates/fate/void/src/ui/Section.tsx +23 -0
- package/templates/fate/void/src/ui/TagBadge.tsx +23 -0
- package/templates/fate/void/src/ui/UserCard.tsx +129 -0
- package/templates/fate/void/src/user/AuthClient.tsx +1 -0
- package/templates/fate/void/src/user/SessionUser.tsx +17 -0
- package/templates/fate/void/tsconfig.json +34 -0
- package/templates/fate/void/vite.config.ts +83 -0
- package/templates/fate/void/void.json +32 -0
- package/templates/fate/void/wrangler.jsonc +16 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { connectionArgs } from '@nkzw/fate/server';
|
|
2
|
+
import { TRPCError } from '@trpc/server';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { likePostRecord, unlikePostRecord } from '../../drizzle/queries.ts';
|
|
5
|
+
import { fate, live, procedure, router } from '../init.ts';
|
|
6
|
+
import { Post, postDataView } from '../views.ts';
|
|
7
|
+
|
|
8
|
+
export const postRouter = router({
|
|
9
|
+
...fate.procedures({
|
|
10
|
+
view: postDataView,
|
|
11
|
+
}),
|
|
12
|
+
like: procedure
|
|
13
|
+
.input(
|
|
14
|
+
z.object({
|
|
15
|
+
args: connectionArgs,
|
|
16
|
+
error: z.enum(['boundary', 'callSite']).optional(),
|
|
17
|
+
id: z.string().min(1, 'Post id is required.'),
|
|
18
|
+
select: z.array(z.string()),
|
|
19
|
+
slow: z.boolean().optional(),
|
|
20
|
+
}),
|
|
21
|
+
)
|
|
22
|
+
.mutation(async ({ ctx, input }) => {
|
|
23
|
+
if (input.slow) {
|
|
24
|
+
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (input.error === 'boundary') {
|
|
28
|
+
throw new TRPCError({
|
|
29
|
+
code: 'INTERNAL_SERVER_ERROR',
|
|
30
|
+
message: 'Simulated error.',
|
|
31
|
+
});
|
|
32
|
+
} else if (input.error === 'callSite') {
|
|
33
|
+
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
34
|
+
throw new TRPCError({
|
|
35
|
+
code: 'PAYMENT_REQUIRED',
|
|
36
|
+
message: 'Gotta pay up.',
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const updated = await likePostRecord(input.id);
|
|
41
|
+
if (!updated) {
|
|
42
|
+
throw new TRPCError({
|
|
43
|
+
code: 'NOT_FOUND',
|
|
44
|
+
message: 'Post not found.',
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const post = await fate.resolveById({
|
|
49
|
+
ctx,
|
|
50
|
+
id: input.id,
|
|
51
|
+
input,
|
|
52
|
+
view: postDataView,
|
|
53
|
+
});
|
|
54
|
+
if (!post) {
|
|
55
|
+
throw new TRPCError({
|
|
56
|
+
code: 'NOT_FOUND',
|
|
57
|
+
message: 'Post not found.',
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
live.update('Post', input.id, { changed: ['likes'] });
|
|
62
|
+
|
|
63
|
+
return post as Post;
|
|
64
|
+
}),
|
|
65
|
+
unlike: procedure
|
|
66
|
+
.input(
|
|
67
|
+
z.object({
|
|
68
|
+
args: connectionArgs,
|
|
69
|
+
id: z.string().min(1, 'Post id is required.'),
|
|
70
|
+
select: z.array(z.string()),
|
|
71
|
+
}),
|
|
72
|
+
)
|
|
73
|
+
.mutation(async ({ ctx, input }) => {
|
|
74
|
+
const updated = await unlikePostRecord(input.id);
|
|
75
|
+
if (!updated) {
|
|
76
|
+
throw new TRPCError({
|
|
77
|
+
code: 'NOT_FOUND',
|
|
78
|
+
message: 'Post not found',
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const post = await fate.resolveById({
|
|
83
|
+
ctx,
|
|
84
|
+
id: input.id,
|
|
85
|
+
input,
|
|
86
|
+
view: postDataView,
|
|
87
|
+
});
|
|
88
|
+
if (!post) {
|
|
89
|
+
throw new TRPCError({
|
|
90
|
+
code: 'NOT_FOUND',
|
|
91
|
+
message: 'Post not found',
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
live.update('Post', input.id, { changed: ['likes'] });
|
|
96
|
+
|
|
97
|
+
return post as Post;
|
|
98
|
+
}),
|
|
99
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { connectionArgs } from '@nkzw/fate/server';
|
|
2
|
+
import { TRPCError } from '@trpc/server';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { auth } from '../../lib/auth.ts';
|
|
5
|
+
import { fate, procedure, router } from '../init.ts';
|
|
6
|
+
import { userDataView } from '../views.ts';
|
|
7
|
+
|
|
8
|
+
export const userRouter = router({
|
|
9
|
+
update: procedure
|
|
10
|
+
.input(
|
|
11
|
+
z.object({
|
|
12
|
+
args: connectionArgs,
|
|
13
|
+
name: z
|
|
14
|
+
.string()
|
|
15
|
+
.trim()
|
|
16
|
+
.min(2, 'Name must be at least 2 characters.')
|
|
17
|
+
.max(50, 'Name must be at most 32 characters.'),
|
|
18
|
+
select: z.array(z.string()),
|
|
19
|
+
}),
|
|
20
|
+
)
|
|
21
|
+
.mutation(async ({ ctx, input }) => {
|
|
22
|
+
if (!ctx.sessionUser) {
|
|
23
|
+
throw new TRPCError({
|
|
24
|
+
code: 'UNAUTHORIZED',
|
|
25
|
+
message: 'You must be logged in to update your name.',
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
await auth.api.updateUser({
|
|
30
|
+
body: { name: input.name },
|
|
31
|
+
headers: ctx.headers,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const result = await fate.resolveById({
|
|
35
|
+
ctx,
|
|
36
|
+
id: ctx.sessionUser.id,
|
|
37
|
+
input,
|
|
38
|
+
view: userDataView,
|
|
39
|
+
});
|
|
40
|
+
if (!result) {
|
|
41
|
+
throw new TRPCError({
|
|
42
|
+
code: 'NOT_FOUND',
|
|
43
|
+
message: 'User not found.',
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return result;
|
|
48
|
+
}),
|
|
49
|
+
viewer: procedure
|
|
50
|
+
.input(
|
|
51
|
+
z.object({
|
|
52
|
+
select: z.array(z.string()),
|
|
53
|
+
}),
|
|
54
|
+
)
|
|
55
|
+
.query(async ({ ctx, input }) => {
|
|
56
|
+
if (!ctx.sessionUser) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const result = await fate.resolveById({
|
|
61
|
+
ctx,
|
|
62
|
+
id: ctx.sessionUser.id,
|
|
63
|
+
input,
|
|
64
|
+
view: userDataView,
|
|
65
|
+
});
|
|
66
|
+
return result;
|
|
67
|
+
}),
|
|
68
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { computed, count, dataView, list, type Entity } from '@nkzw/fate/server';
|
|
2
|
+
import type { CommentRow, PostRow, UserRow } from '../drizzle/schema.ts';
|
|
3
|
+
|
|
4
|
+
export type CommentItem = CommentRow & {
|
|
5
|
+
author?: UserRow | null;
|
|
6
|
+
post?: PostRow | null;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type PostItem = PostRow & {
|
|
10
|
+
author?: UserRow | null;
|
|
11
|
+
comments?: Array<CommentItem>;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const userDataView = dataView<UserRow>('User')({
|
|
15
|
+
id: true,
|
|
16
|
+
name: true,
|
|
17
|
+
username: true,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const basePost = {
|
|
21
|
+
author: userDataView,
|
|
22
|
+
commentCount: computed<PostItem, number>({
|
|
23
|
+
resolve: (_item, deps) => (deps.count as number) ?? 0,
|
|
24
|
+
select: {
|
|
25
|
+
count: count('comments'),
|
|
26
|
+
},
|
|
27
|
+
}),
|
|
28
|
+
content: true,
|
|
29
|
+
id: true,
|
|
30
|
+
likes: true,
|
|
31
|
+
title: true,
|
|
32
|
+
} as const;
|
|
33
|
+
|
|
34
|
+
export const postSummaryDataView = dataView<PostItem>('Post')({
|
|
35
|
+
...basePost,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export const commentDataView = dataView<CommentItem>('Comment')({
|
|
39
|
+
author: userDataView,
|
|
40
|
+
content: true,
|
|
41
|
+
id: true,
|
|
42
|
+
post: postSummaryDataView,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
export const postDataView = dataView<PostItem>('Post')({
|
|
46
|
+
...basePost,
|
|
47
|
+
comments: list(commentDataView, { orderBy: { createdAt: 'asc', id: 'asc' } }),
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
export type User = Entity<typeof userDataView, 'User'>;
|
|
51
|
+
export type Comment = Entity<
|
|
52
|
+
typeof commentDataView,
|
|
53
|
+
'Comment',
|
|
54
|
+
{
|
|
55
|
+
author: User;
|
|
56
|
+
post: Post;
|
|
57
|
+
}
|
|
58
|
+
>;
|
|
59
|
+
export type Post = Entity<
|
|
60
|
+
typeof postDataView,
|
|
61
|
+
'Post',
|
|
62
|
+
{
|
|
63
|
+
author: User;
|
|
64
|
+
comments: Array<Comment>;
|
|
65
|
+
}
|
|
66
|
+
>;
|
|
67
|
+
|
|
68
|
+
export const Root = {
|
|
69
|
+
commentSearch: {
|
|
70
|
+
procedure: 'search',
|
|
71
|
+
view: list(commentDataView, { orderBy: { createdAt: 'desc', id: 'desc' } }),
|
|
72
|
+
},
|
|
73
|
+
posts: list(postDataView, { orderBy: { createdAt: 'desc', id: 'desc' } }),
|
|
74
|
+
viewer: userDataView,
|
|
75
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { UserRow } from '../drizzle/schema.ts';
|
|
2
|
+
|
|
3
|
+
export type SessionUser = Pick<UserRow, 'role' | 'id' | 'username'>;
|
|
4
|
+
|
|
5
|
+
export function toSessionUser({
|
|
6
|
+
email,
|
|
7
|
+
id,
|
|
8
|
+
role,
|
|
9
|
+
username,
|
|
10
|
+
}: Readonly<{
|
|
11
|
+
email: string | null | undefined;
|
|
12
|
+
id: string;
|
|
13
|
+
role?: string | null | undefined;
|
|
14
|
+
username?: string | null | undefined;
|
|
15
|
+
}>): SessionUser {
|
|
16
|
+
return { id, role: role || '', username: username || email || '' };
|
|
17
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"allowJs": true,
|
|
4
|
+
"allowImportingTsExtensions": true,
|
|
5
|
+
"esModuleInterop": true,
|
|
6
|
+
"forceConsistentCasingInFileNames": true,
|
|
7
|
+
"incremental": true,
|
|
8
|
+
"isolatedModules": true,
|
|
9
|
+
"jsx": "react-jsx",
|
|
10
|
+
"lib": ["dom", "dom.iterable", "esnext"],
|
|
11
|
+
"module": "nodenext",
|
|
12
|
+
"moduleResolution": "nodenext",
|
|
13
|
+
"noEmit": true,
|
|
14
|
+
"noImplicitOverride": true,
|
|
15
|
+
"noUnusedLocals": true,
|
|
16
|
+
"resolveJsonModule": true,
|
|
17
|
+
"skipLibCheck": true,
|
|
18
|
+
"strict": true,
|
|
19
|
+
"target": "es2017",
|
|
20
|
+
"types": ["vite/client"]
|
|
21
|
+
},
|
|
22
|
+
"exclude": ["**/.void/**/*.ts", "node_modules"],
|
|
23
|
+
"include": ["**/.fate/*.ts", "**/*.ts", "**/*.tsx"],
|
|
24
|
+
"ts-node": {
|
|
25
|
+
"transpileOnly": true,
|
|
26
|
+
"transpiler": "ts-node/transpilers/swc",
|
|
27
|
+
"files": true,
|
|
28
|
+
"compilerOptions": {
|
|
29
|
+
"module": "esnext",
|
|
30
|
+
"isolatedModules": false
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import nkzw from '@nkzw/oxlint-config';
|
|
3
|
+
import dotenv from 'dotenv';
|
|
4
|
+
import { defineConfig } from 'vite-plus';
|
|
5
|
+
|
|
6
|
+
const root = process.cwd();
|
|
7
|
+
|
|
8
|
+
dotenv.config({
|
|
9
|
+
path: join(root, './server', '.env'),
|
|
10
|
+
quiet: true,
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export default defineConfig({
|
|
14
|
+
fmt: {
|
|
15
|
+
experimentalSortImports: {
|
|
16
|
+
newlinesBetween: false,
|
|
17
|
+
},
|
|
18
|
+
experimentalSortPackageJson: {
|
|
19
|
+
sortScripts: true,
|
|
20
|
+
},
|
|
21
|
+
experimentalTailwindcss: {
|
|
22
|
+
stylesheet: 'client/src/App.css',
|
|
23
|
+
},
|
|
24
|
+
ignorePatterns: [
|
|
25
|
+
'coverage/',
|
|
26
|
+
'dist/',
|
|
27
|
+
'.fate/',
|
|
28
|
+
'client/dist/',
|
|
29
|
+
'client/src/translations/',
|
|
30
|
+
'server/dist/',
|
|
31
|
+
'pnpm-lock.yaml',
|
|
32
|
+
],
|
|
33
|
+
singleQuote: true,
|
|
34
|
+
},
|
|
35
|
+
lint: {
|
|
36
|
+
extends: [nkzw],
|
|
37
|
+
ignorePatterns: [
|
|
38
|
+
'coverage',
|
|
39
|
+
'dist',
|
|
40
|
+
'.fate',
|
|
41
|
+
'client/dist',
|
|
42
|
+
'server/dist',
|
|
43
|
+
'server/src/drizzle/migrations/**',
|
|
44
|
+
'vite.config.ts.timestamp-*',
|
|
45
|
+
'client/vite.config.ts.timestamp-*',
|
|
46
|
+
'server/vite.config.ts.timestamp-*',
|
|
47
|
+
],
|
|
48
|
+
options: { typeAware: true, typeCheck: true },
|
|
49
|
+
overrides: [
|
|
50
|
+
{
|
|
51
|
+
files: ['server/src/index.tsx', 'server/src/drizzle/seed.tsx', '**/__tests__/**'],
|
|
52
|
+
rules: {
|
|
53
|
+
'no-console': 'off',
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
rules: {
|
|
58
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
run: {
|
|
62
|
+
tasks: {
|
|
63
|
+
'test:all': {
|
|
64
|
+
command: 'vp check && vp test',
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
staged: {
|
|
69
|
+
'*': 'vp check --fix',
|
|
70
|
+
},
|
|
71
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
name: test
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
pull_request:
|
|
8
|
+
branches:
|
|
9
|
+
- main
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
test:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
strategy:
|
|
15
|
+
matrix:
|
|
16
|
+
node-version: [24]
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v4
|
|
19
|
+
- uses: voidzero-dev/setup-vp@v1
|
|
20
|
+
with:
|
|
21
|
+
node-version: ${{ matrix.node-version }}
|
|
22
|
+
cache: true
|
|
23
|
+
run-install: true
|
|
24
|
+
- run: |
|
|
25
|
+
vp run dev:setup
|
|
26
|
+
vp run test:all
|
|
27
|
+
vp run build
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "./node_modules/oxfmt/configuration_schema.json",
|
|
3
|
+
"singleQuote": true,
|
|
4
|
+
"experimentalSortImports": {
|
|
5
|
+
"newlinesBetween": false,
|
|
6
|
+
},
|
|
7
|
+
"experimentalSortPackageJson": {
|
|
8
|
+
"sortScripts": true,
|
|
9
|
+
},
|
|
10
|
+
"experimentalTailwindcss": {
|
|
11
|
+
"stylesheet": "client/src/App.css",
|
|
12
|
+
},
|
|
13
|
+
"ignorePatterns": [
|
|
14
|
+
"client/dist/",
|
|
15
|
+
"client/index.html",
|
|
16
|
+
"client/src/fate.ts",
|
|
17
|
+
"client/src/translations/",
|
|
18
|
+
"coverage/",
|
|
19
|
+
"dist/",
|
|
20
|
+
"pnpm-lock.yaml",
|
|
21
|
+
"server/dist",
|
|
22
|
+
],
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
vp staged
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"recommendations": [
|
|
3
|
+
"dbaeumer.vscode-eslint",
|
|
4
|
+
"oxc.oxc-vscode",
|
|
5
|
+
"styled-components.vscode-styled-components",
|
|
6
|
+
"sysoev.vscode-open-in-github",
|
|
7
|
+
"tailwindcss.intellisense",
|
|
8
|
+
"TypeScriptTeam.native-preview",
|
|
9
|
+
"usernamehw.errorlens",
|
|
10
|
+
"wix.vscode-import-cost"
|
|
11
|
+
]
|
|
12
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"editor.formatOnSave": true,
|
|
3
|
+
"files.insertFinalNewline": true,
|
|
4
|
+
"files.trimFinalNewlines": true,
|
|
5
|
+
"editor.codeActionsOnSave": {
|
|
6
|
+
"source.fixAll.eslint": "explicit"
|
|
7
|
+
},
|
|
8
|
+
"[javascript]": {
|
|
9
|
+
"editor.defaultFormatter": "oxc.oxc-vscode"
|
|
10
|
+
},
|
|
11
|
+
"[typescriptreact]": {
|
|
12
|
+
"editor.defaultFormatter": "oxc.oxc-vscode"
|
|
13
|
+
},
|
|
14
|
+
"[typescript]": {
|
|
15
|
+
"editor.defaultFormatter": "oxc.oxc-vscode"
|
|
16
|
+
},
|
|
17
|
+
"[json]": {
|
|
18
|
+
"editor.defaultFormatter": "oxc.oxc-vscode"
|
|
19
|
+
},
|
|
20
|
+
"typescript.preferences.importModuleSpecifierEnding": "js",
|
|
21
|
+
"typescript.reportStyleChecksAsWarnings": false,
|
|
22
|
+
"typescript.updateImportsOnFileMove.enabled": "always",
|
|
23
|
+
"typescript.preferences.autoImportFileExcludePatterns": ["**/node_modules/vitest"],
|
|
24
|
+
"typescript.experimental.useTsgo": true
|
|
25
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Using _fate_ for React applications
|
|
2
|
+
|
|
3
|
+
This guidance is for agents working in projects bootstrapped from the fate template. It focuses on the client-side patterns for fate's view composition and action execution.
|
|
4
|
+
|
|
5
|
+
## Core Workflow
|
|
6
|
+
|
|
7
|
+
- **Define views with explicit selections:** Define reusable view objects with `view<T>()({...})`, compose them via spreads, and resolve them with `useView`.
|
|
8
|
+
- **Resolve data via references:** Avoid passing raw fetched objects; instead pass `ViewRef`s to downstream components to keep selections scoped and cache-aware. Then call `const result = useView(viewDefinition, ref)` to read only the selected fields while subscribing to cache updates. Name the prop after the result data, and rename it using destructuring in the function arguments: `const PostComponent = ({ post: postRef }: { post: ViewRef<'Post'>}) => { const post = useView(PostView, postRef); ... }`.
|
|
9
|
+
- **Request data at screen roots:** Use `useRequest` to compose all views required for a route or screen into a single typed request; wrap roots in `Suspense` and an error boundary since requests may suspend or throw.
|
|
10
|
+
- **Compose reusable views:** Extract nested selections into their own views (e.g., `UserView`) and compose them inside parent views (`author: UserView`) to avoid duplication and overfetching. This keeps selections DRY and ensures view updates propagate consistently when the cache changes.
|
|
11
|
+
|
|
12
|
+
## Actions & Mutations
|
|
13
|
+
|
|
14
|
+
- **Prefer `fate.actions` with `useActionState`:** Trigger mutations through React Actions to integrate with Suspense/`useTransition`, receiving `[result, action, isPending]`. Call actions via the relevant data inputs, for example `action({input: { id: post.id }})`.
|
|
15
|
+
- **Optimistic updates by default:** Pass `optimistic` payloads to immediately update the normalized cache; only views selecting the changed fields re-render and failures roll back automatically. Optimistic payloads should match the expected server data changes of the associated object.
|
|
16
|
+
- **Select extra fields when side effects matter:** When a mutation affects related entities (e.g., comment count on a post), pass a `view` to the action to fetch the needed fields in the same round-trip and keep the cache coherent for all dependent views.
|
|
17
|
+
- **Imperative escape hatch:** Use `fate.mutations` when you must fire mutations outside React components or without waiting on prior actions; handle loading/error states yourself.
|
|
18
|
+
- **Handle deletions and resets explicitly:** Use the `delete: true` flag to evict records from the cache, and send the `'reset'` token to clear stale action errors without re-running the mutation.
|
|
19
|
+
- **Error handling model:** Treat expected errors (e.g., 404) at the call site via the action result; unexpected errors bubble to the nearest React error boundary.
|
|
20
|
+
|
|
21
|
+
## Common Pitfalls
|
|
22
|
+
|
|
23
|
+
- **Use ViewRefs:** Pass references instead of raw data. Keep components focused on views and `ViewRef`s to let fate manage data masking and updates.
|
|
24
|
+
- **Co-locate data needs:** Keep view definitions near their components and compose them upward to the request root for predictable fetching.
|
|
25
|
+
- **Use Suspense:** Wrap pages in `Suspense`/`ErrorBoundary` instead of ad-hoc loading/error flags; fate aligns with Async React by design.
|
|
26
|
+
- **Do not duplicate types:** Keep generated fate types and views imported from the server package. Avoid redefining entity shapes on the client. This ensures view selections stay type-safe end-to-end.
|
|
27
|
+
- **`useRequest` only at the root:** When adding routes or layouts, create a dedicated `useRequest` call per screen root that pulls together all child views; do not scatter `useRequest` across leaf components unless it's necessary to issue requests due to user input.
|
|
28
|
+
- **React Actions:** Prefer React Action-friendly UI primitives (buttons/forms that accept an `action` prop). If unavailable, wrap action calls with `startTransition` in `onClick` handlers.
|
|
29
|
+
- **Generated Client** The fate client is generated via `pnpm fate:generate`. It should not be manually edited. Instead make the proper schema changes on the server and run `pnpm fate:generate`.
|
|
30
|
+
- **Library Versions:** This repository uses the most recent releases of React, fate, Vite, and more. You might not know about the new releases yet, please don't get confused. The versions you see are real, and there are no feature or version mismatches. You can search the internet for more information about them.
|
|
31
|
+
|
|
32
|
+
Full documentation can be found on the filesystem at `./client/node_modules/react-fate/README.md` or online at [fate.technology](https://fate.technology/).
|
|
33
|
+
|
|
34
|
+
## Review Checklist for Agents
|
|
35
|
+
|
|
36
|
+
- [ ] Every component that reads server data does so through `useView` and receives a `ViewRef` prop.
|
|
37
|
+
- [ ] Root components gather data with a single `useRequest` call.
|
|
38
|
+
- [ ] Mutations are wired through `useActionState` with optimistic updates and necessary `view` selections; imperative `fate.mutations` are justified when used.
|
|
39
|
+
- [ ] Shared selections live in reusable views using regular JavaScript object spreads rather than duplicated field lists.
|
|
40
|
+
|
|
41
|
+
<!--VITE PLUS START-->
|
|
42
|
+
|
|
43
|
+
# Using Vite+, the Unified Toolchain for the Web
|
|
44
|
+
|
|
45
|
+
This project is using Vite+, a unified toolchain built on top of Vite, Rolldown, Vitest, tsdown, Oxlint, Oxfmt, and Vite Task. Vite+ wraps runtime management, package management, and frontend tooling in a single global CLI called `vp`. Vite+ is distinct from Vite, and it invokes Vite through `vp dev` and `vp build`. Run `vp help` to print a list of commands and `vp <command> --help` for information about a specific command.
|
|
46
|
+
|
|
47
|
+
Docs are local at `node_modules/vite-plus/docs` or online at https://viteplus.dev/guide/.
|
|
48
|
+
|
|
49
|
+
## Review Checklist
|
|
50
|
+
|
|
51
|
+
- [ ] Run `vp install` after pulling remote changes and before getting started.
|
|
52
|
+
- [ ] Run `vp check` and `vp test` to format, lint, type check and test changes.
|
|
53
|
+
- [ ] Check if there are `vite.config.ts` tasks or `package.json` scripts necessary for validation, run via `vp run <script>`.
|
|
54
|
+
|
|
55
|
+
<!--VITE PLUS END-->
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<picture>
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="/public/fate-logo-dark.svg">
|
|
4
|
+
<source media="(prefers-color-scheme: light)" srcset="/public/fate-logo.svg">
|
|
5
|
+
<img alt="Logo" src="/public/fate-logo.svg" width="50%">
|
|
6
|
+
</picture>
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
**_fate_** is a modern data client for React inspired by [Relay](https://relay.dev/) and [GraphQL](https://graphql.org/). It combines view composition, normalized caching, data masking, Async React features, and type-safe data fetching.
|
|
10
|
+
|
|
11
|
+
Check out [fate.technology](https://fate.technology) for documentation, examples, and guides.
|
|
12
|
+
|
|
13
|
+
# _fate_ Quick Start Template
|
|
14
|
+
|
|
15
|
+
Create a new fate app with Vite+:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
vp create fate my-app --template http
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Getting Started with _fate_
|
|
22
|
+
|
|
23
|
+
Read the [Getting Started Guide](https://fate.technology/guide/core-concepts) to learn how to use _fate_ in your React applications.
|
|
24
|
+
|
|
25
|
+
## Technologies
|
|
26
|
+
|
|
27
|
+
This template combines the Nakazawa Tech's [Web App Template](https://github.com/nkzw-tech/web-app-template) and [Server Template](https://github.com/nkzw-tech/server-template) into a monorepo, with unified tooling and _fate_ as the data client. It uses the native fate HTTP transport with Drizzle.
|
|
28
|
+
|
|
29
|
+
_This template lives on the edge._ It's a turbocharged starting point on top of an already optimized stack. It uses TypeScript Go, Vite+, and ships with sensible defaults to unlock an incredibly fast development experience. It follows the principles laid out in [Building Scalable Applications](https://www.youtube.com/watch?v=rxPTEko8J7c&t=36s).
|
|
30
|
+
|
|
31
|
+
Next to [_fate_](https://fate.technology), it comes with the following technologies:
|
|
32
|
+
|
|
33
|
+
### Client Technologies
|
|
34
|
+
|
|
35
|
+
- [Vite 8](https://vitejs.dev/)
|
|
36
|
+
- [React](https://reactjs.org/) with [React Compiler](https://react.dev/learn/react-compiler) enabled
|
|
37
|
+
- [Tailwind](https://tailwindcss.com/)
|
|
38
|
+
- [fbtee](https://github.com/nkzw-tech/fbtee) for i18n
|
|
39
|
+
- [Better Auth](https://www.better-auth.com/) for authentication
|
|
40
|
+
- [Void Pages Router](https://void.cloud/docs)
|
|
41
|
+
- [TypeScript](https://www.typescriptlang.org)
|
|
42
|
+
- [pnpm](https://pnpm.io/)
|
|
43
|
+
|
|
44
|
+
### Server Technologies
|
|
45
|
+
|
|
46
|
+
- [Drizzle](https://orm.drizzle.team/) as the ORM.
|
|
47
|
+
- Native fate HTTP transport for type-safe data fetching.
|
|
48
|
+
- [Hono](https://hono.dev/)
|
|
49
|
+
- [Better Auth](https://better-auth.com/) for Authentication.
|
|
50
|
+
|
|
51
|
+
### Folder Structure
|
|
52
|
+
|
|
53
|
+
- `client/` - The React client application using _fate_.
|
|
54
|
+
- `server/` - The fate server using native HTTP with Drizzle.
|
|
55
|
+
|
|
56
|
+
## Initial Setup
|
|
57
|
+
|
|
58
|
+
You'll need Node.js 24+ and [Vite+](https://viteplus.dev/guide/).
|
|
59
|
+
|
|
60
|
+
Install dependencies:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
vp install
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Review `server/.env`, which is copied from `server/.env.example` when the app is created. The default local values expect:
|
|
67
|
+
|
|
68
|
+
- Postgres at `postgresql://fate:echo@localhost:5432/fate`.
|
|
69
|
+
- The server at `http://localhost:9000`.
|
|
70
|
+
- The client at `http://localhost:5173`.
|
|
71
|
+
|
|
72
|
+
Start Postgres with Docker:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
docker-compose up -d
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Alternatively, create the database manually:
|
|
79
|
+
|
|
80
|
+
```SQL
|
|
81
|
+
CREATE ROLE fate WITH LOGIN PASSWORD 'echo';
|
|
82
|
+
CREATE DATABASE fate;
|
|
83
|
+
ALTER DATABASE fate OWNER TO fate;
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Then set up the schema, seed data, translations, and generated fate client:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
vp run dev:setup
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Start the app:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
vp run dev
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
The client runs at `http://localhost:5173` and the server runs at `http://localhost:9000`. Native fate requests go to `/fate`; live updates use the SSE endpoint under `/fate/live`.
|
|
99
|
+
|
|
100
|
+
## Development
|
|
101
|
+
|
|
102
|
+
Common commands from the project root:
|
|
103
|
+
|
|
104
|
+
- `vp run dev` starts the client and server together.
|
|
105
|
+
- `vp run dev:client` starts only the client.
|
|
106
|
+
- `vp run dev:server` starts only the server.
|
|
107
|
+
- `vp run dev:setup` pushes the Drizzle schema, seeds the database, runs fbtee setup, and regenerates the fate client.
|
|
108
|
+
- `vp run fate:generate` regenerates `client/.fate/client.generated.ts` after changing server views, roots, or mutations.
|
|
109
|
+
- `vp run drizzle` opens Drizzle Kit commands for the server package.
|
|
110
|
+
- `vp check --fix` formats, lints, and type-checks the workspace.
|
|
111
|
+
- `vp test` runs the test suite.
|
|
112
|
+
- `vp run build` builds the client and server.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
.fate/
|
|
2
|
+
**/.fate/
|
|
3
|
+
.void/
|
|
4
|
+
**/.void/
|
|
5
|
+
.eslintcache
|
|
6
|
+
.pnpm-debug.log
|
|
7
|
+
**/node_modules/
|
|
8
|
+
/node_modules/
|
|
9
|
+
client/.enum_manifest.json
|
|
10
|
+
client/dist/
|
|
11
|
+
client/source_strings.json
|
|
12
|
+
client/src/translations/
|
|
13
|
+
coverage/
|
|
14
|
+
dist/
|
|
15
|
+
server/.env
|
|
16
|
+
server/.prod.env
|
|
17
|
+
server/dist/
|
|
18
|
+
server/src/prisma/prisma-client/
|
|
19
|
+
tsconfig.tsbuildinfo
|
|
20
|
+
vite.config.ts.timestamp-*
|