tvi-cli 0.1.4
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/README.md +147 -0
- package/dist/index.js +4315 -0
- package/package.json +75 -0
- package/templates/addons/biome/biome.json.hbs +83 -0
- package/templates/addons/husky/.husky/pre-commit +1 -0
- package/templates/addons/pwa/apps/web/next/public/favicon/apple-touch-icon.png +0 -0
- package/templates/addons/pwa/apps/web/next/public/favicon/favicon-96x96.png +0 -0
- package/templates/addons/pwa/apps/web/next/public/favicon/favicon.svg +6 -0
- package/templates/addons/pwa/apps/web/next/public/favicon/site.webmanifest.hbs +21 -0
- package/templates/addons/pwa/apps/web/next/public/favicon/web-app-manifest-192x192.png +0 -0
- package/templates/addons/pwa/apps/web/next/public/favicon/web-app-manifest-512x512.png +0 -0
- package/templates/addons/pwa/apps/web/next/src/app/manifest.ts.hbs +26 -0
- package/templates/addons/pwa/apps/web/vite/public/logo.png +0 -0
- package/templates/addons/pwa/apps/web/vite/pwa-assets.config.ts.hbs +12 -0
- package/templates/addons/turborepo/turbo.json.hbs +43 -0
- package/templates/api/orpc/native/utils/orpc.ts.hbs +35 -0
- package/templates/api/orpc/server/base/src/lib/context.ts.hbs +125 -0
- package/templates/api/orpc/server/base/src/lib/orpc.ts.hbs +21 -0
- package/templates/api/orpc/server/next/src/app/rpc/[...all]/route.ts.hbs +23 -0
- package/templates/api/orpc/web/nuxt/app/plugins/orpc.ts.hbs +35 -0
- package/templates/api/orpc/web/react/base/src/utils/orpc.ts.hbs +42 -0
- package/templates/api/orpc/web/solid/src/utils/orpc.ts.hbs +30 -0
- package/templates/api/orpc/web/svelte/src/lib/orpc.ts.hbs +31 -0
- package/templates/api/trpc/native/utils/trpc.ts.hbs +32 -0
- package/templates/api/trpc/server/base/src/lib/context.ts.hbs +127 -0
- package/templates/api/trpc/server/base/src/lib/trpc.ts.hbs +26 -0
- package/templates/api/trpc/server/next/src/app/trpc/[trpc]/route.ts +14 -0
- package/templates/api/trpc/web/react/base/src/utils/trpc.ts.hbs +97 -0
- package/templates/auth/native/native-base/lib/auth-client.ts.hbs +13 -0
- package/templates/auth/native/nativewind/app/(drawer)/index.tsx.hbs +95 -0
- package/templates/auth/native/nativewind/components/sign-in.tsx.hbs +93 -0
- package/templates/auth/native/nativewind/components/sign-up.tsx.hbs +104 -0
- package/templates/auth/native/unistyles/app/(drawer)/index.tsx.hbs +179 -0
- package/templates/auth/native/unistyles/components/sign-in.tsx.hbs +134 -0
- package/templates/auth/native/unistyles/components/sign-up.tsx.hbs +152 -0
- package/templates/auth/server/base/src/lib/auth.ts.hbs +141 -0
- package/templates/auth/server/db/drizzle/mysql/src/db/schema/auth.ts +58 -0
- package/templates/auth/server/db/drizzle/postgres/src/db/schema/auth.ts +47 -0
- package/templates/auth/server/db/drizzle/sqlite/src/db/schema/auth.ts +55 -0
- package/templates/auth/server/db/mongoose/mongodb/src/db/models/auth.model.ts +68 -0
- package/templates/auth/server/db/prisma/mongodb/prisma/schema/auth.prisma +59 -0
- package/templates/auth/server/db/prisma/mysql/prisma/schema/auth.prisma +59 -0
- package/templates/auth/server/db/prisma/postgres/prisma/schema/auth.prisma +59 -0
- package/templates/auth/server/db/prisma/sqlite/prisma/schema/auth.prisma +59 -0
- package/templates/auth/server/next/src/app/api/auth/[...all]/route.ts +4 -0
- package/templates/auth/web/nuxt/app/components/SignInForm.vue +77 -0
- package/templates/auth/web/nuxt/app/components/SignUpForm.vue +84 -0
- package/templates/auth/web/nuxt/app/components/UserMenu.vue +42 -0
- package/templates/auth/web/nuxt/app/middleware/auth.ts +12 -0
- package/templates/auth/web/nuxt/app/pages/dashboard.vue +27 -0
- package/templates/auth/web/nuxt/app/pages/login.vue +24 -0
- package/templates/auth/web/nuxt/app/plugins/auth-client.ts +16 -0
- package/templates/auth/web/react/base/src/lib/auth-client.ts.hbs +10 -0
- package/templates/auth/web/react/next/src/app/dashboard/page.tsx.hbs +47 -0
- package/templates/auth/web/react/next/src/app/login/page.tsx +16 -0
- package/templates/auth/web/react/next/src/components/sign-in-form.tsx +135 -0
- package/templates/auth/web/react/next/src/components/sign-up-form.tsx +160 -0
- package/templates/auth/web/react/next/src/components/theme-provider.tsx +11 -0
- package/templates/auth/web/react/next/src/components/user-menu.tsx +60 -0
- package/templates/auth/web/react/react-router/src/components/sign-in-form.tsx +135 -0
- package/templates/auth/web/react/react-router/src/components/sign-up-form.tsx +160 -0
- package/templates/auth/web/react/react-router/src/components/user-menu.tsx +60 -0
- package/templates/auth/web/react/react-router/src/routes/dashboard.tsx.hbs +40 -0
- package/templates/auth/web/react/react-router/src/routes/login.tsx +13 -0
- package/templates/auth/web/react/tanstack-router/src/components/sign-in-form.tsx +139 -0
- package/templates/auth/web/react/tanstack-router/src/components/sign-up-form.tsx +164 -0
- package/templates/auth/web/react/tanstack-router/src/components/user-menu.tsx +62 -0
- package/templates/auth/web/react/tanstack-router/src/routes/dashboard.tsx.hbs +47 -0
- package/templates/auth/web/react/tanstack-router/src/routes/login.tsx +18 -0
- package/templates/auth/web/react/tanstack-start/src/components/sign-in-form.tsx +139 -0
- package/templates/auth/web/react/tanstack-start/src/components/sign-up-form.tsx +164 -0
- package/templates/auth/web/react/tanstack-start/src/components/user-menu.tsx +62 -0
- package/templates/auth/web/react/tanstack-start/src/routes/dashboard.tsx.hbs +51 -0
- package/templates/auth/web/react/tanstack-start/src/routes/login.tsx +18 -0
- package/templates/auth/web/solid/src/components/sign-in-form.tsx +132 -0
- package/templates/auth/web/solid/src/components/sign-up-form.tsx +158 -0
- package/templates/auth/web/solid/src/components/user-menu.tsx.hbs +55 -0
- package/templates/auth/web/solid/src/lib/auth-client.ts +5 -0
- package/templates/auth/web/solid/src/routes/dashboard.tsx +38 -0
- package/templates/auth/web/solid/src/routes/login.tsx +23 -0
- package/templates/auth/web/svelte/src/components/SignInForm.svelte +108 -0
- package/templates/auth/web/svelte/src/components/SignUpForm.svelte +142 -0
- package/templates/auth/web/svelte/src/components/UserMenu.svelte +54 -0
- package/templates/auth/web/svelte/src/lib/auth-client.ts +6 -0
- package/templates/auth/web/svelte/src/routes/dashboard/+page.svelte +31 -0
- package/templates/auth/web/svelte/src/routes/login/+page.svelte +12 -0
- package/templates/backend/convex/packages/backend/_gitignore +2 -0
- package/templates/backend/convex/packages/backend/convex/README.md +90 -0
- package/templates/backend/convex/packages/backend/convex/healthCheck.ts +7 -0
- package/templates/backend/convex/packages/backend/convex/schema.ts +9 -0
- package/templates/backend/convex/packages/backend/convex/todos.ts +42 -0
- package/templates/backend/convex/packages/backend/convex/tsconfig.json +25 -0
- package/templates/backend/convex/packages/backend/package.json.hbs +17 -0
- package/templates/backend/server/elysia/src/index.ts.hbs +72 -0
- package/templates/backend/server/express/src/index.ts.hbs +88 -0
- package/templates/backend/server/fastify/src/index.ts.hbs +155 -0
- package/templates/backend/server/hono/src/index.ts.hbs +133 -0
- package/templates/backend/server/next/next-env.d.ts +5 -0
- package/templates/backend/server/next/next.config.ts +7 -0
- package/templates/backend/server/next/package.json.hbs +24 -0
- package/templates/backend/server/next/src/app/route.ts +5 -0
- package/templates/backend/server/next/src/middleware.ts +19 -0
- package/templates/backend/server/next/tsconfig.json.hbs +33 -0
- package/templates/backend/server/server-base/_gitignore +52 -0
- package/templates/backend/server/server-base/package.json.hbs +28 -0
- package/templates/backend/server/server-base/src/routers/index.ts.hbs +53 -0
- package/templates/backend/server/server-base/tsconfig.json.hbs +39 -0
- package/templates/base/_gitignore +2 -0
- package/templates/base/package.json.hbs +11 -0
- package/templates/db/drizzle/mysql/drizzle.config.ts.hbs +10 -0
- package/templates/db/drizzle/mysql/src/db/index.ts.hbs +20 -0
- package/templates/db/drizzle/postgres/drizzle.config.ts.hbs +10 -0
- package/templates/db/drizzle/postgres/src/db/index.ts.hbs +12 -0
- package/templates/db/drizzle/sqlite/drizzle.config.ts.hbs +24 -0
- package/templates/db/drizzle/sqlite/src/db/index.ts.hbs +35 -0
- package/templates/db/mongoose/mongodb/src/db/index.ts.hbs +9 -0
- package/templates/db/prisma/mongodb/prisma/index.ts.hbs +5 -0
- package/templates/db/prisma/mongodb/prisma/schema/schema.prisma +10 -0
- package/templates/db/prisma/mongodb/prisma.config.ts.hbs +8 -0
- package/templates/db/prisma/mysql/prisma/index.ts +5 -0
- package/templates/db/prisma/mysql/prisma/schema/schema.prisma +10 -0
- package/templates/db/prisma/mysql/prisma.config.ts +8 -0
- package/templates/db/prisma/postgres/prisma/index.ts +5 -0
- package/templates/db/prisma/postgres/prisma/schema/schema.prisma.hbs +13 -0
- package/templates/db/prisma/postgres/prisma.config.ts.hbs +12 -0
- package/templates/db/prisma/sqlite/prisma/index.ts +5 -0
- package/templates/db/prisma/sqlite/prisma/schema/schema.prisma +10 -0
- package/templates/db/prisma/sqlite/prisma.config.ts +8 -0
- package/templates/examples/ai/native/nativewind/app/(drawer)/ai.tsx.hbs +155 -0
- package/templates/examples/ai/native/nativewind/polyfills.js +25 -0
- package/templates/examples/ai/native/unistyles/app/(drawer)/ai.tsx.hbs +279 -0
- package/templates/examples/ai/native/unistyles/polyfills.js +25 -0
- package/templates/examples/ai/server/next/src/app/ai/route.ts +15 -0
- package/templates/examples/ai/web/nuxt/app/pages/ai.vue +63 -0
- package/templates/examples/ai/web/react/next/src/app/ai/page.tsx +67 -0
- package/templates/examples/ai/web/react/react-router/src/routes/ai.tsx +64 -0
- package/templates/examples/ai/web/react/tanstack-router/src/routes/ai.tsx +69 -0
- package/templates/examples/ai/web/react/tanstack-start/src/routes/ai.tsx +69 -0
- package/templates/examples/ai/web/svelte/src/routes/ai/+page.svelte +98 -0
- package/templates/examples/todo/native/nativewind/app/(drawer)/todos.tsx.hbs +295 -0
- package/templates/examples/todo/native/unistyles/app/(drawer)/todos.tsx.hbs +340 -0
- package/templates/examples/todo/server/drizzle/base/src/routers/todo.ts.hbs +79 -0
- package/templates/examples/todo/server/drizzle/mysql/src/db/schema/todo.ts +7 -0
- package/templates/examples/todo/server/drizzle/postgres/src/db/schema/todo.ts +7 -0
- package/templates/examples/todo/server/drizzle/sqlite/src/db/schema/todo.ts +7 -0
- package/templates/examples/todo/server/mongoose/base/src/routers/todo.ts.hbs +66 -0
- package/templates/examples/todo/server/mongoose/mongodb/src/db/models/todo.model.ts +24 -0
- package/templates/examples/todo/server/prisma/base/src/routers/todo.ts.hbs +118 -0
- package/templates/examples/todo/server/prisma/mongodb/prisma/schema/todo.prisma +7 -0
- package/templates/examples/todo/server/prisma/mysql/prisma/schema/todo.prisma +7 -0
- package/templates/examples/todo/server/prisma/postgres/prisma/schema/todo.prisma +7 -0
- package/templates/examples/todo/server/prisma/sqlite/prisma/schema/todo.prisma +7 -0
- package/templates/examples/todo/web/nuxt/app/pages/todos.vue +108 -0
- package/templates/examples/todo/web/react/next/src/app/todos/page.tsx.hbs +245 -0
- package/templates/examples/todo/web/react/react-router/src/routes/todos.tsx.hbs +242 -0
- package/templates/examples/todo/web/react/tanstack-router/src/routes/todos.tsx.hbs +247 -0
- package/templates/examples/todo/web/react/tanstack-start/src/routes/todos.tsx.hbs +268 -0
- package/templates/examples/todo/web/solid/src/routes/todos.tsx.hbs +132 -0
- package/templates/examples/todo/web/svelte/src/routes/todos/+page.svelte.hbs +317 -0
- package/templates/extras/_npmrc.hbs +5 -0
- package/templates/extras/pnpm-workspace.yaml +3 -0
- package/templates/frontend/native/native-base/assets/adaptive-icon.png +0 -0
- package/templates/frontend/native/native-base/assets/favicon.png +0 -0
- package/templates/frontend/native/native-base/assets/icon.png +0 -0
- package/templates/frontend/native/native-base/assets/splash.png +0 -0
- package/templates/frontend/native/nativewind/_gitignore +25 -0
- package/templates/frontend/native/nativewind/app/(drawer)/(tabs)/_layout.tsx +46 -0
- package/templates/frontend/native/nativewind/app/(drawer)/(tabs)/index.tsx +19 -0
- package/templates/frontend/native/nativewind/app/(drawer)/(tabs)/two.tsx +19 -0
- package/templates/frontend/native/nativewind/app/(drawer)/_layout.tsx.hbs +67 -0
- package/templates/frontend/native/nativewind/app/(drawer)/index.tsx.hbs +95 -0
- package/templates/frontend/native/nativewind/app/+html.tsx +47 -0
- package/templates/frontend/native/nativewind/app/+not-found.tsx +29 -0
- package/templates/frontend/native/nativewind/app/_layout.tsx.hbs +126 -0
- package/templates/frontend/native/nativewind/app/modal.tsx +14 -0
- package/templates/frontend/native/nativewind/app-env.d.ts +2 -0
- package/templates/frontend/native/nativewind/app.json +46 -0
- package/templates/frontend/native/nativewind/babel.config.js +11 -0
- package/templates/frontend/native/nativewind/components/container.tsx +8 -0
- package/templates/frontend/native/nativewind/components/header-button.tsx +26 -0
- package/templates/frontend/native/nativewind/components/tabbar-icon.tsx +8 -0
- package/templates/frontend/native/nativewind/global.css +50 -0
- package/templates/frontend/native/nativewind/lib/android-navigation-bar.tsx +11 -0
- package/templates/frontend/native/nativewind/lib/constants.ts +18 -0
- package/templates/frontend/native/nativewind/lib/use-color-scheme.ts +12 -0
- package/templates/frontend/native/nativewind/metro.config.js +59 -0
- package/templates/frontend/native/nativewind/package.json.hbs +49 -0
- package/templates/frontend/native/nativewind/tailwind.config.js +59 -0
- package/templates/frontend/native/nativewind/tsconfig.json.hbs +23 -0
- package/templates/frontend/native/unistyles/_gitignore +24 -0
- package/templates/frontend/native/unistyles/app/(drawer)/(tabs)/_layout.tsx +39 -0
- package/templates/frontend/native/unistyles/app/(drawer)/(tabs)/index.tsx +37 -0
- package/templates/frontend/native/unistyles/app/(drawer)/(tabs)/two.tsx +37 -0
- package/templates/frontend/native/unistyles/app/(drawer)/_layout.tsx.hbs +87 -0
- package/templates/frontend/native/unistyles/app/(drawer)/index.tsx.hbs +194 -0
- package/templates/frontend/native/unistyles/app/+html.tsx +48 -0
- package/templates/frontend/native/unistyles/app/+not-found.tsx +65 -0
- package/templates/frontend/native/unistyles/app/_layout.tsx.hbs +104 -0
- package/templates/frontend/native/unistyles/app/modal.tsx +33 -0
- package/templates/frontend/native/unistyles/app.json +44 -0
- package/templates/frontend/native/unistyles/babel.config.js +20 -0
- package/templates/frontend/native/unistyles/breakpoints.ts +9 -0
- package/templates/frontend/native/unistyles/components/container.tsx +15 -0
- package/templates/frontend/native/unistyles/components/header-button.tsx +36 -0
- package/templates/frontend/native/unistyles/components/tabbar-icon.tsx +8 -0
- package/templates/frontend/native/unistyles/expo-env.d.ts +3 -0
- package/templates/frontend/native/unistyles/index.js +2 -0
- package/templates/frontend/native/unistyles/metro.config.js +20 -0
- package/templates/frontend/native/unistyles/package.json.hbs +50 -0
- package/templates/frontend/native/unistyles/theme.ts +98 -0
- package/templates/frontend/native/unistyles/tsconfig.json.hbs +17 -0
- package/templates/frontend/native/unistyles/unistyles.ts +27 -0
- package/templates/frontend/nuxt/_gitignore +24 -0
- package/templates/frontend/nuxt/app/app.config.ts +15 -0
- package/templates/frontend/nuxt/app/app.vue +13 -0
- package/templates/frontend/nuxt/app/assets/css/main.css +2 -0
- package/templates/frontend/nuxt/app/components/Header.vue.hbs +45 -0
- package/templates/frontend/nuxt/app/components/Loader.vue +5 -0
- package/templates/frontend/nuxt/app/components/ModeToggle.vue +23 -0
- package/templates/frontend/nuxt/app/layouts/default.vue.hbs +11 -0
- package/templates/frontend/nuxt/app/pages/index.vue.hbs +57 -0
- package/templates/frontend/nuxt/app/plugins/vue-query.ts.hbs +44 -0
- package/templates/frontend/nuxt/nuxt.config.ts.hbs +19 -0
- package/templates/frontend/nuxt/package.json.hbs +25 -0
- package/templates/frontend/nuxt/public/favicon.ico +0 -0
- package/templates/frontend/nuxt/public/robots.txt +2 -0
- package/templates/frontend/nuxt/server/tsconfig.json +3 -0
- package/templates/frontend/nuxt/tsconfig.json.hbs +9 -0
- package/templates/frontend/react/next/next-env.d.ts.hbs +5 -0
- package/templates/frontend/react/next/next.config.ts.hbs +5 -0
- package/templates/frontend/react/next/package.json.hbs +34 -0
- package/templates/frontend/react/next/postcss.config.mjs.hbs +5 -0
- package/templates/frontend/react/next/src/app/favicon.ico +0 -0
- package/templates/frontend/react/next/src/app/layout.tsx.hbs +41 -0
- package/templates/frontend/react/next/src/app/page.tsx.hbs +68 -0
- package/templates/frontend/react/next/src/components/mode-toggle.tsx.hbs +39 -0
- package/templates/frontend/react/next/src/components/providers.tsx.hbs +56 -0
- package/templates/frontend/react/next/src/components/theme-provider.tsx.hbs +11 -0
- package/templates/frontend/react/next/tsconfig.json.hbs +33 -0
- package/templates/frontend/react/react-router/package.json.hbs +42 -0
- package/templates/frontend/react/react-router/public/favicon.ico +0 -0
- package/templates/frontend/react/react-router/react-router.config.ts +6 -0
- package/templates/frontend/react/react-router/src/components/mode-toggle.tsx +37 -0
- package/templates/frontend/react/react-router/src/components/theme-provider.tsx +73 -0
- package/templates/frontend/react/react-router/src/root.tsx.hbs +152 -0
- package/templates/frontend/react/react-router/src/routes/_index.tsx.hbs +74 -0
- package/templates/frontend/react/react-router/src/routes.ts +4 -0
- package/templates/frontend/react/react-router/tsconfig.json.hbs +32 -0
- package/templates/frontend/react/react-router/vite.config.ts.hbs +33 -0
- package/templates/frontend/react/tanstack-router/index.html +12 -0
- package/templates/frontend/react/tanstack-router/package.json.hbs +41 -0
- package/templates/frontend/react/tanstack-router/src/components/mode-toggle.tsx +37 -0
- package/templates/frontend/react/tanstack-router/src/components/theme-provider.tsx +73 -0
- package/templates/frontend/react/tanstack-router/src/main.tsx.hbs +66 -0
- package/templates/frontend/react/tanstack-router/src/routes/__root.tsx.hbs +100 -0
- package/templates/frontend/react/tanstack-router/src/routes/index.tsx.hbs +74 -0
- package/templates/frontend/react/tanstack-router/tsconfig.json.hbs +23 -0
- package/templates/frontend/react/tanstack-router/vite.config.ts.hbs +39 -0
- package/templates/frontend/react/tanstack-start/package.json.hbs +44 -0
- package/templates/frontend/react/tanstack-start/public/robots.txt +3 -0
- package/templates/frontend/react/tanstack-start/src/router.tsx.hbs +144 -0
- package/templates/frontend/react/tanstack-start/src/routes/__root.tsx.hbs +97 -0
- package/templates/frontend/react/tanstack-start/src/routes/index.tsx.hbs +74 -0
- package/templates/frontend/react/tanstack-start/tsconfig.json.hbs +33 -0
- package/templates/frontend/react/tanstack-start/vite.config.ts +8 -0
- package/templates/frontend/react/web-base/_gitignore +52 -0
- package/templates/frontend/react/web-base/components.json +21 -0
- package/templates/frontend/react/web-base/src/components/header.tsx.hbs +79 -0
- package/templates/frontend/react/web-base/src/components/loader.tsx +9 -0
- package/templates/frontend/react/web-base/src/components/ui/button.tsx +59 -0
- package/templates/frontend/react/web-base/src/components/ui/card.tsx +92 -0
- package/templates/frontend/react/web-base/src/components/ui/checkbox.tsx +30 -0
- package/templates/frontend/react/web-base/src/components/ui/dropdown-menu.tsx +257 -0
- package/templates/frontend/react/web-base/src/components/ui/input.tsx +21 -0
- package/templates/frontend/react/web-base/src/components/ui/label.tsx +22 -0
- package/templates/frontend/react/web-base/src/components/ui/skeleton.tsx +13 -0
- package/templates/frontend/react/web-base/src/components/ui/sonner.tsx +25 -0
- package/templates/frontend/react/web-base/src/index.css +134 -0
- package/templates/frontend/react/web-base/src/lib/utils.ts +6 -0
- package/templates/frontend/solid/_gitignore +7 -0
- package/templates/frontend/solid/index.html +13 -0
- package/templates/frontend/solid/package.json.hbs +27 -0
- package/templates/frontend/solid/public/robots.txt +3 -0
- package/templates/frontend/solid/src/components/header.tsx.hbs +38 -0
- package/templates/frontend/solid/src/components/loader.tsx +9 -0
- package/templates/frontend/solid/src/main.tsx.hbs +38 -0
- package/templates/frontend/solid/src/routes/__root.tsx.hbs +34 -0
- package/templates/frontend/solid/src/routes/index.tsx.hbs +61 -0
- package/templates/frontend/solid/src/styles.css +5 -0
- package/templates/frontend/solid/tsconfig.json.hbs +34 -0
- package/templates/frontend/solid/vite.config.js.hbs +39 -0
- package/templates/frontend/svelte/_gitignore +23 -0
- package/templates/frontend/svelte/_npmrc +1 -0
- package/templates/frontend/svelte/package.json.hbs +31 -0
- package/templates/frontend/svelte/src/app.css +5 -0
- package/templates/frontend/svelte/src/app.d.ts +13 -0
- package/templates/frontend/svelte/src/app.html +12 -0
- package/templates/frontend/svelte/src/components/Header.svelte.hbs +40 -0
- package/templates/frontend/svelte/src/lib/index.ts +1 -0
- package/templates/frontend/svelte/src/routes/+layout.svelte.hbs +54 -0
- package/templates/frontend/svelte/src/routes/+page.svelte.hbs +72 -0
- package/templates/frontend/svelte/static/favicon.png +0 -0
- package/templates/frontend/svelte/svelte.config.js +18 -0
- package/templates/frontend/svelte/tsconfig.json.hbs +24 -0
- package/templates/frontend/svelte/vite.config.ts +7 -0
- package/templates/runtime/workers/apps/server/wrangler.jsonc.hbs +34 -0
@@ -0,0 +1,340 @@
|
|
1
|
+
import { useState } from "react";
|
2
|
+
import {
|
3
|
+
View,
|
4
|
+
Text,
|
5
|
+
TextInput,
|
6
|
+
TouchableOpacity,
|
7
|
+
ScrollView,
|
8
|
+
ActivityIndicator,
|
9
|
+
Alert,
|
10
|
+
} from "react-native";
|
11
|
+
import { Ionicons } from "@expo/vector-icons";
|
12
|
+
import { StyleSheet, useUnistyles } from "react-native-unistyles";
|
13
|
+
|
14
|
+
{{#if (eq backend "convex")}}
|
15
|
+
import { useMutation, useQuery } from "convex/react";
|
16
|
+
import { api } from "@{{projectName}}/backend/convex/_generated/api";
|
17
|
+
import type { Id } from "@{{projectName}}/backend/convex/_generated/dataModel";
|
18
|
+
{{else}}
|
19
|
+
import { useMutation, useQuery } from "@tanstack/react-query";
|
20
|
+
{{/if}}
|
21
|
+
|
22
|
+
import { Container } from "@/components/container";
|
23
|
+
{{#unless (eq backend "convex")}}
|
24
|
+
{{#if (eq api "orpc")}}
|
25
|
+
import { orpc } from "@/utils/orpc";
|
26
|
+
{{/if}}
|
27
|
+
{{#if (eq api "trpc")}}
|
28
|
+
import { trpc } from "@/utils/trpc";
|
29
|
+
{{/if}}
|
30
|
+
{{/unless}}
|
31
|
+
|
32
|
+
export default function TodosScreen() {
|
33
|
+
const [newTodoText, setNewTodoText] = useState("");
|
34
|
+
const { theme } = useUnistyles();
|
35
|
+
|
36
|
+
{{#if (eq backend "convex")}}
|
37
|
+
const todos = useQuery(api.todos.getAll);
|
38
|
+
const createTodoMutation = useMutation(api.todos.create);
|
39
|
+
const toggleTodoMutation = useMutation(api.todos.toggle);
|
40
|
+
const deleteTodoMutation = useMutation(api.todos.deleteTodo);
|
41
|
+
|
42
|
+
const handleAddTodo = async () => {
|
43
|
+
const text = newTodoText.trim();
|
44
|
+
if (!text) return;
|
45
|
+
await createTodoMutation({ text });
|
46
|
+
setNewTodoText("");
|
47
|
+
};
|
48
|
+
|
49
|
+
const handleToggleTodo = (id: Id<"todos">, currentCompleted: boolean) => {
|
50
|
+
toggleTodoMutation({ id, completed: !currentCompleted });
|
51
|
+
};
|
52
|
+
|
53
|
+
const handleDeleteTodo = (id: Id<"todos">) => {
|
54
|
+
Alert.alert("Delete Todo", "Are you sure you want to delete this todo?", [
|
55
|
+
{ text: "Cancel", style: "cancel" },
|
56
|
+
{
|
57
|
+
text: "Delete",
|
58
|
+
style: "destructive",
|
59
|
+
onPress: () => deleteTodoMutation({ id }),
|
60
|
+
},
|
61
|
+
]);
|
62
|
+
};
|
63
|
+
{{else}}
|
64
|
+
{{#if (eq api "orpc")}}
|
65
|
+
const todos = useQuery(orpc.todo.getAll.queryOptions());
|
66
|
+
const createMutation = useMutation(
|
67
|
+
orpc.todo.create.mutationOptions({
|
68
|
+
onSuccess: () => {
|
69
|
+
todos.refetch();
|
70
|
+
setNewTodoText("");
|
71
|
+
},
|
72
|
+
})
|
73
|
+
);
|
74
|
+
const toggleMutation = useMutation(
|
75
|
+
orpc.todo.toggle.mutationOptions({
|
76
|
+
onSuccess: () => { todos.refetch() },
|
77
|
+
})
|
78
|
+
);
|
79
|
+
const deleteMutation = useMutation(
|
80
|
+
orpc.todo.delete.mutationOptions({
|
81
|
+
onSuccess: () => { todos.refetch() },
|
82
|
+
})
|
83
|
+
);
|
84
|
+
{{/if}}
|
85
|
+
{{#if (eq api "trpc")}}
|
86
|
+
const todos = useQuery(trpc.todo.getAll.queryOptions());
|
87
|
+
const createMutation = useMutation(
|
88
|
+
trpc.todo.create.mutationOptions({
|
89
|
+
onSuccess: () => {
|
90
|
+
todos.refetch();
|
91
|
+
setNewTodoText("");
|
92
|
+
},
|
93
|
+
})
|
94
|
+
);
|
95
|
+
const toggleMutation = useMutation(
|
96
|
+
trpc.todo.toggle.mutationOptions({
|
97
|
+
onSuccess: () => { todos.refetch() },
|
98
|
+
})
|
99
|
+
);
|
100
|
+
const deleteMutation = useMutation(
|
101
|
+
trpc.todo.delete.mutationOptions({
|
102
|
+
onSuccess: () => { todos.refetch() },
|
103
|
+
})
|
104
|
+
);
|
105
|
+
{{/if}}
|
106
|
+
|
107
|
+
const handleAddTodo = () => {
|
108
|
+
if (newTodoText.trim()) {
|
109
|
+
createMutation.mutate({ text: newTodoText });
|
110
|
+
}
|
111
|
+
};
|
112
|
+
|
113
|
+
const handleToggleTodo = (id: number, completed: boolean) => {
|
114
|
+
toggleMutation.mutate({ id, completed: !completed });
|
115
|
+
};
|
116
|
+
|
117
|
+
const handleDeleteTodo = (id: number) => {
|
118
|
+
Alert.alert("Delete Todo", "Are you sure you want to delete this todo?", [
|
119
|
+
{ text: "Cancel", style: "cancel" },
|
120
|
+
{
|
121
|
+
text: "Delete",
|
122
|
+
style: "destructive",
|
123
|
+
onPress: () => deleteMutation.mutate({ id }),
|
124
|
+
},
|
125
|
+
]);
|
126
|
+
};
|
127
|
+
{{/if}}
|
128
|
+
|
129
|
+
const isLoading = {{#if (eq backend "convex")}}!todos{{else}}todos.isLoading{{/if}};
|
130
|
+
const isCreating = {{#if (eq backend "convex")}}false{{else}}createMutation.isPending{{/if}};
|
131
|
+
const primaryButtonTextColor = theme.colors.background;
|
132
|
+
|
133
|
+
return (
|
134
|
+
<Container>
|
135
|
+
<ScrollView style={styles.scrollView}>
|
136
|
+
<View style={styles.headerContainer}>
|
137
|
+
<Text style={styles.headerTitle}>Todo List</Text>
|
138
|
+
<Text style={styles.headerSubtitle}>
|
139
|
+
Manage your tasks efficiently
|
140
|
+
</Text>
|
141
|
+
|
142
|
+
<View style={styles.inputContainer}>
|
143
|
+
<TextInput
|
144
|
+
value={newTodoText}
|
145
|
+
onChangeText={setNewTodoText}
|
146
|
+
placeholder="Add a new task..."
|
147
|
+
placeholderTextColor={theme.colors.border}
|
148
|
+
editable={!isCreating}
|
149
|
+
style={styles.textInput}
|
150
|
+
onSubmitEditing={handleAddTodo}
|
151
|
+
returnKeyType="done"
|
152
|
+
/>
|
153
|
+
<TouchableOpacity
|
154
|
+
onPress={handleAddTodo}
|
155
|
+
disabled={isCreating || !newTodoText.trim()}
|
156
|
+
style={[
|
157
|
+
styles.addButton,
|
158
|
+
(isCreating || !newTodoText.trim()) && styles.addButtonDisabled,
|
159
|
+
]}
|
160
|
+
>
|
161
|
+
{isCreating ? (
|
162
|
+
<ActivityIndicator size="small" color={primaryButtonTextColor} />
|
163
|
+
) : (
|
164
|
+
<Ionicons
|
165
|
+
name="add"
|
166
|
+
size={24}
|
167
|
+
color={primaryButtonTextColor}
|
168
|
+
/>
|
169
|
+
)}
|
170
|
+
</TouchableOpacity>
|
171
|
+
</View>
|
172
|
+
</View>
|
173
|
+
|
174
|
+
{isLoading && (
|
175
|
+
<View style={styles.loadingContainer}>
|
176
|
+
<ActivityIndicator size="large" color={theme.colors.primary} />
|
177
|
+
<Text style={styles.loadingText}>Loading todos...</Text>
|
178
|
+
</View>
|
179
|
+
)}
|
180
|
+
|
181
|
+
{{#if (eq backend "convex")}}
|
182
|
+
{todos && todos.length === 0 && !isLoading && (
|
183
|
+
<Text style={styles.emptyText}>No todos yet. Add one!</Text>
|
184
|
+
)}
|
185
|
+
{todos?.map((todo) => (
|
186
|
+
<View key={todo._id} style={styles.todoItem}>
|
187
|
+
<TouchableOpacity
|
188
|
+
onPress={() => handleToggleTodo(todo._id, todo.completed)}
|
189
|
+
style={styles.todoContent}
|
190
|
+
>
|
191
|
+
<Ionicons
|
192
|
+
name={todo.completed ? "checkbox" : "square-outline"}
|
193
|
+
size={24}
|
194
|
+
color={todo.completed ? theme.colors.primary : theme.colors.typography}
|
195
|
+
style={styles.checkbox}
|
196
|
+
/>
|
197
|
+
<Text
|
198
|
+
style={[
|
199
|
+
styles.todoText,
|
200
|
+
todo.completed && styles.todoTextCompleted,
|
201
|
+
]}
|
202
|
+
>
|
203
|
+
{todo.text}
|
204
|
+
</Text>
|
205
|
+
</TouchableOpacity>
|
206
|
+
<TouchableOpacity onPress={() => handleDeleteTodo(todo._id)}>
|
207
|
+
<Ionicons name="trash-outline" size={24} color={theme.colors.destructive} />
|
208
|
+
</TouchableOpacity>
|
209
|
+
</View>
|
210
|
+
))}
|
211
|
+
{{else}}
|
212
|
+
{todos.data && todos.data.length === 0 && !isLoading && (
|
213
|
+
<Text style={styles.emptyText}>No todos yet. Add one!</Text>
|
214
|
+
)}
|
215
|
+
{todos.data?.map((todo: { id: number; text: string; completed: boolean }) => (
|
216
|
+
<View key={todo.id} style={styles.todoItem}>
|
217
|
+
<TouchableOpacity
|
218
|
+
onPress={() => handleToggleTodo(todo.id, todo.completed)}
|
219
|
+
style={styles.todoContent}
|
220
|
+
>
|
221
|
+
<Ionicons
|
222
|
+
name={todo.completed ? "checkbox" : "square-outline"}
|
223
|
+
size={24}
|
224
|
+
color={todo.completed ? theme.colors.primary : theme.colors.typography}
|
225
|
+
style={styles.checkbox}
|
226
|
+
/>
|
227
|
+
<Text
|
228
|
+
style={[
|
229
|
+
styles.todoText,
|
230
|
+
todo.completed && styles.todoTextCompleted,
|
231
|
+
]}
|
232
|
+
>
|
233
|
+
{todo.text}
|
234
|
+
</Text>
|
235
|
+
</TouchableOpacity>
|
236
|
+
<TouchableOpacity onPress={() => handleDeleteTodo(todo.id)}>
|
237
|
+
<Ionicons name="trash-outline" size={24} color={theme.colors.destructive} />
|
238
|
+
</TouchableOpacity>
|
239
|
+
</View>
|
240
|
+
))}
|
241
|
+
{{/if}}
|
242
|
+
</ScrollView>
|
243
|
+
</Container>
|
244
|
+
);
|
245
|
+
}
|
246
|
+
|
247
|
+
const styles = StyleSheet.create((theme) => ({
|
248
|
+
scrollView: {
|
249
|
+
flex: 1,
|
250
|
+
},
|
251
|
+
headerContainer: {
|
252
|
+
paddingHorizontal: theme.spacing.md,
|
253
|
+
paddingVertical: theme.spacing.lg,
|
254
|
+
borderBottomWidth: 1,
|
255
|
+
borderBottomColor: theme.colors.border,
|
256
|
+
backgroundColor: theme.colors.background,
|
257
|
+
},
|
258
|
+
headerTitle: {
|
259
|
+
fontSize: 28,
|
260
|
+
fontWeight: "bold",
|
261
|
+
color: theme.colors.typography,
|
262
|
+
marginBottom: theme.spacing.sm,
|
263
|
+
},
|
264
|
+
headerSubtitle: {
|
265
|
+
fontSize: 16,
|
266
|
+
color: theme.colors.typography,
|
267
|
+
marginBottom: theme.spacing.md,
|
268
|
+
},
|
269
|
+
inputContainer: {
|
270
|
+
flexDirection: "row",
|
271
|
+
alignItems: "center",
|
272
|
+
marginBottom: theme.spacing.md,
|
273
|
+
},
|
274
|
+
textInput: {
|
275
|
+
flex: 1,
|
276
|
+
borderWidth: 1,
|
277
|
+
borderColor: theme.colors.border,
|
278
|
+
borderRadius: 8,
|
279
|
+
paddingHorizontal: theme.spacing.md,
|
280
|
+
paddingVertical: theme.spacing.sm,
|
281
|
+
color: theme.colors.typography,
|
282
|
+
backgroundColor: theme.colors.background,
|
283
|
+
marginRight: theme.spacing.sm,
|
284
|
+
fontSize: 16,
|
285
|
+
},
|
286
|
+
addButton: {
|
287
|
+
backgroundColor: theme.colors.primary,
|
288
|
+
padding: theme.spacing.sm,
|
289
|
+
borderRadius: 8,
|
290
|
+
justifyContent: "center",
|
291
|
+
alignItems: "center",
|
292
|
+
},
|
293
|
+
addButtonDisabled: {
|
294
|
+
backgroundColor: theme.colors.border,
|
295
|
+
},
|
296
|
+
loadingContainer: {
|
297
|
+
flex: 1,
|
298
|
+
justifyContent: "center",
|
299
|
+
alignItems: "center",
|
300
|
+
padding: theme.spacing.lg,
|
301
|
+
},
|
302
|
+
loadingText: {
|
303
|
+
marginTop: theme.spacing.sm,
|
304
|
+
fontSize: 16,
|
305
|
+
color: theme.colors.typography,
|
306
|
+
},
|
307
|
+
emptyText: {
|
308
|
+
textAlign: "center",
|
309
|
+
marginTop: theme.spacing.xl,
|
310
|
+
fontSize: 16,
|
311
|
+
color: theme.colors.typography,
|
312
|
+
},
|
313
|
+
todoItem: {
|
314
|
+
flexDirection: "row",
|
315
|
+
justifyContent: "space-between",
|
316
|
+
alignItems: "center",
|
317
|
+
paddingVertical: theme.spacing.md,
|
318
|
+
paddingHorizontal: theme.spacing.md,
|
319
|
+
borderBottomWidth: 1,
|
320
|
+
borderBottomColor: theme.colors.border,
|
321
|
+
backgroundColor: theme.colors.background,
|
322
|
+
},
|
323
|
+
todoContent: {
|
324
|
+
flexDirection: "row",
|
325
|
+
alignItems: "center",
|
326
|
+
flex: 1,
|
327
|
+
},
|
328
|
+
checkbox: {
|
329
|
+
marginRight: theme.spacing.md,
|
330
|
+
},
|
331
|
+
todoText: {
|
332
|
+
fontSize: 16,
|
333
|
+
color: theme.colors.typography,
|
334
|
+
flex: 1,
|
335
|
+
},
|
336
|
+
todoTextCompleted: {
|
337
|
+
textDecorationLine: "line-through",
|
338
|
+
color: theme.colors.border,
|
339
|
+
},
|
340
|
+
}));
|
@@ -0,0 +1,79 @@
|
|
1
|
+
{{#if (eq api "orpc")}}
|
2
|
+
import { eq } from "drizzle-orm";
|
3
|
+
import z from "zod/v4";
|
4
|
+
import { db } from "../db";
|
5
|
+
import { todo } from "../db/schema/todo";
|
6
|
+
import { publicProcedure } from "../lib/orpc";
|
7
|
+
|
8
|
+
export const todoRouter = {
|
9
|
+
getAll: publicProcedure.handler(async () => {
|
10
|
+
return await db.select().from(todo);
|
11
|
+
}),
|
12
|
+
|
13
|
+
create: publicProcedure
|
14
|
+
.input(z.object({ text: z.string().min(1) }))
|
15
|
+
.handler(async ({ input }) => {
|
16
|
+
const result = await db
|
17
|
+
.insert(todo)
|
18
|
+
.values({
|
19
|
+
text: input.text,
|
20
|
+
})
|
21
|
+
.returning();
|
22
|
+
return result[0];
|
23
|
+
}),
|
24
|
+
|
25
|
+
toggle: publicProcedure
|
26
|
+
.input(z.object({ id: z.number(), completed: z.boolean() }))
|
27
|
+
.handler(async ({ input }) => {
|
28
|
+
await db
|
29
|
+
.update(todo)
|
30
|
+
.set({ completed: input.completed })
|
31
|
+
.where(eq(todo.id, input.id));
|
32
|
+
return { success: true };
|
33
|
+
}),
|
34
|
+
|
35
|
+
delete: publicProcedure
|
36
|
+
.input(z.object({ id: z.number() }))
|
37
|
+
.handler(async ({ input }) => {
|
38
|
+
await db.delete(todo).where(eq(todo.id, input.id));
|
39
|
+
return { success: true };
|
40
|
+
}),
|
41
|
+
};
|
42
|
+
{{/if}}
|
43
|
+
|
44
|
+
{{#if (eq api "trpc")}}
|
45
|
+
import z from "zod/v4";
|
46
|
+
import { router, publicProcedure } from "../lib/trpc";
|
47
|
+
import { todo } from "../db/schema/todo";
|
48
|
+
import { eq } from "drizzle-orm";
|
49
|
+
import { db } from "../db";
|
50
|
+
|
51
|
+
export const todoRouter = router({
|
52
|
+
getAll: publicProcedure.query(async () => {
|
53
|
+
return await db.select().from(todo);
|
54
|
+
}),
|
55
|
+
|
56
|
+
create: publicProcedure
|
57
|
+
.input(z.object({ text: z.string().min(1) }))
|
58
|
+
.mutation(async ({ input }) => {
|
59
|
+
return await db.insert(todo).values({
|
60
|
+
text: input.text,
|
61
|
+
});
|
62
|
+
}),
|
63
|
+
|
64
|
+
toggle: publicProcedure
|
65
|
+
.input(z.object({ id: z.number(), completed: z.boolean() }))
|
66
|
+
.mutation(async ({ input }) => {
|
67
|
+
return await db
|
68
|
+
.update(todo)
|
69
|
+
.set({ completed: input.completed })
|
70
|
+
.where(eq(todo.id, input.id));
|
71
|
+
}),
|
72
|
+
|
73
|
+
delete: publicProcedure
|
74
|
+
.input(z.object({ id: z.number() }))
|
75
|
+
.mutation(async ({ input }) => {
|
76
|
+
return await db.delete(todo).where(eq(todo.id, input.id));
|
77
|
+
}),
|
78
|
+
});
|
79
|
+
{{/if}}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { mysqlTable, varchar, int, boolean } from "drizzle-orm/mysql-core";
|
2
|
+
|
3
|
+
export const todo = mysqlTable("todo", {
|
4
|
+
id: int("id").primaryKey().autoincrement(),
|
5
|
+
text: varchar("text", { length: 255 }).notNull(),
|
6
|
+
completed: boolean("completed").default(false).notNull(),
|
7
|
+
});
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
|
2
|
+
|
3
|
+
export const todo = sqliteTable("todo", {
|
4
|
+
id: integer("id").primaryKey({ autoIncrement: true }),
|
5
|
+
text: text("text").notNull(),
|
6
|
+
completed: integer("completed", { mode: "boolean" }).default(false).notNull(),
|
7
|
+
});
|
@@ -0,0 +1,66 @@
|
|
1
|
+
{{#if (eq api "orpc")}}
|
2
|
+
import z from "zod/v4";
|
3
|
+
import { publicProcedure } from "../lib/orpc";
|
4
|
+
import { Todo } from "../db/models/todo.model";
|
5
|
+
|
6
|
+
export const todoRouter = {
|
7
|
+
getAll: publicProcedure.handler(async () => {
|
8
|
+
return await Todo.find().lean();
|
9
|
+
}),
|
10
|
+
|
11
|
+
create: publicProcedure
|
12
|
+
.input(z.object({ text: z.string().min(1) }))
|
13
|
+
.handler(async ({ input }) => {
|
14
|
+
const newTodo = await Todo.create({ text: input.text });
|
15
|
+
return newTodo.toObject();
|
16
|
+
}),
|
17
|
+
|
18
|
+
toggle: publicProcedure
|
19
|
+
.input(z.object({ id: z.string(), completed: z.boolean() }))
|
20
|
+
.handler(async ({ input }) => {
|
21
|
+
await Todo.updateOne({ id: input.id }, { completed: input.completed });
|
22
|
+
return { success: true };
|
23
|
+
}),
|
24
|
+
|
25
|
+
delete: publicProcedure
|
26
|
+
.input(z.object({ id: z.string() }))
|
27
|
+
.handler(async ({ input }) => {
|
28
|
+
await Todo.deleteOne({ id: input.id });
|
29
|
+
return { success: true };
|
30
|
+
}),
|
31
|
+
};
|
32
|
+
|
33
|
+
{{/if}}
|
34
|
+
|
35
|
+
{{#if (eq api "trpc")}}
|
36
|
+
import z from "zod/v4";
|
37
|
+
import { router, publicProcedure } from "../lib/trpc";
|
38
|
+
import { Todo } from "../db/models/todo.model";
|
39
|
+
|
40
|
+
export const todoRouter = router({
|
41
|
+
getAll: publicProcedure.query(async () => {
|
42
|
+
return await Todo.find().lean();
|
43
|
+
}),
|
44
|
+
|
45
|
+
create: publicProcedure
|
46
|
+
.input(z.object({ text: z.string().min(1) }))
|
47
|
+
.mutation(async ({ input }) => {
|
48
|
+
const newTodo = await Todo.create({ text: input.text });
|
49
|
+
return newTodo.toObject();
|
50
|
+
}),
|
51
|
+
|
52
|
+
toggle: publicProcedure
|
53
|
+
.input(z.object({ id: z.string(), completed: z.boolean() }))
|
54
|
+
.mutation(async ({ input }) => {
|
55
|
+
await Todo.updateOne({ id: input.id }, { completed: input.completed });
|
56
|
+
return { success: true };
|
57
|
+
}),
|
58
|
+
|
59
|
+
delete: publicProcedure
|
60
|
+
.input(z.object({ id: z.string() }))
|
61
|
+
.mutation(async ({ input }) => {
|
62
|
+
await Todo.deleteOne({ id: input.id });
|
63
|
+
return { success: true };
|
64
|
+
}),
|
65
|
+
});
|
66
|
+
{{/if}}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import mongoose from 'mongoose';
|
2
|
+
|
3
|
+
const { Schema, model } = mongoose;
|
4
|
+
|
5
|
+
const todoSchema = new Schema({
|
6
|
+
id: {
|
7
|
+
type: mongoose.Schema.Types.ObjectId,
|
8
|
+
auto: true,
|
9
|
+
},
|
10
|
+
text: {
|
11
|
+
type: String,
|
12
|
+
required: true,
|
13
|
+
},
|
14
|
+
completed: {
|
15
|
+
type: Boolean,
|
16
|
+
default: false,
|
17
|
+
},
|
18
|
+
}, {
|
19
|
+
collection: 'todo'
|
20
|
+
});
|
21
|
+
|
22
|
+
const Todo = model('Todo', todoSchema);
|
23
|
+
|
24
|
+
export { Todo };
|
@@ -0,0 +1,118 @@
|
|
1
|
+
{{#if (eq api "orpc")}}
|
2
|
+
import z from "zod/v4";
|
3
|
+
import prisma from "../../prisma";
|
4
|
+
import { publicProcedure } from "../lib/orpc";
|
5
|
+
|
6
|
+
export const todoRouter = {
|
7
|
+
getAll: publicProcedure.handler(async () => {
|
8
|
+
return await prisma.todo.findMany({
|
9
|
+
orderBy: {
|
10
|
+
id: "asc",
|
11
|
+
},
|
12
|
+
});
|
13
|
+
}),
|
14
|
+
|
15
|
+
create: publicProcedure
|
16
|
+
.input(z.object({ text: z.string().min(1) }))
|
17
|
+
.handler(async ({ input }) => {
|
18
|
+
return await prisma.todo.create({
|
19
|
+
data: {
|
20
|
+
text: input.text,
|
21
|
+
},
|
22
|
+
});
|
23
|
+
}),
|
24
|
+
|
25
|
+
toggle: publicProcedure
|
26
|
+
{{#if (eq database "mongodb")}}
|
27
|
+
.input(z.object({ id: z.string(), completed: z.boolean() }))
|
28
|
+
{{else}}
|
29
|
+
.input(z.object({ id: z.number(), completed: z.boolean() }))
|
30
|
+
{{/if}}
|
31
|
+
.handler(async ({ input }) => {
|
32
|
+
await prisma.todo.update({
|
33
|
+
where: { id: input.id },
|
34
|
+
data: { completed: input.completed },
|
35
|
+
});
|
36
|
+
return { success: true };
|
37
|
+
}),
|
38
|
+
|
39
|
+
delete: publicProcedure
|
40
|
+
{{#if (eq database "mongodb")}}
|
41
|
+
.input(z.object({ id: z.string() }))
|
42
|
+
{{else}}
|
43
|
+
.input(z.object({ id: z.number() }))
|
44
|
+
{{/if}}
|
45
|
+
.handler(async ({ input }) => {
|
46
|
+
await prisma.todo.delete({
|
47
|
+
where: { id: input.id },
|
48
|
+
});
|
49
|
+
return { success: true };
|
50
|
+
}),
|
51
|
+
};
|
52
|
+
{{/if}}
|
53
|
+
|
54
|
+
{{#if (eq api "trpc")}}
|
55
|
+
import { TRPCError } from "@trpc/server";
|
56
|
+
import z from "zod/v4";
|
57
|
+
import prisma from "../../prisma";
|
58
|
+
import { publicProcedure, router } from "../lib/trpc";
|
59
|
+
|
60
|
+
export const todoRouter = router({
|
61
|
+
getAll: publicProcedure.query(async () => {
|
62
|
+
return await prisma.todo.findMany({
|
63
|
+
orderBy: {
|
64
|
+
id: "asc"
|
65
|
+
}
|
66
|
+
});
|
67
|
+
}),
|
68
|
+
|
69
|
+
create: publicProcedure
|
70
|
+
.input(z.object({ text: z.string().min(1) }))
|
71
|
+
.mutation(async ({ input }) => {
|
72
|
+
return await prisma.todo.create({
|
73
|
+
data: {
|
74
|
+
text: input.text,
|
75
|
+
},
|
76
|
+
});
|
77
|
+
}),
|
78
|
+
|
79
|
+
toggle: publicProcedure
|
80
|
+
{{#if (eq database "mongodb")}}
|
81
|
+
.input(z.object({ id: z.string(), completed: z.boolean() }))
|
82
|
+
{{else}}
|
83
|
+
.input(z.object({ id: z.number(), completed: z.boolean() }))
|
84
|
+
{{/if}}
|
85
|
+
.mutation(async ({ input }) => {
|
86
|
+
try {
|
87
|
+
return await prisma.todo.update({
|
88
|
+
where: { id: input.id },
|
89
|
+
data: { completed: input.completed },
|
90
|
+
});
|
91
|
+
} catch (error) {
|
92
|
+
throw new TRPCError({
|
93
|
+
code: "NOT_FOUND",
|
94
|
+
message: "Todo not found",
|
95
|
+
});
|
96
|
+
}
|
97
|
+
}),
|
98
|
+
|
99
|
+
delete: publicProcedure
|
100
|
+
{{#if (eq database "mongodb")}}
|
101
|
+
.input(z.object({ id: z.string() }))
|
102
|
+
{{else}}
|
103
|
+
.input(z.object({ id: z.number() }))
|
104
|
+
{{/if}}
|
105
|
+
.mutation(async ({ input }) => {
|
106
|
+
try {
|
107
|
+
return await prisma.todo.delete({
|
108
|
+
where: { id: input.id },
|
109
|
+
});
|
110
|
+
} catch (error) {
|
111
|
+
throw new TRPCError({
|
112
|
+
code: "NOT_FOUND",
|
113
|
+
message: "Todo not found",
|
114
|
+
});
|
115
|
+
}
|
116
|
+
}),
|
117
|
+
});
|
118
|
+
{{/if}}
|