├── public └── favicon.ico ├── postcss.config.js ├── src ├── app │ └── api │ │ ├── auth │ │ └── [...nextauth] │ │ │ └── route.ts │ │ └── model │ │ └── [...path] │ │ └── route.ts ├── styles │ └── globals.css ├── server │ ├── auth │ │ ├── index.ts │ │ └── config.ts │ └── db.ts ├── lib │ └── hooks │ │ ├── index.ts │ │ ├── __model_meta.ts │ │ ├── post.ts │ │ ├── user.ts │ │ ├── session.ts │ │ ├── account.ts │ │ └── verification-token.ts ├── pages │ ├── _app.tsx │ ├── signin.tsx │ ├── signup.tsx │ └── index.tsx └── env.js ├── README.md ├── next.config.js ├── .env.example ├── .gitignore ├── tsconfig.json ├── package.json ├── prisma └── schema.prisma └── schema.zmodel /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zenstackhq/docs-tutorial-nextjs/HEAD/public/favicon.ico -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | export default { 2 | plugins: { 3 | "@tailwindcss/postcss": {}, 4 | }, 5 | }; 6 | -------------------------------------------------------------------------------- /src/app/api/auth/[...nextauth]/route.ts: -------------------------------------------------------------------------------- 1 | import { handlers } from "~/server/auth"; 2 | 3 | export const { GET, POST } = handlers; 4 | -------------------------------------------------------------------------------- /src/styles/globals.css: -------------------------------------------------------------------------------- 1 | @import "tailwindcss"; 2 | 3 | @theme { 4 | --font-sans: var(--font-geist-sans), ui-sans-serif, system-ui, sans-serif, 5 | "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; 6 | } 7 | -------------------------------------------------------------------------------- /src/server/auth/index.ts: -------------------------------------------------------------------------------- 1 | import NextAuth from "next-auth"; 2 | import { cache } from "react"; 3 | 4 | import { authConfig } from "./config"; 5 | 6 | const { auth: uncachedAuth, handlers, signIn, signOut } = NextAuth(authConfig); 7 | 8 | const auth = cache(uncachedAuth); 9 | 10 | export { auth, handlers, signIn, signOut }; 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ZenStack Next.js Tutorial Project(page router) 2 | 3 | This is a sample project for demonstrating how to use ZenStack in a Next.js project for page router. 4 | 5 | See documentation [here](https://zenstack.dev/docs/get-started/nextjs). 6 | 7 | To run the project: 8 | 9 | ``` 10 | npm run build 11 | npm run dev 12 | ``` 13 | 14 | For the Next.js "app" router, please checkout [this project](https://github.com/zenstackhq/docs-tutorial-nextjs-app-dir). 15 | -------------------------------------------------------------------------------- /src/server/db.ts: -------------------------------------------------------------------------------- 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 | undefined; 13 | }; 14 | 15 | export const db = globalForPrisma.prisma ?? createPrismaClient(); 16 | 17 | if (env.NODE_ENV !== "production") globalForPrisma.prisma = db; 18 | -------------------------------------------------------------------------------- /next.config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially useful 3 | * for Docker builds. 4 | */ 5 | import "./src/env.js"; 6 | 7 | /** @type {import("next").NextConfig} */ 8 | const config = { 9 | reactStrictMode: true, 10 | 11 | /** 12 | * If you are using `appDir` then you must comment the below `i18n` config out. 13 | * 14 | * @see https://github.com/vercel/next.js/issues/41980 15 | */ 16 | i18n: { 17 | locales: ["en"], 18 | defaultLocale: "en", 19 | }, 20 | }; 21 | 22 | export default config; 23 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | # When adding additional environment variables, the schema in "/src/env.js" 2 | # should be updated accordingly. 3 | 4 | # Next Auth 5 | # You can generate a new secret on the command line with: 6 | # npx auth secret 7 | # https://next-auth.js.org/configuration/options#secret 8 | AUTH_SECRET="+Dy0QmzHzED6SzzdrJG/HOLLQ0LWLR6ezkJFp2uzios=" # Generated by create-t3-app. 9 | 10 | # Next Auth Discord Provider 11 | AUTH_DISCORD_ID="" 12 | AUTH_DISCORD_SECRET="" 13 | 14 | # Prisma 15 | # https://www.prisma.io/docs/reference/database-reference/connection-urls#env 16 | DATABASE_URL="file:./db.sqlite" 17 | -------------------------------------------------------------------------------- /src/app/api/model/[...path]/route.ts: -------------------------------------------------------------------------------- 1 | import { enhance } from '@zenstackhq/runtime'; 2 | import { NextRequestHandler } from '@zenstackhq/server/next'; 3 | import { db } from '~/server/db'; 4 | import { auth } from '~/server/auth'; 5 | 6 | // create an enhanced Prisma client with user context 7 | async function getPrisma() { 8 | const authObj = await auth(); 9 | return enhance(db, { user: authObj?.user }); 10 | } 11 | 12 | const handler = NextRequestHandler({ getPrisma, useAppDir: true }); 13 | 14 | export { handler as DELETE, handler as GET, handler as PATCH, handler as POST, handler as PUT }; 15 | -------------------------------------------------------------------------------- /src/lib/hooks/index.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * This file was generated by ZenStack CLI. 3 | ******************************************************************************/ 4 | 5 | /* eslint-disable */ 6 | // @ts-nocheck 7 | 8 | export * from './post'; 9 | export * from './account'; 10 | export * from './session'; 11 | export * from './user'; 12 | export * from './verification-token'; 13 | export { getQueryKey } from '@zenstackhq/tanstack-query/runtime-v5'; 14 | export { Provider } from '@zenstackhq/tanstack-query/runtime-v5/react'; 15 | export { default as metadata } from './__model_meta'; 16 | -------------------------------------------------------------------------------- /src/pages/_app.tsx: -------------------------------------------------------------------------------- 1 | import { type AppType } from 'next/app'; 2 | import { type Session } from 'next-auth'; 3 | import { SessionProvider } from 'next-auth/react'; 4 | import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; 5 | 6 | import '../styles/globals.css'; 7 | 8 | const queryClient = new QueryClient(); 9 | 10 | const MyApp: AppType<{ session: Session | null }> = ({ Component, pageProps: { session, ...pageProps } }) => { 11 | return ( 12 | 13 | 14 | 15 | 16 | 17 | ); 18 | }; 19 | 20 | export default MyApp; 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # database 12 | /prisma/db.sqlite 13 | /prisma/db.sqlite-journal 14 | db.sqlite 15 | 16 | # next.js 17 | /.next/ 18 | /out/ 19 | next-env.d.ts 20 | 21 | # production 22 | /build 23 | 24 | # misc 25 | .DS_Store 26 | *.pem 27 | 28 | # debug 29 | npm-debug.log* 30 | yarn-debug.log* 31 | yarn-error.log* 32 | .pnpm-debug.log* 33 | 34 | # local env files 35 | # do not commit any .env files to git, except for the .env.example file. https://create.t3.gg/en/usage/env-variables#using-environment-variables 36 | .env 37 | .env*.local 38 | 39 | # vercel 40 | .vercel 41 | 42 | # typescript 43 | *.tsbuildinfo 44 | 45 | # idea files 46 | .idea -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Base Options: */ 4 | "esModuleInterop": true, 5 | "skipLibCheck": true, 6 | "target": "es2022", 7 | "allowJs": true, 8 | "resolveJsonModule": true, 9 | "moduleDetection": "force", 10 | "isolatedModules": true, 11 | "verbatimModuleSyntax": true, 12 | 13 | /* Strictness */ 14 | "strict": true, 15 | "noUncheckedIndexedAccess": true, 16 | "checkJs": true, 17 | 18 | /* Bundled projects */ 19 | "lib": ["dom", "dom.iterable", "ES2022"], 20 | "noEmit": true, 21 | "module": "ESNext", 22 | "moduleResolution": "Bundler", 23 | "jsx": "preserve", 24 | "plugins": [{ "name": "next" }], 25 | "incremental": true, 26 | 27 | /* Path Aliases */ 28 | "baseUrl": ".", 29 | "paths": { 30 | "~/*": ["./src/*"] 31 | } 32 | }, 33 | "include": [ 34 | "next-env.d.ts", 35 | "**/*.ts", 36 | "**/*.tsx", 37 | "**/*.cjs", 38 | "**/*.js", 39 | ".next/types/**/*.ts" 40 | ], 41 | "exclude": ["node_modules"] 42 | } 43 | -------------------------------------------------------------------------------- /src/env.js: -------------------------------------------------------------------------------- 1 | import { createEnv } from '@t3-oss/env-nextjs'; 2 | import { z } from 'zod'; 3 | 4 | export const env = createEnv({ 5 | /** 6 | * Specify your server-side environment variables schema here. This way you can ensure the app 7 | * isn't built with invalid env vars. 8 | */ 9 | server: { 10 | AUTH_SECRET: process.env.NODE_ENV === 'production' ? z.string() : z.string().optional(), 11 | DATABASE_URL: z.string().url(), 12 | NODE_ENV: z.enum(['development', 'test', 'production']).default('development'), 13 | }, 14 | 15 | /** 16 | * Specify your client-side environment variables schema here. This way you can ensure the app 17 | * isn't built with invalid env vars. To expose them to the client, prefix them with 18 | * `NEXT_PUBLIC_`. 19 | */ 20 | client: { 21 | // NEXT_PUBLIC_CLIENTVAR: z.string(), 22 | }, 23 | 24 | /** 25 | * You can't destruct `process.env` as a regular object in the Next.js edge runtimes (e.g. 26 | * middlewares) or client-side so we need to destruct manually. 27 | */ 28 | runtimeEnv: { 29 | AUTH_SECRET: process.env.AUTH_SECRET, 30 | DATABASE_URL: process.env.DATABASE_URL, 31 | NODE_ENV: process.env.NODE_ENV, 32 | }, 33 | /** 34 | * Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially 35 | * useful for Docker builds. 36 | */ 37 | skipValidation: !!process.env.SKIP_ENV_VALIDATION, 38 | /** 39 | * Makes it so that empty strings are treated as undefined. `SOME_VAR: z.string()` and 40 | * `SOME_VAR=''` will throw an error. 41 | */ 42 | emptyStringAsUndefined: true, 43 | }); 44 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "my-blog-app", 3 | "version": "0.1.0", 4 | "private": true, 5 | "type": "module", 6 | "scripts": { 7 | "generate": "zenstack generate", 8 | "build": "npm run generate && next build", 9 | "db:generate": "prisma migrate dev", 10 | "db:migrate": "prisma migrate deploy", 11 | "db:push": "prisma db push", 12 | "db:studio": "prisma studio", 13 | "dev": "next dev --turbo", 14 | "postinstall": "prisma generate", 15 | "preview": "next build && next start", 16 | "start": "next start", 17 | "typecheck": "tsc --noEmit" 18 | }, 19 | "dependencies": { 20 | "@auth/prisma-adapter": "^2.7.2", 21 | "@prisma/client": "^6.5.0", 22 | "@t3-oss/env-nextjs": "^0.12.0", 23 | "@tanstack/react-query": "^5.80.6", 24 | "@types/bcryptjs": "^2.4.6", 25 | "@zenstackhq/runtime": "2.15.1", 26 | "@zenstackhq/server": "^2.15.1", 27 | "@zenstackhq/tanstack-query": "^2.15.1", 28 | "next": "^15.2.3", 29 | "next-auth": "5.0.0-beta.25", 30 | "react": "^19.0.0", 31 | "react-dom": "^19.0.0", 32 | "zod": "^3.24.2" 33 | }, 34 | "devDependencies": { 35 | "@tailwindcss/postcss": "^4.0.15", 36 | "@types/node": "^20.14.10", 37 | "@types/react": "^19.0.0", 38 | "@types/react-dom": "^19.0.0", 39 | "postcss": "^8.5.3", 40 | "prisma": "6.8.x", 41 | "tailwindcss": "^4.0.15", 42 | "typescript": "^5.8.2", 43 | "zenstack": "2.15.1" 44 | }, 45 | "ct3aMetadata": { 46 | "initVersion": "7.39.3" 47 | }, 48 | "packageManager": "npm@10.8.2" 49 | } 50 | -------------------------------------------------------------------------------- /prisma/schema.prisma: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////////// 2 | // DO NOT MODIFY THIS FILE // 3 | // This file is automatically generated by ZenStack CLI and should not be manually updated. // 4 | ////////////////////////////////////////////////////////////////////////////////////////////// 5 | 6 | datasource db { 7 | provider = "sqlite" 8 | url = env("DATABASE_URL") 9 | } 10 | 11 | generator client { 12 | provider = "prisma-client-js" 13 | } 14 | 15 | model Post { 16 | id Int @id() @default(autoincrement()) 17 | name String 18 | createdAt DateTime @default(now()) 19 | updatedAt DateTime @updatedAt() 20 | published Boolean @default(false) 21 | createdBy User @relation(fields: [createdById], references: [id]) 22 | createdById String 23 | 24 | @@index([name]) 25 | } 26 | 27 | model Account { 28 | id String @id() @default(cuid()) 29 | userId String 30 | type String 31 | provider String 32 | providerAccountId String 33 | refresh_token String? 34 | access_token String? 35 | expires_at Int? 36 | token_type String? 37 | scope String? 38 | id_token String? 39 | session_state String? 40 | user User @relation(fields: [userId], references: [id], onDelete: Cascade) 41 | refresh_token_expires_in Int? 42 | 43 | @@unique([provider, providerAccountId]) 44 | } 45 | 46 | model Session { 47 | id String @id() @default(cuid()) 48 | sessionToken String @unique() 49 | userId String 50 | expires DateTime 51 | user User @relation(fields: [userId], references: [id], onDelete: Cascade) 52 | } 53 | 54 | model User { 55 | id String @id() @default(cuid()) 56 | name String? 57 | email String? @unique() 58 | emailVerified DateTime? 59 | image String? 60 | password String 61 | accounts Account[] 62 | sessions Session[] 63 | posts Post[] 64 | } 65 | 66 | model VerificationToken { 67 | identifier String 68 | token String @unique() 69 | expires DateTime 70 | 71 | @@unique([identifier, token]) 72 | } 73 | -------------------------------------------------------------------------------- /src/pages/signin.tsx: -------------------------------------------------------------------------------- 1 | import type { NextPage } from 'next'; 2 | import { signIn } from 'next-auth/react'; 3 | import Router from 'next/router'; 4 | import { useState, type FormEvent } from 'react'; 5 | 6 | const Signin: NextPage = () => { 7 | const [email, setEmail] = useState(''); 8 | const [password, setPassword] = useState(''); 9 | 10 | async function onSignin(e: FormEvent) { 11 | e.preventDefault(); 12 | 13 | const result = await signIn('credentials', { 14 | redirect: false, 15 | email, 16 | password, 17 | }); 18 | 19 | if (result?.ok) { 20 | await Router.push('/'); 21 | } else { 22 | alert('Signin failed'); 23 | } 24 | } 25 | 26 | return ( 27 |
28 |

Login

29 |
void onSignin(e)}> 30 |
31 | 34 | setEmail(e.currentTarget.value)} 39 | className='ml-4 w-72 rounded border p-2 bg-white' 40 | /> 41 |
42 |
43 | 46 | setPassword(e.currentTarget.value)} 51 | className='ml-4 w-72 rounded border p-2 bg-white' 52 | /> 53 |
54 | 59 |
60 |
61 | ); 62 | }; 63 | 64 | export default Signin; 65 | -------------------------------------------------------------------------------- /src/server/auth/config.ts: -------------------------------------------------------------------------------- 1 | import { PrismaAdapter } from '@auth/prisma-adapter'; 2 | import { type PrismaClient } from '@prisma/client'; 3 | import { type DefaultSession, type NextAuthConfig } from 'next-auth'; 4 | import { compare } from 'bcryptjs'; 5 | import CredentialsProvider from 'next-auth/providers/credentials'; 6 | import { db } from '~/server/db'; 7 | 8 | /** 9 | * Module augmentation for `next-auth` types. Allows us to add custom properties to the `session` 10 | * object and keep type safety. 11 | * 12 | * @see https://next-auth.js.org/getting-started/typescript#module-augmentation 13 | */ 14 | declare module 'next-auth' { 15 | interface Session extends DefaultSession { 16 | user: { 17 | id: string; 18 | }; 19 | } 20 | } 21 | 22 | /** 23 | * Options for NextAuth.js used to configure adapters, providers, callbacks, etc. 24 | * 25 | * @see https://next-auth.js.org/configuration/options 26 | */ 27 | export const authConfig = { 28 | session: { 29 | strategy: 'jwt', 30 | }, 31 | providers: [ 32 | CredentialsProvider({ 33 | credentials: { 34 | email: { type: 'email' }, 35 | password: { type: 'password' }, 36 | }, 37 | authorize: authorize(db), 38 | }), 39 | ], 40 | adapter: PrismaAdapter(db), 41 | callbacks: { 42 | session: ({ session, token }) => { 43 | if (session.user) { 44 | // eslint-disable-next-line @typescript-eslint/no-non-null-assertion 45 | session.user.id = token.sub!; 46 | } 47 | return session; 48 | }, 49 | }, 50 | } satisfies NextAuthConfig; 51 | 52 | function authorize(prisma: PrismaClient) { 53 | return async (credentials: Partial> | undefined) => { 54 | if (!credentials) { 55 | throw new Error('Missing credentials'); 56 | } 57 | 58 | if (typeof credentials.email !== 'string') { 59 | throw new Error('"email" is required in credentials'); 60 | } 61 | 62 | if (typeof credentials.password !== 'string') { 63 | throw new Error('"password" is required in credentials'); 64 | } 65 | const maybeUser = await prisma.user.findFirst({ 66 | where: { email: credentials.email }, 67 | select: { id: true, email: true, password: true }, 68 | }); 69 | if (!maybeUser?.password) return null; 70 | // verify the input password with stored hash 71 | const isValid = await compare(credentials.password, maybeUser.password); 72 | 73 | if (!isValid) return null; 74 | return { id: maybeUser.id, email: maybeUser.email }; 75 | }; 76 | } 77 | -------------------------------------------------------------------------------- /src/pages/signup.tsx: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-explicit-any */ 2 | /* eslint-disable @typescript-eslint/no-unsafe-member-access */ 3 | import type { NextPage } from 'next'; 4 | import { signIn } from 'next-auth/react'; 5 | import Router from 'next/router'; 6 | import { useState, type FormEvent } from 'react'; 7 | import { useCreateUser } from '../lib/hooks'; 8 | 9 | const Signup: NextPage = () => { 10 | const [email, setEmail] = useState(''); 11 | const [password, setPassword] = useState(''); 12 | const { mutateAsync: signup } = useCreateUser(); 13 | 14 | async function onSignup(e: FormEvent) { 15 | e.preventDefault(); 16 | try { 17 | await signup({ data: { email, password } }); 18 | } catch (err: any) { 19 | console.error(err); 20 | if (err.info?.prisma && err.info?.code === 'P2002') { 21 | // P2002 is Prisma's error code for unique constraint violations 22 | alert('User alread exists'); 23 | } else { 24 | alert('An unknown error occurred'); 25 | } 26 | return; 27 | } 28 | 29 | // signin to create a session 30 | await signIn('credentials', { redirect: false, email, password }); 31 | await Router.push('/'); 32 | } 33 | 34 | return ( 35 |
36 |

Sign up

37 |
void onSignup(e)}> 38 |
39 | 42 | setEmail(e.currentTarget.value)} 47 | className='ml-4 w-72 rounded border p-2 bg-white' 48 | /> 49 |
50 |
51 | 54 | setPassword(e.currentTarget.value)} 59 | className='ml-4 w-72 rounded border p-2 bg-white' 60 | /> 61 |
62 | 67 |
68 |
69 | ); 70 | }; 71 | 72 | export default Signup; 73 | -------------------------------------------------------------------------------- /schema.zmodel: -------------------------------------------------------------------------------- 1 | // This is your Prisma schema file, 2 | // learn more about it in the docs: https://pris.ly/d/prisma-schema 3 | 4 | generator client { 5 | provider = "prisma-client-js" 6 | } 7 | 8 | datasource db { 9 | provider = "sqlite" 10 | // NOTE: When using mysql or sqlserver, uncomment the @db.Text annotations in model Account below 11 | // Further reading: 12 | // https://next-auth.js.org/adapters/prisma#create-the-prisma-schema 13 | // https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#string 14 | url = env("DATABASE_URL") 15 | } 16 | 17 | plugin hooks { 18 | provider = '@zenstackhq/tanstack-query' 19 | target = 'react' 20 | version = 'v5' 21 | output = "./src/lib/hooks" 22 | } 23 | 24 | model Post { 25 | id Int @id @default(autoincrement()) 26 | name String 27 | createdAt DateTime @default(now()) 28 | updatedAt DateTime @updatedAt 29 | published Boolean @default(false) 30 | 31 | 32 | createdBy User @relation(fields: [createdById], references: [id]) 33 | createdById String @default(auth().id) 34 | 35 | @@index([name]) 36 | 37 | // author has full access 38 | @@allow('all', auth() == createdBy) 39 | 40 | // logged-in users can view published posts 41 | @@allow('read', auth() != null && published) 42 | } 43 | 44 | // Necessary for Next auth 45 | model Account { 46 | id String @id @default(cuid()) 47 | userId String 48 | type String 49 | provider String 50 | providerAccountId String 51 | refresh_token String? // @db.Text 52 | access_token String? // @db.Text 53 | expires_at Int? 54 | token_type String? 55 | scope String? 56 | id_token String? // @db.Text 57 | session_state String? 58 | user User @relation(fields: [userId], references: [id], onDelete: Cascade) 59 | refresh_token_expires_in Int? 60 | 61 | @@unique([provider, providerAccountId]) 62 | } 63 | 64 | model Session { 65 | id String @id @default(cuid()) 66 | sessionToken String @unique 67 | userId String 68 | expires DateTime 69 | user User @relation(fields: [userId], references: [id], onDelete: Cascade) 70 | } 71 | 72 | model User { 73 | id String @id @default(cuid()) 74 | name String? 75 | email String? @unique 76 | emailVerified DateTime? 77 | image String? 78 | password String @password @omit 79 | 80 | accounts Account[] 81 | sessions Session[] 82 | posts Post[] 83 | 84 | // everyone can signup, and user profile is also publicly readable 85 | @@allow('create,read', true) 86 | 87 | // only the user can update or delete their own profile 88 | @@allow('update,delete', auth() == this) 89 | } 90 | 91 | model VerificationToken { 92 | identifier String 93 | token String @unique 94 | expires DateTime 95 | 96 | @@unique([identifier, token]) 97 | } 98 | -------------------------------------------------------------------------------- /src/pages/index.tsx: -------------------------------------------------------------------------------- 1 | import type { Post } from '@prisma/client'; 2 | import { type NextPage } from 'next'; 3 | import { signOut, useSession } from 'next-auth/react'; 4 | import Link from 'next/link'; 5 | import Router from 'next/router'; 6 | import { useCreatePost, useDeletePost, useFindManyPost, useUpdatePost } from '../lib/hooks'; 7 | 8 | type AuthUser = { id: string; email?: string | null }; 9 | 10 | const Welcome = ({ user }: { user: AuthUser }) => { 11 | async function onSignout() { 12 | await signOut({ redirect: false }); 13 | await Router.push('/signin'); 14 | } 15 | return ( 16 |
17 |

