@proofkit/cli 1.0.0-beta.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/CHANGELOG.md +120 -0
- package/LICENSE.md +21 -0
- package/README.md +19 -0
- package/dist/acorn-AKFTBDM6.js +15 -0
- package/dist/angular-BOQ6FHSU.js +2 -0
- package/dist/babel-ZTOORN7K.js +15 -0
- package/dist/chunk-4LISTI44.js +1 -0
- package/dist/estree-KOJPX4S6.js +36 -0
- package/dist/flow-RCI44GYZ.js +19 -0
- package/dist/glimmer-GV5EF5E4.js +30 -0
- package/dist/graphql-YXQNPQWM.js +29 -0
- package/dist/html-ZAJTRROK.js +22 -0
- package/dist/index.js +300 -0
- package/dist/markdown-Q75DTQI7.js +63 -0
- package/dist/meriyah-32K7GBV5.js +4 -0
- package/dist/postcss-WWYO4PGL.js +54 -0
- package/dist/typescript-M6N7JDNQ.js +20 -0
- package/dist/yaml-LY7PNAYV.js +161 -0
- package/index.d.ts +19 -0
- package/package.json +122 -0
- package/template/extras/_cursor/conditional-rules/nextjs-framework.mdc +51 -0
- package/template/extras/_cursor/conditional-rules/npm.mdc +60 -0
- package/template/extras/_cursor/conditional-rules/pnpm.mdc +65 -0
- package/template/extras/_cursor/conditional-rules/yarn.mdc +60 -0
- package/template/extras/_cursor/rules/cursor-rules.mdc +88 -0
- package/template/extras/_cursor/rules/filemaker-api.mdc +176 -0
- package/template/extras/_cursor/rules/troubleshooting-patterns.mdc +240 -0
- package/template/extras/_cursor/rules/ui-components.mdc +57 -0
- package/template/extras/config/_eslint.js +27 -0
- package/template/extras/config/_prettier.config.js +6 -0
- package/template/extras/config/drizzle-config-mysql.ts +12 -0
- package/template/extras/config/drizzle-config-postgres.ts +12 -0
- package/template/extras/config/drizzle-config-sqlite.ts +12 -0
- package/template/extras/config/fmschema.config.mjs +9 -0
- package/template/extras/config/get-query-client.ts +6 -0
- package/template/extras/config/postcss.config.cjs +7 -0
- package/template/extras/config/query-provider-vite.tsx +19 -0
- package/template/extras/config/query-provider.tsx +21 -0
- package/template/extras/emailProviders/none/email.tsx +24 -0
- package/template/extras/emailProviders/plunk/email.tsx +26 -0
- package/template/extras/emailProviders/plunk/service.ts +4 -0
- package/template/extras/emailProviders/resend/email.tsx +23 -0
- package/template/extras/emailProviders/resend/service.ts +4 -0
- package/template/extras/fmaddon-auth/app/(main)/auth/profile/actions.ts +93 -0
- package/template/extras/fmaddon-auth/app/(main)/auth/profile/page.tsx +27 -0
- package/template/extras/fmaddon-auth/app/(main)/auth/profile/profile-form.tsx +56 -0
- package/template/extras/fmaddon-auth/app/(main)/auth/profile/reset-password-form.tsx +110 -0
- package/template/extras/fmaddon-auth/app/(main)/auth/profile/schema.ts +19 -0
- package/template/extras/fmaddon-auth/app/auth/forgot-password/actions.ts +37 -0
- package/template/extras/fmaddon-auth/app/auth/forgot-password/forgot-form.tsx +41 -0
- package/template/extras/fmaddon-auth/app/auth/forgot-password/page.tsx +21 -0
- package/template/extras/fmaddon-auth/app/auth/forgot-password/schema.ts +5 -0
- package/template/extras/fmaddon-auth/app/auth/login/actions.ts +34 -0
- package/template/extras/fmaddon-auth/app/auth/login/login-form.tsx +64 -0
- package/template/extras/fmaddon-auth/app/auth/login/page.tsx +26 -0
- package/template/extras/fmaddon-auth/app/auth/login/schema.ts +6 -0
- package/template/extras/fmaddon-auth/app/auth/reset-password/actions.ts +50 -0
- package/template/extras/fmaddon-auth/app/auth/reset-password/page.tsx +32 -0
- package/template/extras/fmaddon-auth/app/auth/reset-password/reset-password-form.tsx +59 -0
- package/template/extras/fmaddon-auth/app/auth/reset-password/schema.ts +14 -0
- package/template/extras/fmaddon-auth/app/auth/reset-password/verify-email/actions.ts +45 -0
- package/template/extras/fmaddon-auth/app/auth/reset-password/verify-email/page.tsx +32 -0
- package/template/extras/fmaddon-auth/app/auth/reset-password/verify-email/schema.ts +5 -0
- package/template/extras/fmaddon-auth/app/auth/reset-password/verify-email/verify-email-form.tsx +48 -0
- package/template/extras/fmaddon-auth/app/auth/signup/actions.ts +49 -0
- package/template/extras/fmaddon-auth/app/auth/signup/page.tsx +26 -0
- package/template/extras/fmaddon-auth/app/auth/signup/schema.ts +12 -0
- package/template/extras/fmaddon-auth/app/auth/signup/signup-form.tsx +67 -0
- package/template/extras/fmaddon-auth/app/auth/verify-email/actions.ts +110 -0
- package/template/extras/fmaddon-auth/app/auth/verify-email/email-verification-form.tsx +45 -0
- package/template/extras/fmaddon-auth/app/auth/verify-email/page.tsx +38 -0
- package/template/extras/fmaddon-auth/app/auth/verify-email/resend-button.tsx +35 -0
- package/template/extras/fmaddon-auth/app/auth/verify-email/schema.ts +5 -0
- package/template/extras/fmaddon-auth/components/auth/actions.ts +16 -0
- package/template/extras/fmaddon-auth/components/auth/protect.tsx +17 -0
- package/template/extras/fmaddon-auth/components/auth/redirect.tsx +26 -0
- package/template/extras/fmaddon-auth/components/auth/use-user.ts +59 -0
- package/template/extras/fmaddon-auth/components/auth/user-menu.tsx +51 -0
- package/template/extras/fmaddon-auth/emails/auth-code.tsx +156 -0
- package/template/extras/fmaddon-auth/middleware.ts +45 -0
- package/template/extras/fmaddon-auth/server/auth/utils/email-verification.ts +136 -0
- package/template/extras/fmaddon-auth/server/auth/utils/encryption.ts +51 -0
- package/template/extras/fmaddon-auth/server/auth/utils/index.ts +16 -0
- package/template/extras/fmaddon-auth/server/auth/utils/password-reset.ts +152 -0
- package/template/extras/fmaddon-auth/server/auth/utils/password.ts +67 -0
- package/template/extras/fmaddon-auth/server/auth/utils/redirect.ts +8 -0
- package/template/extras/fmaddon-auth/server/auth/utils/session.ts +192 -0
- package/template/extras/fmaddon-auth/server/auth/utils/user.ts +147 -0
- package/template/extras/prisma/schema/base-planetscale.prisma +24 -0
- package/template/extras/prisma/schema/base.prisma +20 -0
- package/template/extras/prisma/schema/with-auth-planetscale.prisma +77 -0
- package/template/extras/prisma/schema/with-auth.prisma +74 -0
- package/template/extras/src/app/_components/post-tw.tsx +50 -0
- package/template/extras/src/app/_components/post.tsx +54 -0
- package/template/extras/src/app/api/auth/[...nextauth]/route.ts +4 -0
- package/template/extras/src/app/api/trpc/[trpc]/route.ts +34 -0
- package/template/extras/src/app/clerk-auth/layout.tsx +10 -0
- package/template/extras/src/app/clerk-auth/signin/[[...sign-in]]/page.tsx +5 -0
- package/template/extras/src/app/clerk-auth/signup/[[...sign-up]]/page.tsx +5 -0
- package/template/extras/src/app/layout/base.tsx +34 -0
- package/template/extras/src/app/layout/main-shell.tsx +37 -0
- package/template/extras/src/app/layout/with-trpc-tw.tsx +24 -0
- package/template/extras/src/app/layout/with-trpc.tsx +24 -0
- package/template/extras/src/app/layout/with-tw.tsx +20 -0
- package/template/extras/src/app/next-auth/layout.tsx +22 -0
- package/template/extras/src/app/next-auth/signin/page.tsx +82 -0
- package/template/extras/src/app/next-auth/signup/action.ts +24 -0
- package/template/extras/src/app/next-auth/signup/page.tsx +40 -0
- package/template/extras/src/app/next-auth/signup/validation.ts +12 -0
- package/template/extras/src/app/page/base.tsx +6 -0
- package/template/extras/src/app/page/with-auth-trpc-tw.tsx +67 -0
- package/template/extras/src/app/page/with-auth-trpc.tsx +68 -0
- package/template/extras/src/app/page/with-trpc-tw.tsx +53 -0
- package/template/extras/src/app/page/with-trpc.tsx +54 -0
- package/template/extras/src/app/page/with-tw.tsx +37 -0
- package/template/extras/src/components/clerk-auth/clerk-provider.tsx +18 -0
- package/template/extras/src/components/clerk-auth/user-menu-mobile.tsx +36 -0
- package/template/extras/src/components/clerk-auth/user-menu.tsx +24 -0
- package/template/extras/src/components/next-auth/next-auth-provider.tsx +14 -0
- package/template/extras/src/components/next-auth/user-menu-mobile.tsx +31 -0
- package/template/extras/src/components/next-auth/user-menu.tsx +38 -0
- package/template/extras/src/env/with-auth.ts +31 -0
- package/template/extras/src/env/with-clerk.ts +20 -0
- package/template/extras/src/index.module.css +177 -0
- package/template/extras/src/middleware/clerk.ts +20 -0
- package/template/extras/src/middleware/next-auth.ts +5 -0
- package/template/extras/src/pages/_app/base.tsx +14 -0
- package/template/extras/src/pages/_app/with-auth-trpc-tw.tsx +23 -0
- package/template/extras/src/pages/_app/with-auth-trpc.tsx +23 -0
- package/template/extras/src/pages/_app/with-auth-tw.tsx +21 -0
- package/template/extras/src/pages/_app/with-auth.tsx +21 -0
- package/template/extras/src/pages/_app/with-trpc-tw.tsx +16 -0
- package/template/extras/src/pages/_app/with-trpc.tsx +16 -0
- package/template/extras/src/pages/_app/with-tw.tsx +14 -0
- package/template/extras/src/pages/api/auth/[...nextauth].ts +5 -0
- package/template/extras/src/pages/api/trpc/[trpc].ts +19 -0
- package/template/extras/src/pages/index/base.tsx +47 -0
- package/template/extras/src/pages/index/with-auth-trpc-tw.tsx +80 -0
- package/template/extras/src/pages/index/with-auth-trpc.tsx +81 -0
- package/template/extras/src/pages/index/with-trpc-tw.tsx +52 -0
- package/template/extras/src/pages/index/with-trpc.tsx +53 -0
- package/template/extras/src/pages/index/with-tw.tsx +45 -0
- package/template/extras/src/server/api/root.ts +23 -0
- package/template/extras/src/server/api/routers/post/base.ts +40 -0
- package/template/extras/src/server/api/routers/post/with-auth-drizzle.ts +39 -0
- package/template/extras/src/server/api/routers/post/with-auth-prisma.ts +41 -0
- package/template/extras/src/server/api/routers/post/with-auth.ts +37 -0
- package/template/extras/src/server/api/routers/post/with-drizzle.ts +30 -0
- package/template/extras/src/server/api/routers/post/with-prisma.ts +31 -0
- package/template/extras/src/server/api/trpc-app/base.ts +103 -0
- package/template/extras/src/server/api/trpc-app/with-auth-db.ts +133 -0
- package/template/extras/src/server/api/trpc-app/with-auth.ts +130 -0
- package/template/extras/src/server/api/trpc-app/with-db.ts +106 -0
- package/template/extras/src/server/api/trpc-pages/base.ts +122 -0
- package/template/extras/src/server/api/trpc-pages/with-auth-db.ts +160 -0
- package/template/extras/src/server/api/trpc-pages/with-auth.ts +158 -0
- package/template/extras/src/server/api/trpc-pages/with-db.ts +125 -0
- package/template/extras/src/server/data/users.ts +23 -0
- package/template/extras/src/server/db/db-prisma-planetscale.ts +22 -0
- package/template/extras/src/server/db/db-prisma.ts +17 -0
- package/template/extras/src/server/db/index-drizzle/with-mysql.ts +18 -0
- package/template/extras/src/server/db/index-drizzle/with-planetscale.ts +7 -0
- package/template/extras/src/server/db/index-drizzle/with-postgres.ts +18 -0
- package/template/extras/src/server/db/index-drizzle/with-sqlite.ts +19 -0
- package/template/extras/src/server/db/schema-drizzle/base-mysql.ts +34 -0
- package/template/extras/src/server/db/schema-drizzle/base-planetscale.ts +34 -0
- package/template/extras/src/server/db/schema-drizzle/base-postgres.ts +36 -0
- package/template/extras/src/server/db/schema-drizzle/base-sqlite.ts +30 -0
- package/template/extras/src/server/db/schema-drizzle/with-auth-mysql.ts +123 -0
- package/template/extras/src/server/db/schema-drizzle/with-auth-planetscale.ts +117 -0
- package/template/extras/src/server/db/schema-drizzle/with-auth-postgres.ts +130 -0
- package/template/extras/src/server/db/schema-drizzle/with-auth-sqlite.ts +116 -0
- package/template/extras/src/server/next-auth/base.ts +111 -0
- package/template/extras/src/server/next-auth/password.ts +13 -0
- package/template/extras/src/server/next-auth/with-drizzle.ts +83 -0
- package/template/extras/src/server/next-auth/with-prisma.ts +72 -0
- package/template/extras/src/trpc/query-client.ts +25 -0
- package/template/extras/src/trpc/react.tsx +76 -0
- package/template/extras/src/trpc/server.ts +30 -0
- package/template/extras/src/utils/api.ts +68 -0
- package/template/extras/start-database/mysql.sh +54 -0
- package/template/extras/start-database/postgres.sh +55 -0
- package/template/fm-addon/ProofKitAuth/de.xml +518 -0
- package/template/fm-addon/ProofKitAuth/en.xml +518 -0
- package/template/fm-addon/ProofKitAuth/es.xml +518 -0
- package/template/fm-addon/ProofKitAuth/fr.xml +518 -0
- package/template/fm-addon/ProofKitAuth/icon.png +0 -0
- package/template/fm-addon/ProofKitAuth/icon@2x.png +0 -0
- package/template/fm-addon/ProofKitAuth/info.json +11 -0
- package/template/fm-addon/ProofKitAuth/info_de.json +18 -0
- package/template/fm-addon/ProofKitAuth/info_en.json +8 -0
- package/template/fm-addon/ProofKitAuth/info_es.json +18 -0
- package/template/fm-addon/ProofKitAuth/info_fr.json +18 -0
- package/template/fm-addon/ProofKitAuth/info_it.json +18 -0
- package/template/fm-addon/ProofKitAuth/info_ja.json +18 -0
- package/template/fm-addon/ProofKitAuth/info_ko.json +18 -0
- package/template/fm-addon/ProofKitAuth/info_nl.json +18 -0
- package/template/fm-addon/ProofKitAuth/info_pt.json +18 -0
- package/template/fm-addon/ProofKitAuth/info_sv.json +18 -0
- package/template/fm-addon/ProofKitAuth/info_zh.json +18 -0
- package/template/fm-addon/ProofKitAuth/it.xml +518 -0
- package/template/fm-addon/ProofKitAuth/ja.xml +518 -0
- package/template/fm-addon/ProofKitAuth/ko.xml +518 -0
- package/template/fm-addon/ProofKitAuth/nl.xml +518 -0
- package/template/fm-addon/ProofKitAuth/preview.png +0 -0
- package/template/fm-addon/ProofKitAuth/pt.xml +518 -0
- package/template/fm-addon/ProofKitAuth/sv.xml +518 -0
- package/template/fm-addon/ProofKitAuth/template.xml +0 -0
- package/template/fm-addon/ProofKitAuth/zh.xml +518 -0
- package/template/fm-addon/ProofKitWV/de.xml +896 -0
- package/template/fm-addon/ProofKitWV/en.xml +896 -0
- package/template/fm-addon/ProofKitWV/es.xml +896 -0
- package/template/fm-addon/ProofKitWV/fr.xml +896 -0
- package/template/fm-addon/ProofKitWV/icon.png +0 -0
- package/template/fm-addon/ProofKitWV/icon@2x.png +0 -0
- package/template/fm-addon/ProofKitWV/info.json +11 -0
- package/template/fm-addon/ProofKitWV/info_de.json +18 -0
- package/template/fm-addon/ProofKitWV/info_en.json +11 -0
- package/template/fm-addon/ProofKitWV/info_es.json +18 -0
- package/template/fm-addon/ProofKitWV/info_fr.json +18 -0
- package/template/fm-addon/ProofKitWV/info_it.json +18 -0
- package/template/fm-addon/ProofKitWV/info_ja.json +18 -0
- package/template/fm-addon/ProofKitWV/info_ko.json +18 -0
- package/template/fm-addon/ProofKitWV/info_nl.json +18 -0
- package/template/fm-addon/ProofKitWV/info_pt.json +18 -0
- package/template/fm-addon/ProofKitWV/info_sv.json +18 -0
- package/template/fm-addon/ProofKitWV/info_zh.json +18 -0
- package/template/fm-addon/ProofKitWV/it.xml +896 -0
- package/template/fm-addon/ProofKitWV/ja.xml +896 -0
- package/template/fm-addon/ProofKitWV/ko.xml +896 -0
- package/template/fm-addon/ProofKitWV/nl.xml +896 -0
- package/template/fm-addon/ProofKitWV/preview.png +0 -0
- package/template/fm-addon/ProofKitWV/pt.xml +896 -0
- package/template/fm-addon/ProofKitWV/records_de.xml +0 -0
- package/template/fm-addon/ProofKitWV/records_en.xml +0 -0
- package/template/fm-addon/ProofKitWV/records_es.xml +0 -0
- package/template/fm-addon/ProofKitWV/records_fr.xml +0 -0
- package/template/fm-addon/ProofKitWV/records_it.xml +0 -0
- package/template/fm-addon/ProofKitWV/records_ja.xml +0 -0
- package/template/fm-addon/ProofKitWV/records_ko.xml +0 -0
- package/template/fm-addon/ProofKitWV/records_nl.xml +0 -0
- package/template/fm-addon/ProofKitWV/records_pt.xml +0 -0
- package/template/fm-addon/ProofKitWV/records_sv.xml +0 -0
- package/template/fm-addon/ProofKitWV/records_zh.xml +0 -0
- package/template/fm-addon/ProofKitWV/sv.xml +896 -0
- package/template/fm-addon/ProofKitWV/template.xml +0 -0
- package/template/fm-addon/ProofKitWV/zh.xml +896 -0
- package/template/nextjs/README.md +27 -0
- package/template/nextjs/_gitignore +37 -0
- package/template/nextjs/next.config.ts +12 -0
- package/template/nextjs/package.json +50 -0
- package/template/nextjs/postcss.config.cjs +14 -0
- package/template/nextjs/proofkit.json +1 -0
- package/template/nextjs/public/favicon.ico +0 -0
- package/template/nextjs/public/proofkit.png +0 -0
- package/template/nextjs/src/app/(main)/layout.tsx +6 -0
- package/template/nextjs/src/app/(main)/page.tsx +90 -0
- package/template/nextjs/src/app/layout.tsx +39 -0
- package/template/nextjs/src/app/navigation.tsx +12 -0
- package/template/nextjs/src/components/AppLogo.tsx +6 -0
- package/template/nextjs/src/components/AppShell/internal/AppShell.tsx +21 -0
- package/template/nextjs/src/components/AppShell/internal/Header.module.css +40 -0
- package/template/nextjs/src/components/AppShell/internal/Header.tsx +34 -0
- package/template/nextjs/src/components/AppShell/internal/HeaderMobileMenu.tsx +27 -0
- package/template/nextjs/src/components/AppShell/internal/HeaderNavLink.tsx +31 -0
- package/template/nextjs/src/components/AppShell/internal/config.ts +1 -0
- package/template/nextjs/src/components/AppShell/slot-header-center.tsx +13 -0
- package/template/nextjs/src/components/AppShell/slot-header-left.tsx +23 -0
- package/template/nextjs/src/components/AppShell/slot-header-mobile-content.tsx +43 -0
- package/template/nextjs/src/components/AppShell/slot-header-right.tsx +26 -0
- package/template/nextjs/src/config/env.ts +13 -0
- package/template/nextjs/src/config/theme/globals.css +1 -0
- package/template/nextjs/src/config/theme/mantine-theme.ts +22 -0
- package/template/nextjs/src/server/safe-action.ts +3 -0
- package/template/nextjs/src/utils/notification-helpers.ts +32 -0
- package/template/nextjs/tsconfig.json +40 -0
- package/template/pages/nextjs/blank/page.tsx +5 -0
- package/template/pages/nextjs/table/page.tsx +17 -0
- package/template/pages/nextjs/table/table.tsx +18 -0
- package/template/pages/nextjs/table-edit/actions.ts +23 -0
- package/template/pages/nextjs/table-edit/page.tsx +28 -0
- package/template/pages/nextjs/table-edit/schema.ts +4 -0
- package/template/pages/nextjs/table-edit/table.tsx +43 -0
- package/template/pages/nextjs/table-infinite/actions.ts +62 -0
- package/template/pages/nextjs/table-infinite/page.tsx +11 -0
- package/template/pages/nextjs/table-infinite/query.ts +44 -0
- package/template/pages/nextjs/table-infinite/table.tsx +107 -0
- package/template/pages/nextjs/table-infinite-edit/actions.ts +84 -0
- package/template/pages/nextjs/table-infinite-edit/page.tsx +23 -0
- package/template/pages/nextjs/table-infinite-edit/query.ts +81 -0
- package/template/pages/nextjs/table-infinite-edit/schema.ts +4 -0
- package/template/pages/nextjs/table-infinite-edit/table.tsx +130 -0
- package/template/pages/vite-wv/blank/index.tsx +0 -0
- package/template/pages/vite-wv/table/index.tsx +34 -0
- package/template/pages/vite-wv/table-edit/index.tsx +72 -0
- package/template/vite-wv/.vscode/settings.json +11 -0
- package/template/vite-wv/_gitignore +18 -0
- package/template/vite-wv/index.html +13 -0
- package/template/vite-wv/package.json +52 -0
- package/template/vite-wv/pnpm-lock.yaml +2294 -0
- package/template/vite-wv/postcss.config.cjs +14 -0
- package/template/vite-wv/proofkit.json +1 -0
- package/template/vite-wv/scripts/launch-fm.sh +3 -0
- package/template/vite-wv/scripts/upload.js +21 -0
- package/template/vite-wv/src/components/AppLogo.tsx +5 -0
- package/template/vite-wv/src/components/full-screen-loader.tsx +9 -0
- package/template/vite-wv/src/config/env.ts +16 -0
- package/template/vite-wv/src/config/theme/globals.css +1 -0
- package/template/vite-wv/src/config/theme/mantine-theme.ts +22 -0
- package/template/vite-wv/src/main.tsx +42 -0
- package/template/vite-wv/src/routeTree.gen.ts +111 -0
- package/template/vite-wv/src/routes/__root.tsx +21 -0
- package/template/vite-wv/src/routes/index.tsx +63 -0
- package/template/vite-wv/src/routes/secondary.tsx +28 -0
- package/template/vite-wv/src/utils/notification-helpers.ts +32 -0
- package/template/vite-wv/tsconfig.json +14 -0
- package/template/vite-wv/vite.config.ts +18 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* YOU PROBABLY DON'T NEED TO EDIT THIS FILE, UNLESS:
|
|
3
|
+
* 1. You want to modify request context (see Part 1).
|
|
4
|
+
* 2. You want to create a new middleware or type of procedure (see Part 3).
|
|
5
|
+
*
|
|
6
|
+
* TL;DR - This is where all the tRPC server stuff is created and plugged in. The pieces you will
|
|
7
|
+
* need to use are documented accordingly near the end.
|
|
8
|
+
*/
|
|
9
|
+
import { initTRPC, TRPCError } from "@trpc/server";
|
|
10
|
+
import { type CreateNextContextOptions } from "@trpc/server/adapters/next";
|
|
11
|
+
import { type Session } from "next-auth";
|
|
12
|
+
import superjson from "superjson";
|
|
13
|
+
import { ZodError } from "zod/v4";
|
|
14
|
+
|
|
15
|
+
import { getServerAuthSession } from "~/server/auth";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 1. CONTEXT
|
|
19
|
+
*
|
|
20
|
+
* This section defines the "contexts" that are available in the backend API.
|
|
21
|
+
*
|
|
22
|
+
* These allow you to access things when processing a request, like the database, the session, etc.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
interface CreateContextOptions {
|
|
26
|
+
session: Session | null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* This helper generates the "internals" for a tRPC context. If you need to use it, you can export
|
|
31
|
+
* it from here.
|
|
32
|
+
*
|
|
33
|
+
* Examples of things you may need it for:
|
|
34
|
+
* - testing, so we don't have to mock Next.js' req/res
|
|
35
|
+
* - tRPC's `createSSGHelpers`, where we don't have req/res
|
|
36
|
+
*
|
|
37
|
+
* @see https://create.t3.gg/en/usage/trpc#-serverapitrpcts
|
|
38
|
+
*/
|
|
39
|
+
const createInnerTRPCContext = ({ session }: CreateContextOptions) => {
|
|
40
|
+
return {
|
|
41
|
+
session,
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* This is the actual context you will use in your router. It will be used to process every request
|
|
47
|
+
* that goes through your tRPC endpoint.
|
|
48
|
+
*
|
|
49
|
+
* @see https://trpc.io/docs/context
|
|
50
|
+
*/
|
|
51
|
+
export const createTRPCContext = async ({
|
|
52
|
+
req,
|
|
53
|
+
res,
|
|
54
|
+
}: CreateNextContextOptions) => {
|
|
55
|
+
// Get the session from the server using the getServerSession wrapper function
|
|
56
|
+
const session = await getServerAuthSession({ req, res });
|
|
57
|
+
|
|
58
|
+
return createInnerTRPCContext({
|
|
59
|
+
session,
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 2. INITIALIZATION
|
|
65
|
+
*
|
|
66
|
+
* This is where the tRPC API is initialized, connecting the context and transformer. We also parse
|
|
67
|
+
* ZodErrors so that you get typesafety on the frontend if your procedure fails due to validation
|
|
68
|
+
* errors on the backend.
|
|
69
|
+
*/
|
|
70
|
+
|
|
71
|
+
const t = initTRPC.context<typeof createTRPCContext>().create({
|
|
72
|
+
transformer: superjson,
|
|
73
|
+
errorFormatter({ shape, error }) {
|
|
74
|
+
return {
|
|
75
|
+
...shape,
|
|
76
|
+
data: {
|
|
77
|
+
...shape.data,
|
|
78
|
+
zodError:
|
|
79
|
+
error.cause instanceof ZodError ? error.cause.flatten() : null,
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Create a server-side caller.
|
|
87
|
+
*
|
|
88
|
+
* @see https://trpc.io/docs/server/server-side-calls
|
|
89
|
+
*/
|
|
90
|
+
export const createCallerFactory = t.createCallerFactory;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* 3. ROUTER & PROCEDURE (THE IMPORTANT BIT)
|
|
94
|
+
*
|
|
95
|
+
* These are the pieces you use to build your tRPC API. You should import these a lot in the
|
|
96
|
+
* "/src/server/api/routers" directory.
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* This is how you create new routers and sub-routers in your tRPC API.
|
|
101
|
+
*
|
|
102
|
+
* @see https://trpc.io/docs/router
|
|
103
|
+
*/
|
|
104
|
+
export const createTRPCRouter = t.router;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Middleware for timing procedure execution and adding an articifial delay in development.
|
|
108
|
+
*
|
|
109
|
+
* You can remove this if you don't like it, but it can help catch unwanted waterfalls by simulating
|
|
110
|
+
* network latency that would occur in production but not in local development.
|
|
111
|
+
*/
|
|
112
|
+
const timingMiddleware = t.middleware(async ({ next, path }) => {
|
|
113
|
+
const start = Date.now();
|
|
114
|
+
|
|
115
|
+
if (t._config.isDev) {
|
|
116
|
+
// artificial delay in dev
|
|
117
|
+
const waitMs = Math.floor(Math.random() * 400) + 100;
|
|
118
|
+
await new Promise((resolve) => setTimeout(resolve, waitMs));
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const result = await next();
|
|
122
|
+
|
|
123
|
+
const end = Date.now();
|
|
124
|
+
console.log(`[TRPC] ${path} took ${end - start}ms to execute`);
|
|
125
|
+
|
|
126
|
+
return result;
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Public (unauthenticated) procedure
|
|
131
|
+
*
|
|
132
|
+
* This is the base piece you use to build new queries and mutations on your tRPC API. It does not
|
|
133
|
+
* guarantee that a user querying is authorized, but you can still access user session data if they
|
|
134
|
+
* are logged in.
|
|
135
|
+
*/
|
|
136
|
+
export const publicProcedure = t.procedure.use(timingMiddleware);
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Protected (authenticated) procedure
|
|
140
|
+
*
|
|
141
|
+
* If you want a query or mutation to ONLY be accessible to logged in users, use this. It verifies
|
|
142
|
+
* the session is valid and guarantees `ctx.session.user` is not null.
|
|
143
|
+
*
|
|
144
|
+
* @see https://trpc.io/docs/procedures
|
|
145
|
+
*/
|
|
146
|
+
export const protectedProcedure = t.procedure
|
|
147
|
+
.use(timingMiddleware)
|
|
148
|
+
.use(({ ctx, next }) => {
|
|
149
|
+
if (!ctx.session || !ctx.session.user) {
|
|
150
|
+
throw new TRPCError({ code: "UNAUTHORIZED" });
|
|
151
|
+
}
|
|
152
|
+
return next({
|
|
153
|
+
ctx: {
|
|
154
|
+
// infers the `session` as non-nullable
|
|
155
|
+
session: { ...ctx.session, user: ctx.session.user },
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
});
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* YOU PROBABLY DON'T NEED TO EDIT THIS FILE, UNLESS:
|
|
3
|
+
* 1. You want to modify request context (see Part 1).
|
|
4
|
+
* 2. You want to create a new middleware or type of procedure (see Part 3).
|
|
5
|
+
*
|
|
6
|
+
* TL;DR - This is where all the tRPC server stuff is created and plugged in. The pieces you will
|
|
7
|
+
* need to use are documented accordingly near the end.
|
|
8
|
+
*/
|
|
9
|
+
import { initTRPC } from "@trpc/server";
|
|
10
|
+
import { type CreateNextContextOptions } from "@trpc/server/adapters/next";
|
|
11
|
+
import superjson from "superjson";
|
|
12
|
+
import { ZodError } from "zod/v4";
|
|
13
|
+
|
|
14
|
+
import { db } from "~/server/db";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 1. CONTEXT
|
|
18
|
+
*
|
|
19
|
+
* This section defines the "contexts" that are available in the backend API.
|
|
20
|
+
*
|
|
21
|
+
* These allow you to access things when processing a request, like the database, the session, etc.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
type CreateContextOptions = Record<string, never>;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* This helper generates the "internals" for a tRPC context. If you need to use it, you can export
|
|
28
|
+
* it from here.
|
|
29
|
+
*
|
|
30
|
+
* Examples of things you may need it for:
|
|
31
|
+
* - testing, so we don't have to mock Next.js' req/res
|
|
32
|
+
* - tRPC's `createSSGHelpers`, where we don't have req/res
|
|
33
|
+
*
|
|
34
|
+
* @see https://create.t3.gg/en/usage/trpc#-serverapitrpcts
|
|
35
|
+
*/
|
|
36
|
+
const createInnerTRPCContext = (_opts: CreateContextOptions) => {
|
|
37
|
+
return {
|
|
38
|
+
db,
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* This is the actual context you will use in your router. It will be used to process every request
|
|
44
|
+
* that goes through your tRPC endpoint.
|
|
45
|
+
*
|
|
46
|
+
* @see https://trpc.io/docs/context
|
|
47
|
+
*/
|
|
48
|
+
export const createTRPCContext = (_opts: CreateNextContextOptions) => {
|
|
49
|
+
return createInnerTRPCContext({});
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 2. INITIALIZATION
|
|
54
|
+
*
|
|
55
|
+
* This is where the tRPC API is initialized, connecting the context and transformer. We also parse
|
|
56
|
+
* ZodErrors so that you get typesafety on the frontend if your procedure fails due to validation
|
|
57
|
+
* errors on the backend.
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
const t = initTRPC.context<typeof createTRPCContext>().create({
|
|
61
|
+
transformer: superjson,
|
|
62
|
+
errorFormatter({ shape, error }) {
|
|
63
|
+
return {
|
|
64
|
+
...shape,
|
|
65
|
+
data: {
|
|
66
|
+
...shape.data,
|
|
67
|
+
zodError:
|
|
68
|
+
error.cause instanceof ZodError ? error.cause.flatten() : null,
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Create a server-side caller.
|
|
76
|
+
*
|
|
77
|
+
* @see https://trpc.io/docs/server/server-side-calls
|
|
78
|
+
*/
|
|
79
|
+
export const createCallerFactory = t.createCallerFactory;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 3. ROUTER & PROCEDURE (THE IMPORTANT BIT)
|
|
83
|
+
*
|
|
84
|
+
* These are the pieces you use to build your tRPC API. You should import these a lot in the
|
|
85
|
+
* "/src/server/api/routers" directory.
|
|
86
|
+
*/
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* This is how you create new routers and sub-routers in your tRPC API.
|
|
90
|
+
*
|
|
91
|
+
* @see https://trpc.io/docs/router
|
|
92
|
+
*/
|
|
93
|
+
export const createTRPCRouter = t.router;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Middleware for timing procedure execution and adding an articifial delay in development.
|
|
97
|
+
*
|
|
98
|
+
* You can remove this if you don't like it, but it can help catch unwanted waterfalls by simulating
|
|
99
|
+
* network latency that would occur in production but not in local development.
|
|
100
|
+
*/
|
|
101
|
+
const timingMiddleware = t.middleware(async ({ next, path }) => {
|
|
102
|
+
const start = Date.now();
|
|
103
|
+
|
|
104
|
+
if (t._config.isDev) {
|
|
105
|
+
// artificial delay in dev
|
|
106
|
+
const waitMs = Math.floor(Math.random() * 400) + 100;
|
|
107
|
+
await new Promise((resolve) => setTimeout(resolve, waitMs));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const result = await next();
|
|
111
|
+
|
|
112
|
+
const end = Date.now();
|
|
113
|
+
console.log(`[TRPC] ${path} took ${end - start}ms to execute`);
|
|
114
|
+
|
|
115
|
+
return result;
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Public (unauthenticated) procedure
|
|
120
|
+
*
|
|
121
|
+
* This is the base piece you use to build new queries and mutations on your tRPC API. It does not
|
|
122
|
+
* guarantee that a user querying is authorized, but you can still access user session data if they
|
|
123
|
+
* are logged in.
|
|
124
|
+
*/
|
|
125
|
+
export const publicProcedure = t.procedure.use(timingMiddleware);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import "server-only";
|
|
2
|
+
|
|
3
|
+
import { fmAdapter } from "../auth";
|
|
4
|
+
import { saltAndHashPassword } from "../password";
|
|
5
|
+
|
|
6
|
+
type UserSignUpInput = {
|
|
7
|
+
email: string;
|
|
8
|
+
password: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export async function userSignUp(input: UserSignUpInput) {
|
|
12
|
+
const passwordHash = await saltAndHashPassword(input.password);
|
|
13
|
+
|
|
14
|
+
// create the user in our database
|
|
15
|
+
const user = await fmAdapter.typedClients.userWithPasswordHash.create({
|
|
16
|
+
fieldData: {
|
|
17
|
+
email: input.email,
|
|
18
|
+
passwordHash,
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
return user;
|
|
23
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Client } from "@planetscale/database";
|
|
2
|
+
import { PrismaPlanetScale } from "@prisma/adapter-planetscale";
|
|
3
|
+
import { PrismaClient } from "@prisma/client";
|
|
4
|
+
|
|
5
|
+
import { env } from "~/env";
|
|
6
|
+
|
|
7
|
+
const psClient = new Client({ url: env.DATABASE_URL });
|
|
8
|
+
|
|
9
|
+
const createPrismaClient = () =>
|
|
10
|
+
new PrismaClient({
|
|
11
|
+
log:
|
|
12
|
+
env.NODE_ENV === "development" ? ["query", "error", "warn"] : ["error"],
|
|
13
|
+
adapter: new PrismaPlanetScale(psClient),
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const globalForPrisma = globalThis as unknown as {
|
|
17
|
+
prisma: ReturnType<typeof createPrismaClient> | undefined;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const db = globalForPrisma.prisma ?? createPrismaClient();
|
|
21
|
+
|
|
22
|
+
if (env.NODE_ENV !== "production") globalForPrisma.prisma = db;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PrismaClient } from "@prisma/client";
|
|
2
|
+
|
|
3
|
+
import { env } from "~/env";
|
|
4
|
+
|
|
5
|
+
const createPrismaClient = () =>
|
|
6
|
+
new PrismaClient({
|
|
7
|
+
log:
|
|
8
|
+
env.NODE_ENV === "development" ? ["query", "error", "warn"] : ["error"],
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
const globalForPrisma = globalThis as unknown as {
|
|
12
|
+
prisma: ReturnType<typeof createPrismaClient> | undefined;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const db = globalForPrisma.prisma ?? createPrismaClient();
|
|
16
|
+
|
|
17
|
+
if (env.NODE_ENV !== "production") globalForPrisma.prisma = db;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { drizzle } from "drizzle-orm/mysql2";
|
|
2
|
+
import { createPool, type Pool } from "mysql2/promise";
|
|
3
|
+
|
|
4
|
+
import { env } from "~/env";
|
|
5
|
+
import * as schema from "./schema";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Cache the database connection in development. This avoids creating a new connection on every HMR
|
|
9
|
+
* update.
|
|
10
|
+
*/
|
|
11
|
+
const globalForDb = globalThis as unknown as {
|
|
12
|
+
conn: Pool | undefined;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const conn = globalForDb.conn ?? createPool({ uri: env.DATABASE_URL });
|
|
16
|
+
if (env.NODE_ENV !== "production") globalForDb.conn = conn;
|
|
17
|
+
|
|
18
|
+
export const db = drizzle(conn, { schema, mode: "default" });
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { drizzle } from "drizzle-orm/postgres-js";
|
|
2
|
+
import postgres from "postgres";
|
|
3
|
+
|
|
4
|
+
import { env } from "~/env";
|
|
5
|
+
import * as schema from "./schema";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Cache the database connection in development. This avoids creating a new connection on every HMR
|
|
9
|
+
* update.
|
|
10
|
+
*/
|
|
11
|
+
const globalForDb = globalThis as unknown as {
|
|
12
|
+
conn: postgres.Sql | undefined;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const conn = globalForDb.conn ?? postgres(env.DATABASE_URL);
|
|
16
|
+
if (env.NODE_ENV !== "production") globalForDb.conn = conn;
|
|
17
|
+
|
|
18
|
+
export const db = drizzle(conn, { schema });
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createClient, type Client } from "@libsql/client";
|
|
2
|
+
import { drizzle } from "drizzle-orm/libsql";
|
|
3
|
+
|
|
4
|
+
import { env } from "~/env";
|
|
5
|
+
import * as schema from "./schema";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Cache the database connection in development. This avoids creating a new connection on every HMR
|
|
9
|
+
* update.
|
|
10
|
+
*/
|
|
11
|
+
const globalForDb = globalThis as unknown as {
|
|
12
|
+
client: Client | undefined;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const client =
|
|
16
|
+
globalForDb.client ?? createClient({ url: env.DATABASE_URL });
|
|
17
|
+
if (env.NODE_ENV !== "production") globalForDb.client = client;
|
|
18
|
+
|
|
19
|
+
export const db = drizzle(client, { schema });
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Example model schema from the Drizzle docs
|
|
2
|
+
// https://orm.drizzle.team/docs/sql-schema-declaration
|
|
3
|
+
|
|
4
|
+
import { sql } from "drizzle-orm";
|
|
5
|
+
import {
|
|
6
|
+
bigint,
|
|
7
|
+
index,
|
|
8
|
+
mysqlTableCreator,
|
|
9
|
+
timestamp,
|
|
10
|
+
varchar,
|
|
11
|
+
} from "drizzle-orm/mysql-core";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* This is an example of how to use the multi-project schema feature of Drizzle ORM. Use the same
|
|
15
|
+
* database instance for multiple projects.
|
|
16
|
+
*
|
|
17
|
+
* @see https://orm.drizzle.team/docs/goodies#multi-project-schema
|
|
18
|
+
*/
|
|
19
|
+
export const createTable = mysqlTableCreator((name) => `project1_${name}`);
|
|
20
|
+
|
|
21
|
+
export const posts = createTable(
|
|
22
|
+
"post",
|
|
23
|
+
{
|
|
24
|
+
id: bigint("id", { mode: "number" }).primaryKey().autoincrement(),
|
|
25
|
+
name: varchar("name", { length: 256 }),
|
|
26
|
+
createdAt: timestamp("created_at")
|
|
27
|
+
.default(sql`CURRENT_TIMESTAMP`)
|
|
28
|
+
.notNull(),
|
|
29
|
+
updatedAt: timestamp("updated_at").onUpdateNow(),
|
|
30
|
+
},
|
|
31
|
+
(example) => ({
|
|
32
|
+
nameIndex: index("name_idx").on(example.name),
|
|
33
|
+
})
|
|
34
|
+
);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Example model schema from the Drizzle docs
|
|
2
|
+
// https://orm.drizzle.team/docs/sql-schema-declaration
|
|
3
|
+
|
|
4
|
+
import { sql } from "drizzle-orm";
|
|
5
|
+
import {
|
|
6
|
+
bigint,
|
|
7
|
+
index,
|
|
8
|
+
mysqlTableCreator,
|
|
9
|
+
timestamp,
|
|
10
|
+
varchar,
|
|
11
|
+
} from "drizzle-orm/mysql-core";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* This is an example of how to use the multi-project schema feature of Drizzle ORM. Use the same
|
|
15
|
+
* database instance for multiple projects.
|
|
16
|
+
*
|
|
17
|
+
* @see https://orm.drizzle.team/docs/goodies#multi-project-schema
|
|
18
|
+
*/
|
|
19
|
+
export const createTable = mysqlTableCreator((name) => `project1_${name}`);
|
|
20
|
+
|
|
21
|
+
export const posts = createTable(
|
|
22
|
+
"post",
|
|
23
|
+
{
|
|
24
|
+
id: bigint("id", { mode: "number" }).primaryKey().autoincrement(),
|
|
25
|
+
name: varchar("name", { length: 256 }),
|
|
26
|
+
createdAt: timestamp("created_at")
|
|
27
|
+
.default(sql`CURRENT_TIMESTAMP`)
|
|
28
|
+
.notNull(),
|
|
29
|
+
updatedAt: timestamp("updated_at").onUpdateNow(),
|
|
30
|
+
},
|
|
31
|
+
(example) => ({
|
|
32
|
+
nameIndex: index("name_idx").on(example.name),
|
|
33
|
+
})
|
|
34
|
+
);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Example model schema from the Drizzle docs
|
|
2
|
+
// https://orm.drizzle.team/docs/sql-schema-declaration
|
|
3
|
+
|
|
4
|
+
import { sql } from "drizzle-orm";
|
|
5
|
+
import {
|
|
6
|
+
index,
|
|
7
|
+
pgTableCreator,
|
|
8
|
+
serial,
|
|
9
|
+
timestamp,
|
|
10
|
+
varchar,
|
|
11
|
+
} from "drizzle-orm/pg-core";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* This is an example of how to use the multi-project schema feature of Drizzle ORM. Use the same
|
|
15
|
+
* database instance for multiple projects.
|
|
16
|
+
*
|
|
17
|
+
* @see https://orm.drizzle.team/docs/goodies#multi-project-schema
|
|
18
|
+
*/
|
|
19
|
+
export const createTable = pgTableCreator((name) => `project1_${name}`);
|
|
20
|
+
|
|
21
|
+
export const posts = createTable(
|
|
22
|
+
"post",
|
|
23
|
+
{
|
|
24
|
+
id: serial("id").primaryKey(),
|
|
25
|
+
name: varchar("name", { length: 256 }),
|
|
26
|
+
createdAt: timestamp("created_at", { withTimezone: true })
|
|
27
|
+
.default(sql`CURRENT_TIMESTAMP`)
|
|
28
|
+
.notNull(),
|
|
29
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).$onUpdate(
|
|
30
|
+
() => new Date()
|
|
31
|
+
),
|
|
32
|
+
},
|
|
33
|
+
(example) => ({
|
|
34
|
+
nameIndex: index("name_idx").on(example.name),
|
|
35
|
+
})
|
|
36
|
+
);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Example model schema from the Drizzle docs
|
|
2
|
+
// https://orm.drizzle.team/docs/sql-schema-declaration
|
|
3
|
+
|
|
4
|
+
import { sql } from "drizzle-orm";
|
|
5
|
+
import { index, int, sqliteTableCreator, text } from "drizzle-orm/sqlite-core";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* This is an example of how to use the multi-project schema feature of Drizzle ORM. Use the same
|
|
9
|
+
* database instance for multiple projects.
|
|
10
|
+
*
|
|
11
|
+
* @see https://orm.drizzle.team/docs/goodies#multi-project-schema
|
|
12
|
+
*/
|
|
13
|
+
export const createTable = sqliteTableCreator((name) => `project1_${name}`);
|
|
14
|
+
|
|
15
|
+
export const posts = createTable(
|
|
16
|
+
"post",
|
|
17
|
+
{
|
|
18
|
+
id: int("id", { mode: "number" }).primaryKey({ autoIncrement: true }),
|
|
19
|
+
name: text("name", { length: 256 }),
|
|
20
|
+
createdAt: int("created_at", { mode: "timestamp" })
|
|
21
|
+
.default(sql`(unixepoch())`)
|
|
22
|
+
.notNull(),
|
|
23
|
+
updatedAt: int("updated_at", { mode: "timestamp" }).$onUpdate(
|
|
24
|
+
() => new Date()
|
|
25
|
+
),
|
|
26
|
+
},
|
|
27
|
+
(example) => ({
|
|
28
|
+
nameIndex: index("name_idx").on(example.name),
|
|
29
|
+
})
|
|
30
|
+
);
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { relations, sql } from "drizzle-orm";
|
|
2
|
+
import {
|
|
3
|
+
bigint,
|
|
4
|
+
index,
|
|
5
|
+
int,
|
|
6
|
+
mysqlTableCreator,
|
|
7
|
+
primaryKey,
|
|
8
|
+
text,
|
|
9
|
+
timestamp,
|
|
10
|
+
varchar,
|
|
11
|
+
} from "drizzle-orm/mysql-core";
|
|
12
|
+
import { type AdapterAccount } from "next-auth/adapters";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* This is an example of how to use the multi-project schema feature of Drizzle ORM. Use the same
|
|
16
|
+
* database instance for multiple projects.
|
|
17
|
+
*
|
|
18
|
+
* @see https://orm.drizzle.team/docs/goodies#multi-project-schema
|
|
19
|
+
*/
|
|
20
|
+
export const createTable = mysqlTableCreator((name) => `project1_${name}`);
|
|
21
|
+
|
|
22
|
+
export const posts = createTable(
|
|
23
|
+
"post",
|
|
24
|
+
{
|
|
25
|
+
id: bigint("id", { mode: "number" }).primaryKey().autoincrement(),
|
|
26
|
+
name: varchar("name", { length: 256 }),
|
|
27
|
+
createdById: varchar("created_by", { length: 255 })
|
|
28
|
+
.notNull()
|
|
29
|
+
.references(() => users.id),
|
|
30
|
+
createdAt: timestamp("created_at")
|
|
31
|
+
.default(sql`CURRENT_TIMESTAMP`)
|
|
32
|
+
.notNull(),
|
|
33
|
+
updatedAt: timestamp("updated_at").onUpdateNow(),
|
|
34
|
+
},
|
|
35
|
+
(example) => ({
|
|
36
|
+
createdByIdIdx: index("created_by_idx").on(example.createdById),
|
|
37
|
+
nameIndex: index("name_idx").on(example.name),
|
|
38
|
+
})
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
export const users = createTable("user", {
|
|
42
|
+
id: varchar("id", { length: 255 })
|
|
43
|
+
.notNull()
|
|
44
|
+
.primaryKey()
|
|
45
|
+
.$defaultFn(() => crypto.randomUUID()),
|
|
46
|
+
name: varchar("name", { length: 255 }),
|
|
47
|
+
email: varchar("email", { length: 255 }).notNull(),
|
|
48
|
+
emailVerified: timestamp("email_verified", {
|
|
49
|
+
mode: "date",
|
|
50
|
+
fsp: 3,
|
|
51
|
+
}).default(sql`CURRENT_TIMESTAMP(3)`),
|
|
52
|
+
image: varchar("image", { length: 255 }),
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
export const usersRelations = relations(users, ({ many }) => ({
|
|
56
|
+
accounts: many(accounts),
|
|
57
|
+
sessions: many(sessions),
|
|
58
|
+
}));
|
|
59
|
+
|
|
60
|
+
export const accounts = createTable(
|
|
61
|
+
"account",
|
|
62
|
+
{
|
|
63
|
+
userId: varchar("user_id", { length: 255 })
|
|
64
|
+
.notNull()
|
|
65
|
+
.references(() => users.id),
|
|
66
|
+
type: varchar("type", { length: 255 })
|
|
67
|
+
.$type<AdapterAccount["type"]>()
|
|
68
|
+
.notNull(),
|
|
69
|
+
provider: varchar("provider", { length: 255 }).notNull(),
|
|
70
|
+
providerAccountId: varchar("provider_account_id", {
|
|
71
|
+
length: 255,
|
|
72
|
+
}).notNull(),
|
|
73
|
+
refresh_token: text("refresh_token"),
|
|
74
|
+
access_token: text("access_token"),
|
|
75
|
+
expires_at: int("expires_at"),
|
|
76
|
+
token_type: varchar("token_type", { length: 255 }),
|
|
77
|
+
scope: varchar("scope", { length: 255 }),
|
|
78
|
+
id_token: text("id_token"),
|
|
79
|
+
session_state: varchar("session_state", { length: 255 }),
|
|
80
|
+
},
|
|
81
|
+
(account) => ({
|
|
82
|
+
compoundKey: primaryKey({
|
|
83
|
+
columns: [account.provider, account.providerAccountId],
|
|
84
|
+
}),
|
|
85
|
+
userIdIdx: index("account_user_id_idx").on(account.userId),
|
|
86
|
+
})
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
export const accountsRelations = relations(accounts, ({ one }) => ({
|
|
90
|
+
user: one(users, { fields: [accounts.userId], references: [users.id] }),
|
|
91
|
+
}));
|
|
92
|
+
|
|
93
|
+
export const sessions = createTable(
|
|
94
|
+
"session",
|
|
95
|
+
{
|
|
96
|
+
sessionToken: varchar("session_token", { length: 255 })
|
|
97
|
+
.notNull()
|
|
98
|
+
.primaryKey(),
|
|
99
|
+
userId: varchar("user_id", { length: 255 })
|
|
100
|
+
.notNull()
|
|
101
|
+
.references(() => users.id),
|
|
102
|
+
expires: timestamp("expires", { mode: "date" }).notNull(),
|
|
103
|
+
},
|
|
104
|
+
(session) => ({
|
|
105
|
+
userIdIdx: index("session_user_id_idx").on(session.userId),
|
|
106
|
+
})
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
export const sessionsRelations = relations(sessions, ({ one }) => ({
|
|
110
|
+
user: one(users, { fields: [sessions.userId], references: [users.id] }),
|
|
111
|
+
}));
|
|
112
|
+
|
|
113
|
+
export const verificationTokens = createTable(
|
|
114
|
+
"verification_token",
|
|
115
|
+
{
|
|
116
|
+
identifier: varchar("identifier", { length: 255 }).notNull(),
|
|
117
|
+
token: varchar("token", { length: 255 }).notNull(),
|
|
118
|
+
expires: timestamp("expires", { mode: "date" }).notNull(),
|
|
119
|
+
},
|
|
120
|
+
(vt) => ({
|
|
121
|
+
compoundKey: primaryKey({ columns: [vt.identifier, vt.token] }),
|
|
122
|
+
})
|
|
123
|
+
);
|