Welcome back, {user?.email}

18 | 21 |
22 | ); 23 | }; 24 | 25 | const SigninSignup = () => { 26 | return ( 27 |
28 | 29 | Signin 30 | 31 | 32 | Signup 33 | 34 |
35 | ); 36 | }; 37 | 38 | const Posts = () => { 39 | // Post crud hooks 40 | const { mutateAsync: createPost } = useCreatePost(); 41 | const { mutateAsync: updatePost } = useUpdatePost(); 42 | const { mutateAsync: deletePost } = useDeletePost(); 43 | 44 | // list all posts that're visible to the current user, together with their authors 45 | const { data: posts } = useFindManyPost({ 46 | include: { createdBy: true }, 47 | orderBy: { createdAt: 'desc' }, 48 | }); 49 | 50 | async function onCreatePost() { 51 | const name = prompt('Enter post name'); 52 | if (name) { 53 | await createPost({ data: { name } }); 54 | } 55 | } 56 | 57 | async function onTogglePublished(post: Post) { 58 | await updatePost({ 59 | where: { id: post.id }, 60 | data: { published: !post.published }, 61 | }); 62 | } 63 | 64 | async function onDelete(post: Post) { 65 | await deletePost({ where: { id: post.id } }); 66 | } 67 | 68 | return ( 69 |
70 | 73 | 74 |
    75 | {posts?.map((post) => ( 76 |
  • 77 |

    78 | {post.name} 79 | by {post.createdBy.email} 80 |

    81 |
    82 | 85 | 88 |
    89 |
  • 90 | ))} 91 |
92 |
93 | ); 94 | }; 95 | 96 | const Home: NextPage = () => { 97 | const { data: session, status } = useSession(); 98 | 99 | if (status === 'loading') return

Loading ...

; 100 | 101 | return ( 102 |
103 |
104 |

My Awesome Blog

105 | 106 | {session?.user ? ( 107 | // welcome & blog posts 108 |
109 | 110 |
111 | 112 |
113 |
114 | ) : ( 115 | // if not logged in 116 | 117 | )} 118 |
119 |
120 | ); 121 | }; 122 | 123 | export default Home; 124 | -------------------------------------------------------------------------------- /src/lib/hooks/__model_meta.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * This file was generated by ZenStack CLI. 3 | ******************************************************************************/ 4 | 5 | /* eslint-disable */ 6 | // @ts-nocheck 7 | 8 | const metadata = { 9 | models: { 10 | post: { 11 | name: 'Post', fields: { 12 | id: { 13 | name: "id", 14 | type: "Int", 15 | isId: true, 16 | attributes: [{ "name": "@default", "args": [] }], 17 | isAutoIncrement: true, 18 | }, name: { 19 | name: "name", 20 | type: "String", 21 | }, createdAt: { 22 | name: "createdAt", 23 | type: "DateTime", 24 | attributes: [{ "name": "@default", "args": [] }], 25 | }, updatedAt: { 26 | name: "updatedAt", 27 | type: "DateTime", 28 | attributes: [{ "name": "@updatedAt", "args": [] }], 29 | }, published: { 30 | name: "published", 31 | type: "Boolean", 32 | attributes: [{ "name": "@default", "args": [{ "value": false }] }], 33 | }, createdBy: { 34 | name: "createdBy", 35 | type: "User", 36 | isDataModel: true, 37 | backLink: 'posts', 38 | isRelationOwner: true, 39 | foreignKeyMapping: { "id": "createdById" }, 40 | }, createdById: { 41 | name: "createdById", 42 | type: "String", 43 | attributes: [{ "name": "@default", "args": [] }], 44 | defaultValueProvider: $default$Post$createdById, 45 | isForeignKey: true, 46 | relationField: 'createdBy', 47 | }, 48 | }, uniqueConstraints: { 49 | id: { 50 | name: "id", 51 | fields: ["id"] 52 | }, 53 | }, 54 | }, 55 | account: { 56 | name: 'Account', fields: { 57 | id: { 58 | name: "id", 59 | type: "String", 60 | isId: true, 61 | attributes: [{ "name": "@default", "args": [] }], 62 | }, userId: { 63 | name: "userId", 64 | type: "String", 65 | isForeignKey: true, 66 | relationField: 'user', 67 | }, type: { 68 | name: "type", 69 | type: "String", 70 | }, provider: { 71 | name: "provider", 72 | type: "String", 73 | }, providerAccountId: { 74 | name: "providerAccountId", 75 | type: "String", 76 | }, refresh_token: { 77 | name: "refresh_token", 78 | type: "String", 79 | isOptional: true, 80 | }, access_token: { 81 | name: "access_token", 82 | type: "String", 83 | isOptional: true, 84 | }, expires_at: { 85 | name: "expires_at", 86 | type: "Int", 87 | isOptional: true, 88 | }, token_type: { 89 | name: "token_type", 90 | type: "String", 91 | isOptional: true, 92 | }, scope: { 93 | name: "scope", 94 | type: "String", 95 | isOptional: true, 96 | }, id_token: { 97 | name: "id_token", 98 | type: "String", 99 | isOptional: true, 100 | }, session_state: { 101 | name: "session_state", 102 | type: "String", 103 | isOptional: true, 104 | }, user: { 105 | name: "user", 106 | type: "User", 107 | isDataModel: true, 108 | backLink: 'accounts', 109 | isRelationOwner: true, 110 | onDeleteAction: 'Cascade', 111 | foreignKeyMapping: { "id": "userId" }, 112 | }, refresh_token_expires_in: { 113 | name: "refresh_token_expires_in", 114 | type: "Int", 115 | isOptional: true, 116 | }, 117 | }, uniqueConstraints: { 118 | id: { 119 | name: "id", 120 | fields: ["id"] 121 | }, provider_providerAccountId: { 122 | name: "provider_providerAccountId", 123 | fields: ["provider", "providerAccountId"] 124 | }, 125 | }, 126 | }, 127 | session: { 128 | name: 'Session', fields: { 129 | id: { 130 | name: "id", 131 | type: "String", 132 | isId: true, 133 | attributes: [{ "name": "@default", "args": [] }], 134 | }, sessionToken: { 135 | name: "sessionToken", 136 | type: "String", 137 | }, userId: { 138 | name: "userId", 139 | type: "String", 140 | isForeignKey: true, 141 | relationField: 'user', 142 | }, expires: { 143 | name: "expires", 144 | type: "DateTime", 145 | }, user: { 146 | name: "user", 147 | type: "User", 148 | isDataModel: true, 149 | backLink: 'sessions', 150 | isRelationOwner: true, 151 | onDeleteAction: 'Cascade', 152 | foreignKeyMapping: { "id": "userId" }, 153 | }, 154 | }, uniqueConstraints: { 155 | id: { 156 | name: "id", 157 | fields: ["id"] 158 | }, sessionToken: { 159 | name: "sessionToken", 160 | fields: ["sessionToken"] 161 | }, 162 | }, 163 | }, 164 | user: { 165 | name: 'User', fields: { 166 | id: { 167 | name: "id", 168 | type: "String", 169 | isId: true, 170 | attributes: [{ "name": "@default", "args": [] }], 171 | }, name: { 172 | name: "name", 173 | type: "String", 174 | isOptional: true, 175 | }, email: { 176 | name: "email", 177 | type: "String", 178 | isOptional: true, 179 | }, emailVerified: { 180 | name: "emailVerified", 181 | type: "DateTime", 182 | isOptional: true, 183 | }, image: { 184 | name: "image", 185 | type: "String", 186 | isOptional: true, 187 | }, password: { 188 | name: "password", 189 | type: "String", 190 | }, accounts: { 191 | name: "accounts", 192 | type: "Account", 193 | isDataModel: true, 194 | isArray: true, 195 | backLink: 'user', 196 | }, sessions: { 197 | name: "sessions", 198 | type: "Session", 199 | isDataModel: true, 200 | isArray: true, 201 | backLink: 'user', 202 | }, posts: { 203 | name: "posts", 204 | type: "Post", 205 | isDataModel: true, 206 | isArray: true, 207 | backLink: 'createdBy', 208 | }, 209 | }, uniqueConstraints: { 210 | id: { 211 | name: "id", 212 | fields: ["id"] 213 | }, email: { 214 | name: "email", 215 | fields: ["email"] 216 | }, 217 | }, 218 | }, 219 | verificationToken: { 220 | name: 'VerificationToken', fields: { 221 | identifier: { 222 | name: "identifier", 223 | type: "String", 224 | }, token: { 225 | name: "token", 226 | type: "String", 227 | isId: true, 228 | }, expires: { 229 | name: "expires", 230 | type: "DateTime", 231 | }, 232 | }, uniqueConstraints: { 233 | token: { 234 | name: "token", 235 | fields: ["token"] 236 | }, identifier_token: { 237 | name: "identifier_token", 238 | fields: ["identifier", "token"] 239 | }, 240 | }, 241 | }, 242 | 243 | }, 244 | deleteCascade: { 245 | user: ['Account', 'Session'], 246 | 247 | }, 248 | authModel: 'User' 249 | 250 | }; 251 | 252 | function $default$Post$createdById(user: any): unknown { 253 | return user?.id; 254 | } 255 | export default metadata; 256 | -------------------------------------------------------------------------------- /src/lib/hooks/post.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * This file was generated by ZenStack CLI. 3 | ******************************************************************************/ 4 | 5 | /* eslint-disable */ 6 | // @ts-nocheck 7 | 8 | import type { Prisma, Post } from "@zenstackhq/runtime/models"; 9 | import type { UseMutationOptions, UseQueryOptions, UseInfiniteQueryOptions, InfiniteData } from '@tanstack/react-query'; 10 | import { getHooksContext } from '@zenstackhq/tanstack-query/runtime-v5/react'; 11 | import { useModelQuery, useInfiniteModelQuery, useModelMutation } from '@zenstackhq/tanstack-query/runtime-v5/react'; 12 | import type { PickEnumerable, CheckSelect, QueryError, ExtraQueryOptions, ExtraMutationOptions } from '@zenstackhq/tanstack-query/runtime-v5'; 13 | import type { PolicyCrudKind } from '@zenstackhq/runtime' 14 | import metadata from './__model_meta'; 15 | type DefaultError = QueryError; 16 | import { useSuspenseModelQuery, useSuspenseInfiniteModelQuery } from '@zenstackhq/tanstack-query/runtime-v5/react'; 17 | import type { UseSuspenseQueryOptions, UseSuspenseInfiniteQueryOptions } from '@tanstack/react-query'; 18 | 19 | export function useCreatePost(options?: Omit<(UseMutationOptions<(Post | undefined), DefaultError, Prisma.PostCreateArgs> & ExtraMutationOptions), 'mutationFn'>) { 20 | const { endpoint, fetch } = getHooksContext(); 21 | const _mutation = 22 | useModelMutation('Post', 'POST', `${endpoint}/post/create`, metadata, options, fetch, true) 23 | ; 24 | const mutation = { 25 | ..._mutation, 26 | mutateAsync: async ( 27 | args: Prisma.SelectSubset, 28 | options?: Omit<(UseMutationOptions<(CheckSelect> | undefined), DefaultError, Prisma.SelectSubset> & ExtraMutationOptions), 'mutationFn'> 29 | ) => { 30 | return (await _mutation.mutateAsync( 31 | args, 32 | options as any 33 | )) as (CheckSelect> | undefined); 34 | }, 35 | }; 36 | return mutation; 37 | } 38 | 39 | export function useCreateManyPost(options?: Omit<(UseMutationOptions & ExtraMutationOptions), 'mutationFn'>) { 40 | const { endpoint, fetch } = getHooksContext(); 41 | const _mutation = 42 | useModelMutation('Post', 'POST', `${endpoint}/post/createMany`, metadata, options, fetch, false) 43 | ; 44 | const mutation = { 45 | ..._mutation, 46 | mutateAsync: async ( 47 | args: Prisma.SelectSubset, 48 | options?: Omit<(UseMutationOptions> & ExtraMutationOptions), 'mutationFn'> 49 | ) => { 50 | return (await _mutation.mutateAsync( 51 | args, 52 | options as any 53 | )) as Prisma.BatchPayload; 54 | }, 55 | }; 56 | return mutation; 57 | } 58 | 59 | export function useFindManyPost & { $optimistic?: boolean }>, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 60 | const { endpoint, fetch } = getHooksContext(); 61 | return useModelQuery('Post', `${endpoint}/post/findMany`, args, options, fetch); 62 | } 63 | 64 | export function useInfiniteFindManyPost>, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: Omit>, 'queryKey' | 'initialPageParam'>) { 65 | options = options ?? { getNextPageParam: () => null }; 66 | const { endpoint, fetch } = getHooksContext(); 67 | return useInfiniteModelQuery('Post', `${endpoint}/post/findMany`, args, options, fetch); 68 | } 69 | 70 | export function useSuspenseFindManyPost & { $optimistic?: boolean }>, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 71 | const { endpoint, fetch } = getHooksContext(); 72 | return useSuspenseModelQuery('Post', `${endpoint}/post/findMany`, args, options, fetch); 73 | } 74 | 75 | export function useSuspenseInfiniteFindManyPost>, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: Omit>, 'queryKey' | 'initialPageParam'>) { 76 | options = options ?? { getNextPageParam: () => null }; 77 | const { endpoint, fetch } = getHooksContext(); 78 | return useSuspenseInfiniteModelQuery('Post', `${endpoint}/post/findMany`, args, options, fetch); 79 | } 80 | 81 | export function useFindUniquePost & { $optimistic?: boolean }, TData = TQueryFnData, TError = DefaultError>(args: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 82 | const { endpoint, fetch } = getHooksContext(); 83 | return useModelQuery('Post', `${endpoint}/post/findUnique`, args, options, fetch); 84 | } 85 | 86 | export function useSuspenseFindUniquePost & { $optimistic?: boolean }, TData = TQueryFnData, TError = DefaultError>(args: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 87 | const { endpoint, fetch } = getHooksContext(); 88 | return useSuspenseModelQuery('Post', `${endpoint}/post/findUnique`, args, options, fetch); 89 | } 90 | 91 | export function useFindFirstPost & { $optimistic?: boolean }, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 92 | const { endpoint, fetch } = getHooksContext(); 93 | return useModelQuery('Post', `${endpoint}/post/findFirst`, args, options, fetch); 94 | } 95 | 96 | export function useSuspenseFindFirstPost & { $optimistic?: boolean }, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 97 | const { endpoint, fetch } = getHooksContext(); 98 | return useSuspenseModelQuery('Post', `${endpoint}/post/findFirst`, args, options, fetch); 99 | } 100 | 101 | export function useUpdatePost(options?: Omit<(UseMutationOptions<(Post | undefined), DefaultError, Prisma.PostUpdateArgs> & ExtraMutationOptions), 'mutationFn'>) { 102 | const { endpoint, fetch } = getHooksContext(); 103 | const _mutation = 104 | useModelMutation('Post', 'PUT', `${endpoint}/post/update`, metadata, options, fetch, true) 105 | ; 106 | const mutation = { 107 | ..._mutation, 108 | mutateAsync: async ( 109 | args: Prisma.SelectSubset, 110 | options?: Omit<(UseMutationOptions<(CheckSelect> | undefined), DefaultError, Prisma.SelectSubset> & ExtraMutationOptions), 'mutationFn'> 111 | ) => { 112 | return (await _mutation.mutateAsync( 113 | args, 114 | options as any 115 | )) as (CheckSelect> | undefined); 116 | }, 117 | }; 118 | return mutation; 119 | } 120 | 121 | export function useUpdateManyPost(options?: Omit<(UseMutationOptions & ExtraMutationOptions), 'mutationFn'>) { 122 | const { endpoint, fetch } = getHooksContext(); 123 | const _mutation = 124 | useModelMutation('Post', 'PUT', `${endpoint}/post/updateMany`, metadata, options, fetch, false) 125 | ; 126 | const mutation = { 127 | ..._mutation, 128 | mutateAsync: async ( 129 | args: Prisma.SelectSubset, 130 | options?: Omit<(UseMutationOptions> & ExtraMutationOptions), 'mutationFn'> 131 | ) => { 132 | return (await _mutation.mutateAsync( 133 | args, 134 | options as any 135 | )) as Prisma.BatchPayload; 136 | }, 137 | }; 138 | return mutation; 139 | } 140 | 141 | export function useUpsertPost(options?: Omit<(UseMutationOptions<(Post | undefined), DefaultError, Prisma.PostUpsertArgs> & ExtraMutationOptions), 'mutationFn'>) { 142 | const { endpoint, fetch } = getHooksContext(); 143 | const _mutation = 144 | useModelMutation('Post', 'POST', `${endpoint}/post/upsert`, metadata, options, fetch, true) 145 | ; 146 | const mutation = { 147 | ..._mutation, 148 | mutateAsync: async ( 149 | args: Prisma.SelectSubset, 150 | options?: Omit<(UseMutationOptions<(CheckSelect> | undefined), DefaultError, Prisma.SelectSubset> & ExtraMutationOptions), 'mutationFn'> 151 | ) => { 152 | return (await _mutation.mutateAsync( 153 | args, 154 | options as any 155 | )) as (CheckSelect> | undefined); 156 | }, 157 | }; 158 | return mutation; 159 | } 160 | 161 | export function useDeletePost(options?: Omit<(UseMutationOptions<(Post | undefined), DefaultError, Prisma.PostDeleteArgs> & ExtraMutationOptions), 'mutationFn'>) { 162 | const { endpoint, fetch } = getHooksContext(); 163 | const _mutation = 164 | useModelMutation('Post', 'DELETE', `${endpoint}/post/delete`, metadata, options, fetch, true) 165 | ; 166 | const mutation = { 167 | ..._mutation, 168 | mutateAsync: async ( 169 | args: Prisma.SelectSubset, 170 | options?: Omit<(UseMutationOptions<(CheckSelect> | undefined), DefaultError, Prisma.SelectSubset> & ExtraMutationOptions), 'mutationFn'> 171 | ) => { 172 | return (await _mutation.mutateAsync( 173 | args, 174 | options as any 175 | )) as (CheckSelect> | undefined); 176 | }, 177 | }; 178 | return mutation; 179 | } 180 | 181 | export function useDeleteManyPost(options?: Omit<(UseMutationOptions & ExtraMutationOptions), 'mutationFn'>) { 182 | const { endpoint, fetch } = getHooksContext(); 183 | const _mutation = 184 | useModelMutation('Post', 'DELETE', `${endpoint}/post/deleteMany`, metadata, options, fetch, false) 185 | ; 186 | const mutation = { 187 | ..._mutation, 188 | mutateAsync: async ( 189 | args: Prisma.SelectSubset, 190 | options?: Omit<(UseMutationOptions> & ExtraMutationOptions), 'mutationFn'> 191 | ) => { 192 | return (await _mutation.mutateAsync( 193 | args, 194 | options as any 195 | )) as Prisma.BatchPayload; 196 | }, 197 | }; 198 | return mutation; 199 | } 200 | 201 | export function useAggregatePost, TData = TQueryFnData, TError = DefaultError>(args: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 202 | const { endpoint, fetch } = getHooksContext(); 203 | return useModelQuery('Post', `${endpoint}/post/aggregate`, args, options, fetch); 204 | } 205 | 206 | export function useSuspenseAggregatePost, TData = TQueryFnData, TError = DefaultError>(args: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 207 | const { endpoint, fetch } = getHooksContext(); 208 | return useSuspenseModelQuery('Post', `${endpoint}/post/aggregate`, args, options, fetch); 209 | } 210 | 211 | export function useGroupByPost>, Prisma.Extends<'take', Prisma.Keys>>, OrderByArg extends Prisma.True extends HasSelectOrTake ? { orderBy: Prisma.PostGroupByArgs['orderBy'] } : { orderBy?: Prisma.PostGroupByArgs['orderBy'] }, OrderFields extends Prisma.ExcludeUnderscoreKeys>>, ByFields extends Prisma.MaybeTupleToUnion, ByValid extends Prisma.Has, HavingFields extends Prisma.GetHavingFields, HavingValid extends Prisma.Has, ByEmpty extends TArgs['by'] extends never[] ? Prisma.True : Prisma.False, InputErrors extends ByEmpty extends Prisma.True 212 | ? `Error: "by" must not be empty.` 213 | : HavingValid extends Prisma.False 214 | ? { 215 | [P in HavingFields]: P extends ByFields 216 | ? never 217 | : P extends string 218 | ? `Error: Field "${P}" used in "having" needs to be provided in "by".` 219 | : [ 220 | Error, 221 | 'Field ', 222 | P, 223 | ` in "having" needs to be provided in "by"`, 224 | ] 225 | }[HavingFields] 226 | : 'take' extends Prisma.Keys 227 | ? 'orderBy' extends Prisma.Keys 228 | ? ByValid extends Prisma.True 229 | ? {} 230 | : { 231 | [P in OrderFields]: P extends ByFields 232 | ? never 233 | : `Error: Field "${P}" in "orderBy" needs to be provided in "by"` 234 | }[OrderFields] 235 | : 'Error: If you provide "take", you also need to provide "orderBy"' 236 | : 'skip' extends Prisma.Keys 237 | ? 'orderBy' extends Prisma.Keys 238 | ? ByValid extends Prisma.True 239 | ? {} 240 | : { 241 | [P in OrderFields]: P extends ByFields 242 | ? never 243 | : `Error: Field "${P}" in "orderBy" needs to be provided in "by"` 244 | }[OrderFields] 245 | : 'Error: If you provide "skip", you also need to provide "orderBy"' 246 | : ByValid extends Prisma.True 247 | ? {} 248 | : { 249 | [P in OrderFields]: P extends ByFields 250 | ? never 251 | : `Error: Field "${P}" in "orderBy" needs to be provided in "by"` 252 | }[OrderFields], TQueryFnData = {} extends InputErrors ? 253 | Array & 254 | { 255 | [P in ((keyof TArgs) & (keyof Prisma.PostGroupByOutputType))]: P extends '_count' 256 | ? TArgs[P] extends boolean 257 | ? number 258 | : Prisma.GetScalarType 259 | : Prisma.GetScalarType 260 | } 261 | > : InputErrors, TData = TQueryFnData, TError = DefaultError>(args: Prisma.SelectSubset & InputErrors>, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 262 | const { endpoint, fetch } = getHooksContext(); 263 | return useModelQuery('Post', `${endpoint}/post/groupBy`, args, options, fetch); 264 | } 265 | 266 | export function useSuspenseGroupByPost>, Prisma.Extends<'take', Prisma.Keys>>, OrderByArg extends Prisma.True extends HasSelectOrTake ? { orderBy: Prisma.PostGroupByArgs['orderBy'] } : { orderBy?: Prisma.PostGroupByArgs['orderBy'] }, OrderFields extends Prisma.ExcludeUnderscoreKeys>>, ByFields extends Prisma.MaybeTupleToUnion, ByValid extends Prisma.Has, HavingFields extends Prisma.GetHavingFields, HavingValid extends Prisma.Has, ByEmpty extends TArgs['by'] extends never[] ? Prisma.True : Prisma.False, InputErrors extends ByEmpty extends Prisma.True 267 | ? `Error: "by" must not be empty.` 268 | : HavingValid extends Prisma.False 269 | ? { 270 | [P in HavingFields]: P extends ByFields 271 | ? never 272 | : P extends string 273 | ? `Error: Field "${P}" used in "having" needs to be provided in "by".` 274 | : [ 275 | Error, 276 | 'Field ', 277 | P, 278 | ` in "having" needs to be provided in "by"`, 279 | ] 280 | }[HavingFields] 281 | : 'take' extends Prisma.Keys 282 | ? 'orderBy' extends Prisma.Keys 283 | ? ByValid extends Prisma.True 284 | ? {} 285 | : { 286 | [P in OrderFields]: P extends ByFields 287 | ? never 288 | : `Error: Field "${P}" in "orderBy" needs to be provided in "by"` 289 | }[OrderFields] 290 | : 'Error: If you provide "take", you also need to provide "orderBy"' 291 | : 'skip' extends Prisma.Keys 292 | ? 'orderBy' extends Prisma.Keys 293 | ? ByValid extends Prisma.True 294 | ? {} 295 | : { 296 | [P in OrderFields]: P extends ByFields 297 | ? never 298 | : `Error: Field "${P}" in "orderBy" needs to be provided in "by"` 299 | }[OrderFields] 300 | : 'Error: If you provide "skip", you also need to provide "orderBy"' 301 | : ByValid extends Prisma.True 302 | ? {} 303 | : { 304 | [P in OrderFields]: P extends ByFields 305 | ? never 306 | : `Error: Field "${P}" in "orderBy" needs to be provided in "by"` 307 | }[OrderFields], TQueryFnData = {} extends InputErrors ? 308 | Array & 309 | { 310 | [P in ((keyof TArgs) & (keyof Prisma.PostGroupByOutputType))]: P extends '_count' 311 | ? TArgs[P] extends boolean 312 | ? number 313 | : Prisma.GetScalarType 314 | : Prisma.GetScalarType 315 | } 316 | > : InputErrors, TData = TQueryFnData, TError = DefaultError>(args: Prisma.SelectSubset & InputErrors>, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 317 | const { endpoint, fetch } = getHooksContext(); 318 | return useSuspenseModelQuery('Post', `${endpoint}/post/groupBy`, args, options, fetch); 319 | } 320 | 321 | export function useCountPost : number, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 322 | const { endpoint, fetch } = getHooksContext(); 323 | return useModelQuery('Post', `${endpoint}/post/count`, args, options, fetch); 324 | } 325 | 326 | export function useSuspenseCountPost : number, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 327 | const { endpoint, fetch } = getHooksContext(); 328 | return useSuspenseModelQuery('Post', `${endpoint}/post/count`, args, options, fetch); 329 | } 330 | 331 | export function useCheckPost(args: { operation: PolicyCrudKind; where?: { id?: number; name?: string; published?: boolean; createdById?: string }; }, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 332 | const { endpoint, fetch } = getHooksContext(); 333 | return useModelQuery('Post', `${endpoint}/post/check`, args, options, fetch); 334 | } 335 | -------------------------------------------------------------------------------- /src/lib/hooks/user.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * This file was generated by ZenStack CLI. 3 | ******************************************************************************/ 4 | 5 | /* eslint-disable */ 6 | // @ts-nocheck 7 | 8 | import type { Prisma, User } from "@zenstackhq/runtime/models"; 9 | import type { UseMutationOptions, UseQueryOptions, UseInfiniteQueryOptions, InfiniteData } from '@tanstack/react-query'; 10 | import { getHooksContext } from '@zenstackhq/tanstack-query/runtime-v5/react'; 11 | import { useModelQuery, useInfiniteModelQuery, useModelMutation } from '@zenstackhq/tanstack-query/runtime-v5/react'; 12 | import type { PickEnumerable, CheckSelect, QueryError, ExtraQueryOptions, ExtraMutationOptions } from '@zenstackhq/tanstack-query/runtime-v5'; 13 | import type { PolicyCrudKind } from '@zenstackhq/runtime' 14 | import metadata from './__model_meta'; 15 | type DefaultError = QueryError; 16 | import { useSuspenseModelQuery, useSuspenseInfiniteModelQuery } from '@zenstackhq/tanstack-query/runtime-v5/react'; 17 | import type { UseSuspenseQueryOptions, UseSuspenseInfiniteQueryOptions } from '@tanstack/react-query'; 18 | 19 | export function useCreateUser(options?: Omit<(UseMutationOptions<(User | undefined), DefaultError, Prisma.UserCreateArgs> & ExtraMutationOptions), 'mutationFn'>) { 20 | const { endpoint, fetch } = getHooksContext(); 21 | const _mutation = 22 | useModelMutation('User', 'POST', `${endpoint}/user/create`, metadata, options, fetch, true) 23 | ; 24 | const mutation = { 25 | ..._mutation, 26 | mutateAsync: async ( 27 | args: Prisma.SelectSubset, 28 | options?: Omit<(UseMutationOptions<(CheckSelect> | undefined), DefaultError, Prisma.SelectSubset> & ExtraMutationOptions), 'mutationFn'> 29 | ) => { 30 | return (await _mutation.mutateAsync( 31 | args, 32 | options as any 33 | )) as (CheckSelect> | undefined); 34 | }, 35 | }; 36 | return mutation; 37 | } 38 | 39 | export function useCreateManyUser(options?: Omit<(UseMutationOptions & ExtraMutationOptions), 'mutationFn'>) { 40 | const { endpoint, fetch } = getHooksContext(); 41 | const _mutation = 42 | useModelMutation('User', 'POST', `${endpoint}/user/createMany`, metadata, options, fetch, false) 43 | ; 44 | const mutation = { 45 | ..._mutation, 46 | mutateAsync: async ( 47 | args: Prisma.SelectSubset, 48 | options?: Omit<(UseMutationOptions> & ExtraMutationOptions), 'mutationFn'> 49 | ) => { 50 | return (await _mutation.mutateAsync( 51 | args, 52 | options as any 53 | )) as Prisma.BatchPayload; 54 | }, 55 | }; 56 | return mutation; 57 | } 58 | 59 | export function useFindManyUser & { $optimistic?: boolean }>, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 60 | const { endpoint, fetch } = getHooksContext(); 61 | return useModelQuery('User', `${endpoint}/user/findMany`, args, options, fetch); 62 | } 63 | 64 | export function useInfiniteFindManyUser>, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: Omit>, 'queryKey' | 'initialPageParam'>) { 65 | options = options ?? { getNextPageParam: () => null }; 66 | const { endpoint, fetch } = getHooksContext(); 67 | return useInfiniteModelQuery('User', `${endpoint}/user/findMany`, args, options, fetch); 68 | } 69 | 70 | export function useSuspenseFindManyUser & { $optimistic?: boolean }>, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 71 | const { endpoint, fetch } = getHooksContext(); 72 | return useSuspenseModelQuery('User', `${endpoint}/user/findMany`, args, options, fetch); 73 | } 74 | 75 | export function useSuspenseInfiniteFindManyUser>, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: Omit>, 'queryKey' | 'initialPageParam'>) { 76 | options = options ?? { getNextPageParam: () => null }; 77 | const { endpoint, fetch } = getHooksContext(); 78 | return useSuspenseInfiniteModelQuery('User', `${endpoint}/user/findMany`, args, options, fetch); 79 | } 80 | 81 | export function useFindUniqueUser & { $optimistic?: boolean }, TData = TQueryFnData, TError = DefaultError>(args: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 82 | const { endpoint, fetch } = getHooksContext(); 83 | return useModelQuery('User', `${endpoint}/user/findUnique`, args, options, fetch); 84 | } 85 | 86 | export function useSuspenseFindUniqueUser & { $optimistic?: boolean }, TData = TQueryFnData, TError = DefaultError>(args: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 87 | const { endpoint, fetch } = getHooksContext(); 88 | return useSuspenseModelQuery('User', `${endpoint}/user/findUnique`, args, options, fetch); 89 | } 90 | 91 | export function useFindFirstUser & { $optimistic?: boolean }, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 92 | const { endpoint, fetch } = getHooksContext(); 93 | return useModelQuery('User', `${endpoint}/user/findFirst`, args, options, fetch); 94 | } 95 | 96 | export function useSuspenseFindFirstUser & { $optimistic?: boolean }, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 97 | const { endpoint, fetch } = getHooksContext(); 98 | return useSuspenseModelQuery('User', `${endpoint}/user/findFirst`, args, options, fetch); 99 | } 100 | 101 | export function useUpdateUser(options?: Omit<(UseMutationOptions<(User | undefined), DefaultError, Prisma.UserUpdateArgs> & ExtraMutationOptions), 'mutationFn'>) { 102 | const { endpoint, fetch } = getHooksContext(); 103 | const _mutation = 104 | useModelMutation('User', 'PUT', `${endpoint}/user/update`, metadata, options, fetch, true) 105 | ; 106 | const mutation = { 107 | ..._mutation, 108 | mutateAsync: async ( 109 | args: Prisma.SelectSubset, 110 | options?: Omit<(UseMutationOptions<(CheckSelect> | undefined), DefaultError, Prisma.SelectSubset> & ExtraMutationOptions), 'mutationFn'> 111 | ) => { 112 | return (await _mutation.mutateAsync( 113 | args, 114 | options as any 115 | )) as (CheckSelect> | undefined); 116 | }, 117 | }; 118 | return mutation; 119 | } 120 | 121 | export function useUpdateManyUser(options?: Omit<(UseMutationOptions & ExtraMutationOptions), 'mutationFn'>) { 122 | const { endpoint, fetch } = getHooksContext(); 123 | const _mutation = 124 | useModelMutation('User', 'PUT', `${endpoint}/user/updateMany`, metadata, options, fetch, false) 125 | ; 126 | const mutation = { 127 | ..._mutation, 128 | mutateAsync: async ( 129 | args: Prisma.SelectSubset, 130 | options?: Omit<(UseMutationOptions> & ExtraMutationOptions), 'mutationFn'> 131 | ) => { 132 | return (await _mutation.mutateAsync( 133 | args, 134 | options as any 135 | )) as Prisma.BatchPayload; 136 | }, 137 | }; 138 | return mutation; 139 | } 140 | 141 | export function useUpsertUser(options?: Omit<(UseMutationOptions<(User | undefined), DefaultError, Prisma.UserUpsertArgs> & ExtraMutationOptions), 'mutationFn'>) { 142 | const { endpoint, fetch } = getHooksContext(); 143 | const _mutation = 144 | useModelMutation('User', 'POST', `${endpoint}/user/upsert`, metadata, options, fetch, true) 145 | ; 146 | const mutation = { 147 | ..._mutation, 148 | mutateAsync: async ( 149 | args: Prisma.SelectSubset, 150 | options?: Omit<(UseMutationOptions<(CheckSelect> | undefined), DefaultError, Prisma.SelectSubset> & ExtraMutationOptions), 'mutationFn'> 151 | ) => { 152 | return (await _mutation.mutateAsync( 153 | args, 154 | options as any 155 | )) as (CheckSelect> | undefined); 156 | }, 157 | }; 158 | return mutation; 159 | } 160 | 161 | export function useDeleteUser(options?: Omit<(UseMutationOptions<(User | undefined), DefaultError, Prisma.UserDeleteArgs> & ExtraMutationOptions), 'mutationFn'>) { 162 | const { endpoint, fetch } = getHooksContext(); 163 | const _mutation = 164 | useModelMutation('User', 'DELETE', `${endpoint}/user/delete`, metadata, options, fetch, true) 165 | ; 166 | const mutation = { 167 | ..._mutation, 168 | mutateAsync: async ( 169 | args: Prisma.SelectSubset, 170 | options?: Omit<(UseMutationOptions<(CheckSelect> | undefined), DefaultError, Prisma.SelectSubset> & ExtraMutationOptions), 'mutationFn'> 171 | ) => { 172 | return (await _mutation.mutateAsync( 173 | args, 174 | options as any 175 | )) as (CheckSelect> | undefined); 176 | }, 177 | }; 178 | return mutation; 179 | } 180 | 181 | export function useDeleteManyUser(options?: Omit<(UseMutationOptions & ExtraMutationOptions), 'mutationFn'>) { 182 | const { endpoint, fetch } = getHooksContext(); 183 | const _mutation = 184 | useModelMutation('User', 'DELETE', `${endpoint}/user/deleteMany`, metadata, options, fetch, false) 185 | ; 186 | const mutation = { 187 | ..._mutation, 188 | mutateAsync: async ( 189 | args: Prisma.SelectSubset, 190 | options?: Omit<(UseMutationOptions> & ExtraMutationOptions), 'mutationFn'> 191 | ) => { 192 | return (await _mutation.mutateAsync( 193 | args, 194 | options as any 195 | )) as Prisma.BatchPayload; 196 | }, 197 | }; 198 | return mutation; 199 | } 200 | 201 | export function useAggregateUser, TData = TQueryFnData, TError = DefaultError>(args: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 202 | const { endpoint, fetch } = getHooksContext(); 203 | return useModelQuery('User', `${endpoint}/user/aggregate`, args, options, fetch); 204 | } 205 | 206 | export function useSuspenseAggregateUser, TData = TQueryFnData, TError = DefaultError>(args: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 207 | const { endpoint, fetch } = getHooksContext(); 208 | return useSuspenseModelQuery('User', `${endpoint}/user/aggregate`, args, options, fetch); 209 | } 210 | 211 | export function useGroupByUser>, Prisma.Extends<'take', Prisma.Keys>>, OrderByArg extends Prisma.True extends HasSelectOrTake ? { orderBy: Prisma.UserGroupByArgs['orderBy'] } : { orderBy?: Prisma.UserGroupByArgs['orderBy'] }, OrderFields extends Prisma.ExcludeUnderscoreKeys>>, ByFields extends Prisma.MaybeTupleToUnion, ByValid extends Prisma.Has, HavingFields extends Prisma.GetHavingFields, HavingValid extends Prisma.Has, ByEmpty extends TArgs['by'] extends never[] ? Prisma.True : Prisma.False, InputErrors extends ByEmpty extends Prisma.True 212 | ? `Error: "by" must not be empty.` 213 | : HavingValid extends Prisma.False 214 | ? { 215 | [P in HavingFields]: P extends ByFields 216 | ? never 217 | : P extends string 218 | ? `Error: Field "${P}" used in "having" needs to be provided in "by".` 219 | : [ 220 | Error, 221 | 'Field ', 222 | P, 223 | ` in "having" needs to be provided in "by"`, 224 | ] 225 | }[HavingFields] 226 | : 'take' extends Prisma.Keys 227 | ? 'orderBy' extends Prisma.Keys 228 | ? ByValid extends Prisma.True 229 | ? {} 230 | : { 231 | [P in OrderFields]: P extends ByFields 232 | ? never 233 | : `Error: Field "${P}" in "orderBy" needs to be provided in "by"` 234 | }[OrderFields] 235 | : 'Error: If you provide "take", you also need to provide "orderBy"' 236 | : 'skip' extends Prisma.Keys 237 | ? 'orderBy' extends Prisma.Keys 238 | ? ByValid extends Prisma.True 239 | ? {} 240 | : { 241 | [P in OrderFields]: P extends ByFields 242 | ? never 243 | : `Error: Field "${P}" in "orderBy" needs to be provided in "by"` 244 | }[OrderFields] 245 | : 'Error: If you provide "skip", you also need to provide "orderBy"' 246 | : ByValid extends Prisma.True 247 | ? {} 248 | : { 249 | [P in OrderFields]: P extends ByFields 250 | ? never 251 | : `Error: Field "${P}" in "orderBy" needs to be provided in "by"` 252 | }[OrderFields], TQueryFnData = {} extends InputErrors ? 253 | Array & 254 | { 255 | [P in ((keyof TArgs) & (keyof Prisma.UserGroupByOutputType))]: P extends '_count' 256 | ? TArgs[P] extends boolean 257 | ? number 258 | : Prisma.GetScalarType 259 | : Prisma.GetScalarType 260 | } 261 | > : InputErrors, TData = TQueryFnData, TError = DefaultError>(args: Prisma.SelectSubset & InputErrors>, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 262 | const { endpoint, fetch } = getHooksContext(); 263 | return useModelQuery('User', `${endpoint}/user/groupBy`, args, options, fetch); 264 | } 265 | 266 | export function useSuspenseGroupByUser>, Prisma.Extends<'take', Prisma.Keys>>, OrderByArg extends Prisma.True extends HasSelectOrTake ? { orderBy: Prisma.UserGroupByArgs['orderBy'] } : { orderBy?: Prisma.UserGroupByArgs['orderBy'] }, OrderFields extends Prisma.ExcludeUnderscoreKeys>>, ByFields extends Prisma.MaybeTupleToUnion, ByValid extends Prisma.Has, HavingFields extends Prisma.GetHavingFields, HavingValid extends Prisma.Has, ByEmpty extends TArgs['by'] extends never[] ? Prisma.True : Prisma.False, InputErrors extends ByEmpty extends Prisma.True 267 | ? `Error: "by" must not be empty.` 268 | : HavingValid extends Prisma.False 269 | ? { 270 | [P in HavingFields]: P extends ByFields 271 | ? never 272 | : P extends string 273 | ? `Error: Field "${P}" used in "having" needs to be provided in "by".` 274 | : [ 275 | Error, 276 | 'Field ', 277 | P, 278 | ` in "having" needs to be provided in "by"`, 279 | ] 280 | }[HavingFields] 281 | : 'take' extends Prisma.Keys 282 | ? 'orderBy' extends Prisma.Keys 283 | ? ByValid extends Prisma.True 284 | ? {} 285 | : { 286 | [P in OrderFields]: P extends ByFields 287 | ? never 288 | : `Error: Field "${P}" in "orderBy" needs to be provided in "by"` 289 | }[OrderFields] 290 | : 'Error: If you provide "take", you also need to provide "orderBy"' 291 | : 'skip' extends Prisma.Keys 292 | ? 'orderBy' extends Prisma.Keys 293 | ? ByValid extends Prisma.True 294 | ? {} 295 | : { 296 | [P in OrderFields]: P extends ByFields 297 | ? never 298 | : `Error: Field "${P}" in "orderBy" needs to be provided in "by"` 299 | }[OrderFields] 300 | : 'Error: If you provide "skip", you also need to provide "orderBy"' 301 | : ByValid extends Prisma.True 302 | ? {} 303 | : { 304 | [P in OrderFields]: P extends ByFields 305 | ? never 306 | : `Error: Field "${P}" in "orderBy" needs to be provided in "by"` 307 | }[OrderFields], TQueryFnData = {} extends InputErrors ? 308 | Array & 309 | { 310 | [P in ((keyof TArgs) & (keyof Prisma.UserGroupByOutputType))]: P extends '_count' 311 | ? TArgs[P] extends boolean 312 | ? number 313 | : Prisma.GetScalarType 314 | : Prisma.GetScalarType 315 | } 316 | > : InputErrors, TData = TQueryFnData, TError = DefaultError>(args: Prisma.SelectSubset & InputErrors>, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 317 | const { endpoint, fetch } = getHooksContext(); 318 | return useSuspenseModelQuery('User', `${endpoint}/user/groupBy`, args, options, fetch); 319 | } 320 | 321 | export function useCountUser : number, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 322 | const { endpoint, fetch } = getHooksContext(); 323 | return useModelQuery('User', `${endpoint}/user/count`, args, options, fetch); 324 | } 325 | 326 | export function useSuspenseCountUser : number, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 327 | const { endpoint, fetch } = getHooksContext(); 328 | return useSuspenseModelQuery('User', `${endpoint}/user/count`, args, options, fetch); 329 | } 330 | 331 | export function useCheckUser(args: { operation: PolicyCrudKind; where?: { id?: string; name?: string; email?: string; image?: string; password?: string }; }, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 332 | const { endpoint, fetch } = getHooksContext(); 333 | return useModelQuery('User', `${endpoint}/user/check`, args, options, fetch); 334 | } 335 | -------------------------------------------------------------------------------- /src/lib/hooks/session.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * This file was generated by ZenStack CLI. 3 | ******************************************************************************/ 4 | 5 | /* eslint-disable */ 6 | // @ts-nocheck 7 | 8 | import type { Prisma, Session } from "@zenstackhq/runtime/models"; 9 | import type { UseMutationOptions, UseQueryOptions, UseInfiniteQueryOptions, InfiniteData } from '@tanstack/react-query'; 10 | import { getHooksContext } from '@zenstackhq/tanstack-query/runtime-v5/react'; 11 | import { useModelQuery, useInfiniteModelQuery, useModelMutation } from '@zenstackhq/tanstack-query/runtime-v5/react'; 12 | import type { PickEnumerable, CheckSelect, QueryError, ExtraQueryOptions, ExtraMutationOptions } from '@zenstackhq/tanstack-query/runtime-v5'; 13 | import type { PolicyCrudKind } from '@zenstackhq/runtime' 14 | import metadata from './__model_meta'; 15 | type DefaultError = QueryError; 16 | import { useSuspenseModelQuery, useSuspenseInfiniteModelQuery } from '@zenstackhq/tanstack-query/runtime-v5/react'; 17 | import type { UseSuspenseQueryOptions, UseSuspenseInfiniteQueryOptions } from '@tanstack/react-query'; 18 | 19 | export function useCreateSession(options?: Omit<(UseMutationOptions<(Session | undefined), DefaultError, Prisma.SessionCreateArgs> & ExtraMutationOptions), 'mutationFn'>) { 20 | const { endpoint, fetch } = getHooksContext(); 21 | const _mutation = 22 | useModelMutation('Session', 'POST', `${endpoint}/session/create`, metadata, options, fetch, true) 23 | ; 24 | const mutation = { 25 | ..._mutation, 26 | mutateAsync: async ( 27 | args: Prisma.SelectSubset, 28 | options?: Omit<(UseMutationOptions<(CheckSelect> | undefined), DefaultError, Prisma.SelectSubset> & ExtraMutationOptions), 'mutationFn'> 29 | ) => { 30 | return (await _mutation.mutateAsync( 31 | args, 32 | options as any 33 | )) as (CheckSelect> | undefined); 34 | }, 35 | }; 36 | return mutation; 37 | } 38 | 39 | export function useCreateManySession(options?: Omit<(UseMutationOptions & ExtraMutationOptions), 'mutationFn'>) { 40 | const { endpoint, fetch } = getHooksContext(); 41 | const _mutation = 42 | useModelMutation('Session', 'POST', `${endpoint}/session/createMany`, metadata, options, fetch, false) 43 | ; 44 | const mutation = { 45 | ..._mutation, 46 | mutateAsync: async ( 47 | args: Prisma.SelectSubset, 48 | options?: Omit<(UseMutationOptions> & ExtraMutationOptions), 'mutationFn'> 49 | ) => { 50 | return (await _mutation.mutateAsync( 51 | args, 52 | options as any 53 | )) as Prisma.BatchPayload; 54 | }, 55 | }; 56 | return mutation; 57 | } 58 | 59 | export function useFindManySession & { $optimistic?: boolean }>, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 60 | const { endpoint, fetch } = getHooksContext(); 61 | return useModelQuery('Session', `${endpoint}/session/findMany`, args, options, fetch); 62 | } 63 | 64 | export function useInfiniteFindManySession>, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: Omit>, 'queryKey' | 'initialPageParam'>) { 65 | options = options ?? { getNextPageParam: () => null }; 66 | const { endpoint, fetch } = getHooksContext(); 67 | return useInfiniteModelQuery('Session', `${endpoint}/session/findMany`, args, options, fetch); 68 | } 69 | 70 | export function useSuspenseFindManySession & { $optimistic?: boolean }>, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 71 | const { endpoint, fetch } = getHooksContext(); 72 | return useSuspenseModelQuery('Session', `${endpoint}/session/findMany`, args, options, fetch); 73 | } 74 | 75 | export function useSuspenseInfiniteFindManySession>, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: Omit>, 'queryKey' | 'initialPageParam'>) { 76 | options = options ?? { getNextPageParam: () => null }; 77 | const { endpoint, fetch } = getHooksContext(); 78 | return useSuspenseInfiniteModelQuery('Session', `${endpoint}/session/findMany`, args, options, fetch); 79 | } 80 | 81 | export function useFindUniqueSession & { $optimistic?: boolean }, TData = TQueryFnData, TError = DefaultError>(args: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 82 | const { endpoint, fetch } = getHooksContext(); 83 | return useModelQuery('Session', `${endpoint}/session/findUnique`, args, options, fetch); 84 | } 85 | 86 | export function useSuspenseFindUniqueSession & { $optimistic?: boolean }, TData = TQueryFnData, TError = DefaultError>(args: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 87 | const { endpoint, fetch } = getHooksContext(); 88 | return useSuspenseModelQuery('Session', `${endpoint}/session/findUnique`, args, options, fetch); 89 | } 90 | 91 | export function useFindFirstSession & { $optimistic?: boolean }, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 92 | const { endpoint, fetch } = getHooksContext(); 93 | return useModelQuery('Session', `${endpoint}/session/findFirst`, args, options, fetch); 94 | } 95 | 96 | export function useSuspenseFindFirstSession & { $optimistic?: boolean }, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 97 | const { endpoint, fetch } = getHooksContext(); 98 | return useSuspenseModelQuery('Session', `${endpoint}/session/findFirst`, args, options, fetch); 99 | } 100 | 101 | export function useUpdateSession(options?: Omit<(UseMutationOptions<(Session | undefined), DefaultError, Prisma.SessionUpdateArgs> & ExtraMutationOptions), 'mutationFn'>) { 102 | const { endpoint, fetch } = getHooksContext(); 103 | const _mutation = 104 | useModelMutation('Session', 'PUT', `${endpoint}/session/update`, metadata, options, fetch, true) 105 | ; 106 | const mutation = { 107 | ..._mutation, 108 | mutateAsync: async ( 109 | args: Prisma.SelectSubset, 110 | options?: Omit<(UseMutationOptions<(CheckSelect> | undefined), DefaultError, Prisma.SelectSubset> & ExtraMutationOptions), 'mutationFn'> 111 | ) => { 112 | return (await _mutation.mutateAsync( 113 | args, 114 | options as any 115 | )) as (CheckSelect> | undefined); 116 | }, 117 | }; 118 | return mutation; 119 | } 120 | 121 | export function useUpdateManySession(options?: Omit<(UseMutationOptions & ExtraMutationOptions), 'mutationFn'>) { 122 | const { endpoint, fetch } = getHooksContext(); 123 | const _mutation = 124 | useModelMutation('Session', 'PUT', `${endpoint}/session/updateMany`, metadata, options, fetch, false) 125 | ; 126 | const mutation = { 127 | ..._mutation, 128 | mutateAsync: async ( 129 | args: Prisma.SelectSubset, 130 | options?: Omit<(UseMutationOptions> & ExtraMutationOptions), 'mutationFn'> 131 | ) => { 132 | return (await _mutation.mutateAsync( 133 | args, 134 | options as any 135 | )) as Prisma.BatchPayload; 136 | }, 137 | }; 138 | return mutation; 139 | } 140 | 141 | export function useUpsertSession(options?: Omit<(UseMutationOptions<(Session | undefined), DefaultError, Prisma.SessionUpsertArgs> & ExtraMutationOptions), 'mutationFn'>) { 142 | const { endpoint, fetch } = getHooksContext(); 143 | const _mutation = 144 | useModelMutation('Session', 'POST', `${endpoint}/session/upsert`, metadata, options, fetch, true) 145 | ; 146 | const mutation = { 147 | ..._mutation, 148 | mutateAsync: async ( 149 | args: Prisma.SelectSubset, 150 | options?: Omit<(UseMutationOptions<(CheckSelect> | undefined), DefaultError, Prisma.SelectSubset> & ExtraMutationOptions), 'mutationFn'> 151 | ) => { 152 | return (await _mutation.mutateAsync( 153 | args, 154 | options as any 155 | )) as (CheckSelect> | undefined); 156 | }, 157 | }; 158 | return mutation; 159 | } 160 | 161 | export function useDeleteSession(options?: Omit<(UseMutationOptions<(Session | undefined), DefaultError, Prisma.SessionDeleteArgs> & ExtraMutationOptions), 'mutationFn'>) { 162 | const { endpoint, fetch } = getHooksContext(); 163 | const _mutation = 164 | useModelMutation('Session', 'DELETE', `${endpoint}/session/delete`, metadata, options, fetch, true) 165 | ; 166 | const mutation = { 167 | ..._mutation, 168 | mutateAsync: async ( 169 | args: Prisma.SelectSubset, 170 | options?: Omit<(UseMutationOptions<(CheckSelect> | undefined), DefaultError, Prisma.SelectSubset> & ExtraMutationOptions), 'mutationFn'> 171 | ) => { 172 | return (await _mutation.mutateAsync( 173 | args, 174 | options as any 175 | )) as (CheckSelect> | undefined); 176 | }, 177 | }; 178 | return mutation; 179 | } 180 | 181 | export function useDeleteManySession(options?: Omit<(UseMutationOptions & ExtraMutationOptions), 'mutationFn'>) { 182 | const { endpoint, fetch } = getHooksContext(); 183 | const _mutation = 184 | useModelMutation('Session', 'DELETE', `${endpoint}/session/deleteMany`, metadata, options, fetch, false) 185 | ; 186 | const mutation = { 187 | ..._mutation, 188 | mutateAsync: async ( 189 | args: Prisma.SelectSubset, 190 | options?: Omit<(UseMutationOptions> & ExtraMutationOptions), 'mutationFn'> 191 | ) => { 192 | return (await _mutation.mutateAsync( 193 | args, 194 | options as any 195 | )) as Prisma.BatchPayload; 196 | }, 197 | }; 198 | return mutation; 199 | } 200 | 201 | export function useAggregateSession, TData = TQueryFnData, TError = DefaultError>(args: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 202 | const { endpoint, fetch } = getHooksContext(); 203 | return useModelQuery('Session', `${endpoint}/session/aggregate`, args, options, fetch); 204 | } 205 | 206 | export function useSuspenseAggregateSession, TData = TQueryFnData, TError = DefaultError>(args: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 207 | const { endpoint, fetch } = getHooksContext(); 208 | return useSuspenseModelQuery('Session', `${endpoint}/session/aggregate`, args, options, fetch); 209 | } 210 | 211 | export function useGroupBySession>, Prisma.Extends<'take', Prisma.Keys>>, OrderByArg extends Prisma.True extends HasSelectOrTake ? { orderBy: Prisma.SessionGroupByArgs['orderBy'] } : { orderBy?: Prisma.SessionGroupByArgs['orderBy'] }, OrderFields extends Prisma.ExcludeUnderscoreKeys>>, ByFields extends Prisma.MaybeTupleToUnion, ByValid extends Prisma.Has, HavingFields extends Prisma.GetHavingFields, HavingValid extends Prisma.Has, ByEmpty extends TArgs['by'] extends never[] ? Prisma.True : Prisma.False, InputErrors extends ByEmpty extends Prisma.True 212 | ? `Error: "by" must not be empty.` 213 | : HavingValid extends Prisma.False 214 | ? { 215 | [P in HavingFields]: P extends ByFields 216 | ? never 217 | : P extends string 218 | ? `Error: Field "${P}" used in "having" needs to be provided in "by".` 219 | : [ 220 | Error, 221 | 'Field ', 222 | P, 223 | ` in "having" needs to be provided in "by"`, 224 | ] 225 | }[HavingFields] 226 | : 'take' extends Prisma.Keys 227 | ? 'orderBy' extends Prisma.Keys 228 | ? ByValid extends Prisma.True 229 | ? {} 230 | : { 231 | [P in OrderFields]: P extends ByFields 232 | ? never 233 | : `Error: Field "${P}" in "orderBy" needs to be provided in "by"` 234 | }[OrderFields] 235 | : 'Error: If you provide "take", you also need to provide "orderBy"' 236 | : 'skip' extends Prisma.Keys 237 | ? 'orderBy' extends Prisma.Keys 238 | ? ByValid extends Prisma.True 239 | ? {} 240 | : { 241 | [P in OrderFields]: P extends ByFields 242 | ? never 243 | : `Error: Field "${P}" in "orderBy" needs to be provided in "by"` 244 | }[OrderFields] 245 | : 'Error: If you provide "skip", you also need to provide "orderBy"' 246 | : ByValid extends Prisma.True 247 | ? {} 248 | : { 249 | [P in OrderFields]: P extends ByFields 250 | ? never 251 | : `Error: Field "${P}" in "orderBy" needs to be provided in "by"` 252 | }[OrderFields], TQueryFnData = {} extends InputErrors ? 253 | Array & 254 | { 255 | [P in ((keyof TArgs) & (keyof Prisma.SessionGroupByOutputType))]: P extends '_count' 256 | ? TArgs[P] extends boolean 257 | ? number 258 | : Prisma.GetScalarType 259 | : Prisma.GetScalarType 260 | } 261 | > : InputErrors, TData = TQueryFnData, TError = DefaultError>(args: Prisma.SelectSubset & InputErrors>, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 262 | const { endpoint, fetch } = getHooksContext(); 263 | return useModelQuery('Session', `${endpoint}/session/groupBy`, args, options, fetch); 264 | } 265 | 266 | export function useSuspenseGroupBySession>, Prisma.Extends<'take', Prisma.Keys>>, OrderByArg extends Prisma.True extends HasSelectOrTake ? { orderBy: Prisma.SessionGroupByArgs['orderBy'] } : { orderBy?: Prisma.SessionGroupByArgs['orderBy'] }, OrderFields extends Prisma.ExcludeUnderscoreKeys>>, ByFields extends Prisma.MaybeTupleToUnion, ByValid extends Prisma.Has, HavingFields extends Prisma.GetHavingFields, HavingValid extends Prisma.Has, ByEmpty extends TArgs['by'] extends never[] ? Prisma.True : Prisma.False, InputErrors extends ByEmpty extends Prisma.True 267 | ? `Error: "by" must not be empty.` 268 | : HavingValid extends Prisma.False 269 | ? { 270 | [P in HavingFields]: P extends ByFields 271 | ? never 272 | : P extends string 273 | ? `Error: Field "${P}" used in "having" needs to be provided in "by".` 274 | : [ 275 | Error, 276 | 'Field ', 277 | P, 278 | ` in "having" needs to be provided in "by"`, 279 | ] 280 | }[HavingFields] 281 | : 'take' extends Prisma.Keys 282 | ? 'orderBy' extends Prisma.Keys 283 | ? ByValid extends Prisma.True 284 | ? {} 285 | : { 286 | [P in OrderFields]: P extends ByFields 287 | ? never 288 | : `Error: Field "${P}" in "orderBy" needs to be provided in "by"` 289 | }[OrderFields] 290 | : 'Error: If you provide "take", you also need to provide "orderBy"' 291 | : 'skip' extends Prisma.Keys 292 | ? 'orderBy' extends Prisma.Keys 293 | ? ByValid extends Prisma.True 294 | ? {} 295 | : { 296 | [P in OrderFields]: P extends ByFields 297 | ? never 298 | : `Error: Field "${P}" in "orderBy" needs to be provided in "by"` 299 | }[OrderFields] 300 | : 'Error: If you provide "skip", you also need to provide "orderBy"' 301 | : ByValid extends Prisma.True 302 | ? {} 303 | : { 304 | [P in OrderFields]: P extends ByFields 305 | ? never 306 | : `Error: Field "${P}" in "orderBy" needs to be provided in "by"` 307 | }[OrderFields], TQueryFnData = {} extends InputErrors ? 308 | Array & 309 | { 310 | [P in ((keyof TArgs) & (keyof Prisma.SessionGroupByOutputType))]: P extends '_count' 311 | ? TArgs[P] extends boolean 312 | ? number 313 | : Prisma.GetScalarType 314 | : Prisma.GetScalarType 315 | } 316 | > : InputErrors, TData = TQueryFnData, TError = DefaultError>(args: Prisma.SelectSubset & InputErrors>, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 317 | const { endpoint, fetch } = getHooksContext(); 318 | return useSuspenseModelQuery('Session', `${endpoint}/session/groupBy`, args, options, fetch); 319 | } 320 | 321 | export function useCountSession : number, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 322 | const { endpoint, fetch } = getHooksContext(); 323 | return useModelQuery('Session', `${endpoint}/session/count`, args, options, fetch); 324 | } 325 | 326 | export function useSuspenseCountSession : number, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 327 | const { endpoint, fetch } = getHooksContext(); 328 | return useSuspenseModelQuery('Session', `${endpoint}/session/count`, args, options, fetch); 329 | } 330 | 331 | export function useCheckSession(args: { operation: PolicyCrudKind; where?: { id?: string; sessionToken?: string; userId?: string }; }, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 332 | const { endpoint, fetch } = getHooksContext(); 333 | return useModelQuery('Session', `${endpoint}/session/check`, args, options, fetch); 334 | } 335 | -------------------------------------------------------------------------------- /src/lib/hooks/account.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * This file was generated by ZenStack CLI. 3 | ******************************************************************************/ 4 | 5 | /* eslint-disable */ 6 | // @ts-nocheck 7 | 8 | import type { Prisma, Account } from "@zenstackhq/runtime/models"; 9 | import type { UseMutationOptions, UseQueryOptions, UseInfiniteQueryOptions, InfiniteData } from '@tanstack/react-query'; 10 | import { getHooksContext } from '@zenstackhq/tanstack-query/runtime-v5/react'; 11 | import { useModelQuery, useInfiniteModelQuery, useModelMutation } from '@zenstackhq/tanstack-query/runtime-v5/react'; 12 | import type { PickEnumerable, CheckSelect, QueryError, ExtraQueryOptions, ExtraMutationOptions } from '@zenstackhq/tanstack-query/runtime-v5'; 13 | import type { PolicyCrudKind } from '@zenstackhq/runtime' 14 | import metadata from './__model_meta'; 15 | type DefaultError = QueryError; 16 | import { useSuspenseModelQuery, useSuspenseInfiniteModelQuery } from '@zenstackhq/tanstack-query/runtime-v5/react'; 17 | import type { UseSuspenseQueryOptions, UseSuspenseInfiniteQueryOptions } from '@tanstack/react-query'; 18 | 19 | export function useCreateAccount(options?: Omit<(UseMutationOptions<(Account | undefined), DefaultError, Prisma.AccountCreateArgs> & ExtraMutationOptions), 'mutationFn'>) { 20 | const { endpoint, fetch } = getHooksContext(); 21 | const _mutation = 22 | useModelMutation('Account', 'POST', `${endpoint}/account/create`, metadata, options, fetch, true) 23 | ; 24 | const mutation = { 25 | ..._mutation, 26 | mutateAsync: async ( 27 | args: Prisma.SelectSubset, 28 | options?: Omit<(UseMutationOptions<(CheckSelect> | undefined), DefaultError, Prisma.SelectSubset> & ExtraMutationOptions), 'mutationFn'> 29 | ) => { 30 | return (await _mutation.mutateAsync( 31 | args, 32 | options as any 33 | )) as (CheckSelect> | undefined); 34 | }, 35 | }; 36 | return mutation; 37 | } 38 | 39 | export function useCreateManyAccount(options?: Omit<(UseMutationOptions & ExtraMutationOptions), 'mutationFn'>) { 40 | const { endpoint, fetch } = getHooksContext(); 41 | const _mutation = 42 | useModelMutation('Account', 'POST', `${endpoint}/account/createMany`, metadata, options, fetch, false) 43 | ; 44 | const mutation = { 45 | ..._mutation, 46 | mutateAsync: async ( 47 | args: Prisma.SelectSubset, 48 | options?: Omit<(UseMutationOptions> & ExtraMutationOptions), 'mutationFn'> 49 | ) => { 50 | return (await _mutation.mutateAsync( 51 | args, 52 | options as any 53 | )) as Prisma.BatchPayload; 54 | }, 55 | }; 56 | return mutation; 57 | } 58 | 59 | export function useFindManyAccount & { $optimistic?: boolean }>, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 60 | const { endpoint, fetch } = getHooksContext(); 61 | return useModelQuery('Account', `${endpoint}/account/findMany`, args, options, fetch); 62 | } 63 | 64 | export function useInfiniteFindManyAccount>, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: Omit>, 'queryKey' | 'initialPageParam'>) { 65 | options = options ?? { getNextPageParam: () => null }; 66 | const { endpoint, fetch } = getHooksContext(); 67 | return useInfiniteModelQuery('Account', `${endpoint}/account/findMany`, args, options, fetch); 68 | } 69 | 70 | export function useSuspenseFindManyAccount & { $optimistic?: boolean }>, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 71 | const { endpoint, fetch } = getHooksContext(); 72 | return useSuspenseModelQuery('Account', `${endpoint}/account/findMany`, args, options, fetch); 73 | } 74 | 75 | export function useSuspenseInfiniteFindManyAccount>, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: Omit>, 'queryKey' | 'initialPageParam'>) { 76 | options = options ?? { getNextPageParam: () => null }; 77 | const { endpoint, fetch } = getHooksContext(); 78 | return useSuspenseInfiniteModelQuery('Account', `${endpoint}/account/findMany`, args, options, fetch); 79 | } 80 | 81 | export function useFindUniqueAccount & { $optimistic?: boolean }, TData = TQueryFnData, TError = DefaultError>(args: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 82 | const { endpoint, fetch } = getHooksContext(); 83 | return useModelQuery('Account', `${endpoint}/account/findUnique`, args, options, fetch); 84 | } 85 | 86 | export function useSuspenseFindUniqueAccount & { $optimistic?: boolean }, TData = TQueryFnData, TError = DefaultError>(args: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 87 | const { endpoint, fetch } = getHooksContext(); 88 | return useSuspenseModelQuery('Account', `${endpoint}/account/findUnique`, args, options, fetch); 89 | } 90 | 91 | export function useFindFirstAccount & { $optimistic?: boolean }, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 92 | const { endpoint, fetch } = getHooksContext(); 93 | return useModelQuery('Account', `${endpoint}/account/findFirst`, args, options, fetch); 94 | } 95 | 96 | export function useSuspenseFindFirstAccount & { $optimistic?: boolean }, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 97 | const { endpoint, fetch } = getHooksContext(); 98 | return useSuspenseModelQuery('Account', `${endpoint}/account/findFirst`, args, options, fetch); 99 | } 100 | 101 | export function useUpdateAccount(options?: Omit<(UseMutationOptions<(Account | undefined), DefaultError, Prisma.AccountUpdateArgs> & ExtraMutationOptions), 'mutationFn'>) { 102 | const { endpoint, fetch } = getHooksContext(); 103 | const _mutation = 104 | useModelMutation('Account', 'PUT', `${endpoint}/account/update`, metadata, options, fetch, true) 105 | ; 106 | const mutation = { 107 | ..._mutation, 108 | mutateAsync: async ( 109 | args: Prisma.SelectSubset, 110 | options?: Omit<(UseMutationOptions<(CheckSelect> | undefined), DefaultError, Prisma.SelectSubset> & ExtraMutationOptions), 'mutationFn'> 111 | ) => { 112 | return (await _mutation.mutateAsync( 113 | args, 114 | options as any 115 | )) as (CheckSelect> | undefined); 116 | }, 117 | }; 118 | return mutation; 119 | } 120 | 121 | export function useUpdateManyAccount(options?: Omit<(UseMutationOptions & ExtraMutationOptions), 'mutationFn'>) { 122 | const { endpoint, fetch } = getHooksContext(); 123 | const _mutation = 124 | useModelMutation('Account', 'PUT', `${endpoint}/account/updateMany`, metadata, options, fetch, false) 125 | ; 126 | const mutation = { 127 | ..._mutation, 128 | mutateAsync: async ( 129 | args: Prisma.SelectSubset, 130 | options?: Omit<(UseMutationOptions> & ExtraMutationOptions), 'mutationFn'> 131 | ) => { 132 | return (await _mutation.mutateAsync( 133 | args, 134 | options as any 135 | )) as Prisma.BatchPayload; 136 | }, 137 | }; 138 | return mutation; 139 | } 140 | 141 | export function useUpsertAccount(options?: Omit<(UseMutationOptions<(Account | undefined), DefaultError, Prisma.AccountUpsertArgs> & ExtraMutationOptions), 'mutationFn'>) { 142 | const { endpoint, fetch } = getHooksContext(); 143 | const _mutation = 144 | useModelMutation('Account', 'POST', `${endpoint}/account/upsert`, metadata, options, fetch, true) 145 | ; 146 | const mutation = { 147 | ..._mutation, 148 | mutateAsync: async ( 149 | args: Prisma.SelectSubset, 150 | options?: Omit<(UseMutationOptions<(CheckSelect> | undefined), DefaultError, Prisma.SelectSubset> & ExtraMutationOptions), 'mutationFn'> 151 | ) => { 152 | return (await _mutation.mutateAsync( 153 | args, 154 | options as any 155 | )) as (CheckSelect> | undefined); 156 | }, 157 | }; 158 | return mutation; 159 | } 160 | 161 | export function useDeleteAccount(options?: Omit<(UseMutationOptions<(Account | undefined), DefaultError, Prisma.AccountDeleteArgs> & ExtraMutationOptions), 'mutationFn'>) { 162 | const { endpoint, fetch } = getHooksContext(); 163 | const _mutation = 164 | useModelMutation('Account', 'DELETE', `${endpoint}/account/delete`, metadata, options, fetch, true) 165 | ; 166 | const mutation = { 167 | ..._mutation, 168 | mutateAsync: async ( 169 | args: Prisma.SelectSubset, 170 | options?: Omit<(UseMutationOptions<(CheckSelect> | undefined), DefaultError, Prisma.SelectSubset> & ExtraMutationOptions), 'mutationFn'> 171 | ) => { 172 | return (await _mutation.mutateAsync( 173 | args, 174 | options as any 175 | )) as (CheckSelect> | undefined); 176 | }, 177 | }; 178 | return mutation; 179 | } 180 | 181 | export function useDeleteManyAccount(options?: Omit<(UseMutationOptions & ExtraMutationOptions), 'mutationFn'>) { 182 | const { endpoint, fetch } = getHooksContext(); 183 | const _mutation = 184 | useModelMutation('Account', 'DELETE', `${endpoint}/account/deleteMany`, metadata, options, fetch, false) 185 | ; 186 | const mutation = { 187 | ..._mutation, 188 | mutateAsync: async ( 189 | args: Prisma.SelectSubset, 190 | options?: Omit<(UseMutationOptions> & ExtraMutationOptions), 'mutationFn'> 191 | ) => { 192 | return (await _mutation.mutateAsync( 193 | args, 194 | options as any 195 | )) as Prisma.BatchPayload; 196 | }, 197 | }; 198 | return mutation; 199 | } 200 | 201 | export function useAggregateAccount, TData = TQueryFnData, TError = DefaultError>(args: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 202 | const { endpoint, fetch } = getHooksContext(); 203 | return useModelQuery('Account', `${endpoint}/account/aggregate`, args, options, fetch); 204 | } 205 | 206 | export function useSuspenseAggregateAccount, TData = TQueryFnData, TError = DefaultError>(args: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 207 | const { endpoint, fetch } = getHooksContext(); 208 | return useSuspenseModelQuery('Account', `${endpoint}/account/aggregate`, args, options, fetch); 209 | } 210 | 211 | export function useGroupByAccount>, Prisma.Extends<'take', Prisma.Keys>>, OrderByArg extends Prisma.True extends HasSelectOrTake ? { orderBy: Prisma.AccountGroupByArgs['orderBy'] } : { orderBy?: Prisma.AccountGroupByArgs['orderBy'] }, OrderFields extends Prisma.ExcludeUnderscoreKeys>>, ByFields extends Prisma.MaybeTupleToUnion, ByValid extends Prisma.Has, HavingFields extends Prisma.GetHavingFields, HavingValid extends Prisma.Has, ByEmpty extends TArgs['by'] extends never[] ? Prisma.True : Prisma.False, InputErrors extends ByEmpty extends Prisma.True 212 | ? `Error: "by" must not be empty.` 213 | : HavingValid extends Prisma.False 214 | ? { 215 | [P in HavingFields]: P extends ByFields 216 | ? never 217 | : P extends string 218 | ? `Error: Field "${P}" used in "having" needs to be provided in "by".` 219 | : [ 220 | Error, 221 | 'Field ', 222 | P, 223 | ` in "having" needs to be provided in "by"`, 224 | ] 225 | }[HavingFields] 226 | : 'take' extends Prisma.Keys 227 | ? 'orderBy' extends Prisma.Keys 228 | ? ByValid extends Prisma.True 229 | ? {} 230 | : { 231 | [P in OrderFields]: P extends ByFields 232 | ? never 233 | : `Error: Field "${P}" in "orderBy" needs to be provided in "by"` 234 | }[OrderFields] 235 | : 'Error: If you provide "take", you also need to provide "orderBy"' 236 | : 'skip' extends Prisma.Keys 237 | ? 'orderBy' extends Prisma.Keys 238 | ? ByValid extends Prisma.True 239 | ? {} 240 | : { 241 | [P in OrderFields]: P extends ByFields 242 | ? never 243 | : `Error: Field "${P}" in "orderBy" needs to be provided in "by"` 244 | }[OrderFields] 245 | : 'Error: If you provide "skip", you also need to provide "orderBy"' 246 | : ByValid extends Prisma.True 247 | ? {} 248 | : { 249 | [P in OrderFields]: P extends ByFields 250 | ? never 251 | : `Error: Field "${P}" in "orderBy" needs to be provided in "by"` 252 | }[OrderFields], TQueryFnData = {} extends InputErrors ? 253 | Array & 254 | { 255 | [P in ((keyof TArgs) & (keyof Prisma.AccountGroupByOutputType))]: P extends '_count' 256 | ? TArgs[P] extends boolean 257 | ? number 258 | : Prisma.GetScalarType 259 | : Prisma.GetScalarType 260 | } 261 | > : InputErrors, TData = TQueryFnData, TError = DefaultError>(args: Prisma.SelectSubset & InputErrors>, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 262 | const { endpoint, fetch } = getHooksContext(); 263 | return useModelQuery('Account', `${endpoint}/account/groupBy`, args, options, fetch); 264 | } 265 | 266 | export function useSuspenseGroupByAccount>, Prisma.Extends<'take', Prisma.Keys>>, OrderByArg extends Prisma.True extends HasSelectOrTake ? { orderBy: Prisma.AccountGroupByArgs['orderBy'] } : { orderBy?: Prisma.AccountGroupByArgs['orderBy'] }, OrderFields extends Prisma.ExcludeUnderscoreKeys>>, ByFields extends Prisma.MaybeTupleToUnion, ByValid extends Prisma.Has, HavingFields extends Prisma.GetHavingFields, HavingValid extends Prisma.Has, ByEmpty extends TArgs['by'] extends never[] ? Prisma.True : Prisma.False, InputErrors extends ByEmpty extends Prisma.True 267 | ? `Error: "by" must not be empty.` 268 | : HavingValid extends Prisma.False 269 | ? { 270 | [P in HavingFields]: P extends ByFields 271 | ? never 272 | : P extends string 273 | ? `Error: Field "${P}" used in "having" needs to be provided in "by".` 274 | : [ 275 | Error, 276 | 'Field ', 277 | P, 278 | ` in "having" needs to be provided in "by"`, 279 | ] 280 | }[HavingFields] 281 | : 'take' extends Prisma.Keys 282 | ? 'orderBy' extends Prisma.Keys 283 | ? ByValid extends Prisma.True 284 | ? {} 285 | : { 286 | [P in OrderFields]: P extends ByFields 287 | ? never 288 | : `Error: Field "${P}" in "orderBy" needs to be provided in "by"` 289 | }[OrderFields] 290 | : 'Error: If you provide "take", you also need to provide "orderBy"' 291 | : 'skip' extends Prisma.Keys 292 | ? 'orderBy' extends Prisma.Keys 293 | ? ByValid extends Prisma.True 294 | ? {} 295 | : { 296 | [P in OrderFields]: P extends ByFields 297 | ? never 298 | : `Error: Field "${P}" in "orderBy" needs to be provided in "by"` 299 | }[OrderFields] 300 | : 'Error: If you provide "skip", you also need to provide "orderBy"' 301 | : ByValid extends Prisma.True 302 | ? {} 303 | : { 304 | [P in OrderFields]: P extends ByFields 305 | ? never 306 | : `Error: Field "${P}" in "orderBy" needs to be provided in "by"` 307 | }[OrderFields], TQueryFnData = {} extends InputErrors ? 308 | Array & 309 | { 310 | [P in ((keyof TArgs) & (keyof Prisma.AccountGroupByOutputType))]: P extends '_count' 311 | ? TArgs[P] extends boolean 312 | ? number 313 | : Prisma.GetScalarType 314 | : Prisma.GetScalarType 315 | } 316 | > : InputErrors, TData = TQueryFnData, TError = DefaultError>(args: Prisma.SelectSubset & InputErrors>, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 317 | const { endpoint, fetch } = getHooksContext(); 318 | return useSuspenseModelQuery('Account', `${endpoint}/account/groupBy`, args, options, fetch); 319 | } 320 | 321 | export function useCountAccount : number, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 322 | const { endpoint, fetch } = getHooksContext(); 323 | return useModelQuery('Account', `${endpoint}/account/count`, args, options, fetch); 324 | } 325 | 326 | export function useSuspenseCountAccount : number, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 327 | const { endpoint, fetch } = getHooksContext(); 328 | return useSuspenseModelQuery('Account', `${endpoint}/account/count`, args, options, fetch); 329 | } 330 | 331 | export function useCheckAccount(args: { operation: PolicyCrudKind; where?: { id?: string; userId?: string; type?: string; provider?: string; providerAccountId?: string; refresh_token?: string; access_token?: string; expires_at?: number; token_type?: string; scope?: string; id_token?: string; session_state?: string; refresh_token_expires_in?: number }; }, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 332 | const { endpoint, fetch } = getHooksContext(); 333 | return useModelQuery('Account', `${endpoint}/account/check`, args, options, fetch); 334 | } 335 | -------------------------------------------------------------------------------- /src/lib/hooks/verification-token.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * This file was generated by ZenStack CLI. 3 | ******************************************************************************/ 4 | 5 | /* eslint-disable */ 6 | // @ts-nocheck 7 | 8 | import type { Prisma, VerificationToken } from "@zenstackhq/runtime/models"; 9 | import type { UseMutationOptions, UseQueryOptions, UseInfiniteQueryOptions, InfiniteData } from '@tanstack/react-query'; 10 | import { getHooksContext } from '@zenstackhq/tanstack-query/runtime-v5/react'; 11 | import { useModelQuery, useInfiniteModelQuery, useModelMutation } from '@zenstackhq/tanstack-query/runtime-v5/react'; 12 | import type { PickEnumerable, CheckSelect, QueryError, ExtraQueryOptions, ExtraMutationOptions } from '@zenstackhq/tanstack-query/runtime-v5'; 13 | import type { PolicyCrudKind } from '@zenstackhq/runtime' 14 | import metadata from './__model_meta'; 15 | type DefaultError = QueryError; 16 | import { useSuspenseModelQuery, useSuspenseInfiniteModelQuery } from '@zenstackhq/tanstack-query/runtime-v5/react'; 17 | import type { UseSuspenseQueryOptions, UseSuspenseInfiniteQueryOptions } from '@tanstack/react-query'; 18 | 19 | export function useCreateVerificationToken(options?: Omit<(UseMutationOptions<(VerificationToken | undefined), DefaultError, Prisma.VerificationTokenCreateArgs> & ExtraMutationOptions), 'mutationFn'>) { 20 | const { endpoint, fetch } = getHooksContext(); 21 | const _mutation = 22 | useModelMutation('VerificationToken', 'POST', `${endpoint}/verificationToken/create`, metadata, options, fetch, true) 23 | ; 24 | const mutation = { 25 | ..._mutation, 26 | mutateAsync: async ( 27 | args: Prisma.SelectSubset, 28 | options?: Omit<(UseMutationOptions<(CheckSelect> | undefined), DefaultError, Prisma.SelectSubset> & ExtraMutationOptions), 'mutationFn'> 29 | ) => { 30 | return (await _mutation.mutateAsync( 31 | args, 32 | options as any 33 | )) as (CheckSelect> | undefined); 34 | }, 35 | }; 36 | return mutation; 37 | } 38 | 39 | export function useCreateManyVerificationToken(options?: Omit<(UseMutationOptions & ExtraMutationOptions), 'mutationFn'>) { 40 | const { endpoint, fetch } = getHooksContext(); 41 | const _mutation = 42 | useModelMutation('VerificationToken', 'POST', `${endpoint}/verificationToken/createMany`, metadata, options, fetch, false) 43 | ; 44 | const mutation = { 45 | ..._mutation, 46 | mutateAsync: async ( 47 | args: Prisma.SelectSubset, 48 | options?: Omit<(UseMutationOptions> & ExtraMutationOptions), 'mutationFn'> 49 | ) => { 50 | return (await _mutation.mutateAsync( 51 | args, 52 | options as any 53 | )) as Prisma.BatchPayload; 54 | }, 55 | }; 56 | return mutation; 57 | } 58 | 59 | export function useFindManyVerificationToken & { $optimistic?: boolean }>, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 60 | const { endpoint, fetch } = getHooksContext(); 61 | return useModelQuery('VerificationToken', `${endpoint}/verificationToken/findMany`, args, options, fetch); 62 | } 63 | 64 | export function useInfiniteFindManyVerificationToken>, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: Omit>, 'queryKey' | 'initialPageParam'>) { 65 | options = options ?? { getNextPageParam: () => null }; 66 | const { endpoint, fetch } = getHooksContext(); 67 | return useInfiniteModelQuery('VerificationToken', `${endpoint}/verificationToken/findMany`, args, options, fetch); 68 | } 69 | 70 | export function useSuspenseFindManyVerificationToken & { $optimistic?: boolean }>, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 71 | const { endpoint, fetch } = getHooksContext(); 72 | return useSuspenseModelQuery('VerificationToken', `${endpoint}/verificationToken/findMany`, args, options, fetch); 73 | } 74 | 75 | export function useSuspenseInfiniteFindManyVerificationToken>, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: Omit>, 'queryKey' | 'initialPageParam'>) { 76 | options = options ?? { getNextPageParam: () => null }; 77 | const { endpoint, fetch } = getHooksContext(); 78 | return useSuspenseInfiniteModelQuery('VerificationToken', `${endpoint}/verificationToken/findMany`, args, options, fetch); 79 | } 80 | 81 | export function useFindUniqueVerificationToken & { $optimistic?: boolean }, TData = TQueryFnData, TError = DefaultError>(args: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 82 | const { endpoint, fetch } = getHooksContext(); 83 | return useModelQuery('VerificationToken', `${endpoint}/verificationToken/findUnique`, args, options, fetch); 84 | } 85 | 86 | export function useSuspenseFindUniqueVerificationToken & { $optimistic?: boolean }, TData = TQueryFnData, TError = DefaultError>(args: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 87 | const { endpoint, fetch } = getHooksContext(); 88 | return useSuspenseModelQuery('VerificationToken', `${endpoint}/verificationToken/findUnique`, args, options, fetch); 89 | } 90 | 91 | export function useFindFirstVerificationToken & { $optimistic?: boolean }, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 92 | const { endpoint, fetch } = getHooksContext(); 93 | return useModelQuery('VerificationToken', `${endpoint}/verificationToken/findFirst`, args, options, fetch); 94 | } 95 | 96 | export function useSuspenseFindFirstVerificationToken & { $optimistic?: boolean }, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 97 | const { endpoint, fetch } = getHooksContext(); 98 | return useSuspenseModelQuery('VerificationToken', `${endpoint}/verificationToken/findFirst`, args, options, fetch); 99 | } 100 | 101 | export function useUpdateVerificationToken(options?: Omit<(UseMutationOptions<(VerificationToken | undefined), DefaultError, Prisma.VerificationTokenUpdateArgs> & ExtraMutationOptions), 'mutationFn'>) { 102 | const { endpoint, fetch } = getHooksContext(); 103 | const _mutation = 104 | useModelMutation('VerificationToken', 'PUT', `${endpoint}/verificationToken/update`, metadata, options, fetch, true) 105 | ; 106 | const mutation = { 107 | ..._mutation, 108 | mutateAsync: async ( 109 | args: Prisma.SelectSubset, 110 | options?: Omit<(UseMutationOptions<(CheckSelect> | undefined), DefaultError, Prisma.SelectSubset> & ExtraMutationOptions), 'mutationFn'> 111 | ) => { 112 | return (await _mutation.mutateAsync( 113 | args, 114 | options as any 115 | )) as (CheckSelect> | undefined); 116 | }, 117 | }; 118 | return mutation; 119 | } 120 | 121 | export function useUpdateManyVerificationToken(options?: Omit<(UseMutationOptions & ExtraMutationOptions), 'mutationFn'>) { 122 | const { endpoint, fetch } = getHooksContext(); 123 | const _mutation = 124 | useModelMutation('VerificationToken', 'PUT', `${endpoint}/verificationToken/updateMany`, metadata, options, fetch, false) 125 | ; 126 | const mutation = { 127 | ..._mutation, 128 | mutateAsync: async ( 129 | args: Prisma.SelectSubset, 130 | options?: Omit<(UseMutationOptions> & ExtraMutationOptions), 'mutationFn'> 131 | ) => { 132 | return (await _mutation.mutateAsync( 133 | args, 134 | options as any 135 | )) as Prisma.BatchPayload; 136 | }, 137 | }; 138 | return mutation; 139 | } 140 | 141 | export function useUpsertVerificationToken(options?: Omit<(UseMutationOptions<(VerificationToken | undefined), DefaultError, Prisma.VerificationTokenUpsertArgs> & ExtraMutationOptions), 'mutationFn'>) { 142 | const { endpoint, fetch } = getHooksContext(); 143 | const _mutation = 144 | useModelMutation('VerificationToken', 'POST', `${endpoint}/verificationToken/upsert`, metadata, options, fetch, true) 145 | ; 146 | const mutation = { 147 | ..._mutation, 148 | mutateAsync: async ( 149 | args: Prisma.SelectSubset, 150 | options?: Omit<(UseMutationOptions<(CheckSelect> | undefined), DefaultError, Prisma.SelectSubset> & ExtraMutationOptions), 'mutationFn'> 151 | ) => { 152 | return (await _mutation.mutateAsync( 153 | args, 154 | options as any 155 | )) as (CheckSelect> | undefined); 156 | }, 157 | }; 158 | return mutation; 159 | } 160 | 161 | export function useDeleteVerificationToken(options?: Omit<(UseMutationOptions<(VerificationToken | undefined), DefaultError, Prisma.VerificationTokenDeleteArgs> & ExtraMutationOptions), 'mutationFn'>) { 162 | const { endpoint, fetch } = getHooksContext(); 163 | const _mutation = 164 | useModelMutation('VerificationToken', 'DELETE', `${endpoint}/verificationToken/delete`, metadata, options, fetch, true) 165 | ; 166 | const mutation = { 167 | ..._mutation, 168 | mutateAsync: async ( 169 | args: Prisma.SelectSubset, 170 | options?: Omit<(UseMutationOptions<(CheckSelect> | undefined), DefaultError, Prisma.SelectSubset> & ExtraMutationOptions), 'mutationFn'> 171 | ) => { 172 | return (await _mutation.mutateAsync( 173 | args, 174 | options as any 175 | )) as (CheckSelect> | undefined); 176 | }, 177 | }; 178 | return mutation; 179 | } 180 | 181 | export function useDeleteManyVerificationToken(options?: Omit<(UseMutationOptions & ExtraMutationOptions), 'mutationFn'>) { 182 | const { endpoint, fetch } = getHooksContext(); 183 | const _mutation = 184 | useModelMutation('VerificationToken', 'DELETE', `${endpoint}/verificationToken/deleteMany`, metadata, options, fetch, false) 185 | ; 186 | const mutation = { 187 | ..._mutation, 188 | mutateAsync: async ( 189 | args: Prisma.SelectSubset, 190 | options?: Omit<(UseMutationOptions> & ExtraMutationOptions), 'mutationFn'> 191 | ) => { 192 | return (await _mutation.mutateAsync( 193 | args, 194 | options as any 195 | )) as Prisma.BatchPayload; 196 | }, 197 | }; 198 | return mutation; 199 | } 200 | 201 | export function useAggregateVerificationToken, TData = TQueryFnData, TError = DefaultError>(args: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 202 | const { endpoint, fetch } = getHooksContext(); 203 | return useModelQuery('VerificationToken', `${endpoint}/verificationToken/aggregate`, args, options, fetch); 204 | } 205 | 206 | export function useSuspenseAggregateVerificationToken, TData = TQueryFnData, TError = DefaultError>(args: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 207 | const { endpoint, fetch } = getHooksContext(); 208 | return useSuspenseModelQuery('VerificationToken', `${endpoint}/verificationToken/aggregate`, args, options, fetch); 209 | } 210 | 211 | export function useGroupByVerificationToken>, Prisma.Extends<'take', Prisma.Keys>>, OrderByArg extends Prisma.True extends HasSelectOrTake ? { orderBy: Prisma.VerificationTokenGroupByArgs['orderBy'] } : { orderBy?: Prisma.VerificationTokenGroupByArgs['orderBy'] }, OrderFields extends Prisma.ExcludeUnderscoreKeys>>, ByFields extends Prisma.MaybeTupleToUnion, ByValid extends Prisma.Has, HavingFields extends Prisma.GetHavingFields, HavingValid extends Prisma.Has, ByEmpty extends TArgs['by'] extends never[] ? Prisma.True : Prisma.False, InputErrors extends ByEmpty extends Prisma.True 212 | ? `Error: "by" must not be empty.` 213 | : HavingValid extends Prisma.False 214 | ? { 215 | [P in HavingFields]: P extends ByFields 216 | ? never 217 | : P extends string 218 | ? `Error: Field "${P}" used in "having" needs to be provided in "by".` 219 | : [ 220 | Error, 221 | 'Field ', 222 | P, 223 | ` in "having" needs to be provided in "by"`, 224 | ] 225 | }[HavingFields] 226 | : 'take' extends Prisma.Keys 227 | ? 'orderBy' extends Prisma.Keys 228 | ? ByValid extends Prisma.True 229 | ? {} 230 | : { 231 | [P in OrderFields]: P extends ByFields 232 | ? never 233 | : `Error: Field "${P}" in "orderBy" needs to be provided in "by"` 234 | }[OrderFields] 235 | : 'Error: If you provide "take", you also need to provide "orderBy"' 236 | : 'skip' extends Prisma.Keys 237 | ? 'orderBy' extends Prisma.Keys 238 | ? ByValid extends Prisma.True 239 | ? {} 240 | : { 241 | [P in OrderFields]: P extends ByFields 242 | ? never 243 | : `Error: Field "${P}" in "orderBy" needs to be provided in "by"` 244 | }[OrderFields] 245 | : 'Error: If you provide "skip", you also need to provide "orderBy"' 246 | : ByValid extends Prisma.True 247 | ? {} 248 | : { 249 | [P in OrderFields]: P extends ByFields 250 | ? never 251 | : `Error: Field "${P}" in "orderBy" needs to be provided in "by"` 252 | }[OrderFields], TQueryFnData = {} extends InputErrors ? 253 | Array & 254 | { 255 | [P in ((keyof TArgs) & (keyof Prisma.VerificationTokenGroupByOutputType))]: P extends '_count' 256 | ? TArgs[P] extends boolean 257 | ? number 258 | : Prisma.GetScalarType 259 | : Prisma.GetScalarType 260 | } 261 | > : InputErrors, TData = TQueryFnData, TError = DefaultError>(args: Prisma.SelectSubset & InputErrors>, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 262 | const { endpoint, fetch } = getHooksContext(); 263 | return useModelQuery('VerificationToken', `${endpoint}/verificationToken/groupBy`, args, options, fetch); 264 | } 265 | 266 | export function useSuspenseGroupByVerificationToken>, Prisma.Extends<'take', Prisma.Keys>>, OrderByArg extends Prisma.True extends HasSelectOrTake ? { orderBy: Prisma.VerificationTokenGroupByArgs['orderBy'] } : { orderBy?: Prisma.VerificationTokenGroupByArgs['orderBy'] }, OrderFields extends Prisma.ExcludeUnderscoreKeys>>, ByFields extends Prisma.MaybeTupleToUnion, ByValid extends Prisma.Has, HavingFields extends Prisma.GetHavingFields, HavingValid extends Prisma.Has, ByEmpty extends TArgs['by'] extends never[] ? Prisma.True : Prisma.False, InputErrors extends ByEmpty extends Prisma.True 267 | ? `Error: "by" must not be empty.` 268 | : HavingValid extends Prisma.False 269 | ? { 270 | [P in HavingFields]: P extends ByFields 271 | ? never 272 | : P extends string 273 | ? `Error: Field "${P}" used in "having" needs to be provided in "by".` 274 | : [ 275 | Error, 276 | 'Field ', 277 | P, 278 | ` in "having" needs to be provided in "by"`, 279 | ] 280 | }[HavingFields] 281 | : 'take' extends Prisma.Keys 282 | ? 'orderBy' extends Prisma.Keys 283 | ? ByValid extends Prisma.True 284 | ? {} 285 | : { 286 | [P in OrderFields]: P extends ByFields 287 | ? never 288 | : `Error: Field "${P}" in "orderBy" needs to be provided in "by"` 289 | }[OrderFields] 290 | : 'Error: If you provide "take", you also need to provide "orderBy"' 291 | : 'skip' extends Prisma.Keys 292 | ? 'orderBy' extends Prisma.Keys 293 | ? ByValid extends Prisma.True 294 | ? {} 295 | : { 296 | [P in OrderFields]: P extends ByFields 297 | ? never 298 | : `Error: Field "${P}" in "orderBy" needs to be provided in "by"` 299 | }[OrderFields] 300 | : 'Error: If you provide "skip", you also need to provide "orderBy"' 301 | : ByValid extends Prisma.True 302 | ? {} 303 | : { 304 | [P in OrderFields]: P extends ByFields 305 | ? never 306 | : `Error: Field "${P}" in "orderBy" needs to be provided in "by"` 307 | }[OrderFields], TQueryFnData = {} extends InputErrors ? 308 | Array & 309 | { 310 | [P in ((keyof TArgs) & (keyof Prisma.VerificationTokenGroupByOutputType))]: P extends '_count' 311 | ? TArgs[P] extends boolean 312 | ? number 313 | : Prisma.GetScalarType 314 | : Prisma.GetScalarType 315 | } 316 | > : InputErrors, TData = TQueryFnData, TError = DefaultError>(args: Prisma.SelectSubset & InputErrors>, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 317 | const { endpoint, fetch } = getHooksContext(); 318 | return useSuspenseModelQuery('VerificationToken', `${endpoint}/verificationToken/groupBy`, args, options, fetch); 319 | } 320 | 321 | export function useCountVerificationToken : number, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 322 | const { endpoint, fetch } = getHooksContext(); 323 | return useModelQuery('VerificationToken', `${endpoint}/verificationToken/count`, args, options, fetch); 324 | } 325 | 326 | export function useSuspenseCountVerificationToken : number, TData = TQueryFnData, TError = DefaultError>(args?: Prisma.SelectSubset, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 327 | const { endpoint, fetch } = getHooksContext(); 328 | return useSuspenseModelQuery('VerificationToken', `${endpoint}/verificationToken/count`, args, options, fetch); 329 | } 330 | 331 | export function useCheckVerificationToken(args: { operation: PolicyCrudKind; where?: { identifier?: string; token?: string }; }, options?: (Omit, 'queryKey'> & ExtraQueryOptions)) { 332 | const { endpoint, fetch } = getHooksContext(); 333 | return useModelQuery('VerificationToken', `${endpoint}/verificationToken/check`, args, options, fetch); 334 | } 335 | --------------------------------------------------------------------------------