├── 1.PNG ├── 2.PNG ├── 3.PNG ├── 4.PNG ├── README.md ├── backend ├── .gitignore ├── README.md ├── package-lock.json ├── package.json ├── prisma │ ├── migrations │ │ ├── 20240620091118_init_schema │ │ │ └── migration.sql │ │ └── migration_lock.toml │ └── schema.prisma ├── src │ ├── index.ts │ └── route │ │ ├── blog.ts │ │ └── user.ts ├── steps.md ├── tsconfig.json └── wrangler.toml ├── common ├── .npmignore ├── dist │ ├── index.d.ts │ └── index.js ├── node_modules │ ├── .package-lock.json │ └── zod │ │ ├── LICENSE │ │ ├── README.md │ │ ├── index.d.ts │ │ ├── lib │ │ ├── ZodError.d.ts │ │ ├── ZodError.js │ │ ├── __tests__ │ │ │ ├── Mocker.d.ts │ │ │ └── Mocker.js │ │ ├── benchmarks │ │ │ ├── datetime.d.ts │ │ │ ├── datetime.js │ │ │ ├── discriminatedUnion.d.ts │ │ │ ├── discriminatedUnion.js │ │ │ ├── index.d.ts │ │ │ ├── index.js │ │ │ ├── ipv4.d.ts │ │ │ ├── ipv4.js │ │ │ ├── object.d.ts │ │ │ ├── object.js │ │ │ ├── primitives.d.ts │ │ │ ├── primitives.js │ │ │ ├── realworld.d.ts │ │ │ ├── realworld.js │ │ │ ├── string.d.ts │ │ │ ├── string.js │ │ │ ├── union.d.ts │ │ │ └── union.js │ │ ├── errors.d.ts │ │ ├── errors.js │ │ ├── external.d.ts │ │ ├── external.js │ │ ├── helpers │ │ │ ├── enumUtil.d.ts │ │ │ ├── enumUtil.js │ │ │ ├── errorUtil.d.ts │ │ │ ├── errorUtil.js │ │ │ ├── parseUtil.d.ts │ │ │ ├── parseUtil.js │ │ │ ├── partialUtil.d.ts │ │ │ ├── partialUtil.js │ │ │ ├── typeAliases.d.ts │ │ │ ├── typeAliases.js │ │ │ ├── util.d.ts │ │ │ └── util.js │ │ ├── index.d.ts │ │ ├── index.js │ │ ├── index.mjs │ │ ├── index.umd.js │ │ ├── locales │ │ │ ├── en.d.ts │ │ │ └── en.js │ │ ├── types.d.ts │ │ └── types.js │ │ └── package.json ├── package-lock.json ├── package.json ├── src │ └── index.ts └── tsconfig.json └── frontend ├── .eslintrc.cjs ├── .gitignore ├── README.md ├── index.html ├── package-lock.json ├── package.json ├── postcss.config.js ├── public └── vite.svg ├── src ├── App.css ├── App.tsx ├── assets │ └── react.svg ├── components │ ├── Appbar.tsx │ ├── Auth.tsx │ ├── BlogCard.tsx │ ├── BlogSkeleton.tsx │ ├── FullBlog.tsx │ ├── Logout.tsx │ └── Quotes.tsx ├── config.ts ├── hooks │ └── index.ts ├── index.css ├── main.tsx ├── pages │ ├── Blog.tsx │ ├── Blogs.tsx │ ├── Publish.tsx │ ├── Signin.tsx │ └── Signup.tsx └── vite-env.d.ts ├── tailwind.config.js ├── tsconfig.app.json ├── tsconfig.json ├── tsconfig.node.json └── vite.config.ts /1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/syedahmedullah14/blogging-app-like-medium/be8d6a073a1a6ddebb56c8193e21b2f2d219394f/1.PNG -------------------------------------------------------------------------------- /2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/syedahmedullah14/blogging-app-like-medium/be8d6a073a1a6ddebb56c8193e21b2f2d219394f/2.PNG -------------------------------------------------------------------------------- /3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/syedahmedullah14/blogging-app-like-medium/be8d6a073a1a6ddebb56c8193e21b2f2d219394f/3.PNG -------------------------------------------------------------------------------- /4.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/syedahmedullah14/blogging-app-like-medium/be8d6a073a1a6ddebb56c8193e21b2f2d219394f/4.PNG -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Blogging App Like Medium 2 | 3 | This is a blogging application inspired by Medium, developed as part of Cohort 2.0 by Harkirat. The project is built from scratch using a modern tech stack and deployed on Vercel and Cloudflare Workers. 4 | 5 | ## Live Demo 6 | Check out the live app [here](https://blogging-app-like-medium.vercel.app/). 7 | ## Features 8 | 9 | - User Authentication (JWT) 10 | - Skeleton Loading for a smoother user experience 11 | - Connection Pooling with Prisma 12 | - Type Inference and Validation with Zod 13 | 14 | ## Tech Stack 15 | 16 | ### Frontend 17 | 18 | - **React**: A JavaScript library for building user interfaces. 19 | - **Vite**: A build tool that significantly improves the development experience. 20 | - **Skeleton Loading**: For enhanced UX during data fetches. 21 | 22 | ### Backend 23 | 24 | - **Cloudflare Workers**: Serverless functions for handling backend logic. 25 | - **TypeScript**: A strongly typed programming language that builds on JavaScript. 26 | - **Prisma**: ORM for database interaction with connection pooling. 27 | - **PostgreSQL**: The relational database used. 28 | - **Zod**: For schema validation and type inference. 29 | - **JWT**: For secure authentication. 30 | 31 | ## Getting Started 32 | 33 | Follow these instructions to set up the project locally. 34 | 35 | ### Prerequisites 36 | 37 | - Node.js 38 | - PostgreSQL 39 | 40 | ### Installation 41 | 42 | 1. Clone the repository: 43 | 44 | 45 | git clone https://github.com/syedahmedullah14/blogging-app-like-medium.git 46 | 47 | 2. Navigate to the project directory: 48 | 49 | 50 | cd blogging-app-like-medium 51 | 52 | 3. Install the dependencies: 53 | 54 | 55 | npm install 56 | 57 | ### Configuration 58 | 59 | 1. Set up your environment variables. Create a `.env` file in the root directory and add the following: 60 | 61 | 62 | DATABASE_URL=your_postgres_connection_string 63 | JWT_SECRET=your_jwt_secret 64 | 65 | 2. Configure Cloudflare Workers and Vercel for deployment (refer to their respective documentation for detailed steps). 66 | 67 | ### Running the Application 68 | 69 | 1. Start the backend (Cloudflare Workers) and frontend (Vercel): 70 | 71 | 72 | #For the backend 73 | npm run start:backend 74 | 75 | #For the frontend 76 | npm run dev 77 | 78 | 2. Open http://localhost:3000 to view the application in your browser. 79 | 80 | ## Deployment 81 | 82 | ### Backend 83 | 84 | Deploy the backend using Cloudflare Workers. Follow the Cloudflare Workers documentation for detailed deployment instructions. 85 | 86 | ### Frontend 87 | 88 | Deploy the frontend on Vercel. Follow the Vercel documentation for detailed deployment instructions. 89 | 90 | ## Contributing 91 | 92 | Contributions are welcome! Please fork the repository and submit a pull request. 93 | -------------------------------------------------------------------------------- /backend/.gitignore: -------------------------------------------------------------------------------- 1 | # prod 2 | dist/ 3 | 4 | # dev 5 | .yarn/ 6 | !.yarn/releases 7 | .vscode/* 8 | !.vscode/launch.json 9 | !.vscode/*.code-snippets 10 | .idea/workspace.xml 11 | .idea/usage.statistics.xml 12 | .idea/shelf 13 | 14 | # deps 15 | node_modules/ 16 | .wrangler 17 | 18 | # env 19 | .env 20 | .env.production 21 | .dev.vars 22 | 23 | # logs 24 | logs/ 25 | *.log 26 | npm-debug.log* 27 | yarn-debug.log* 28 | yarn-error.log* 29 | pnpm-debug.log* 30 | lerna-debug.log* 31 | 32 | # misc 33 | .DS_Store 34 | -------------------------------------------------------------------------------- /backend/README.md: -------------------------------------------------------------------------------- 1 | ``` 2 | npm install 3 | npm run dev 4 | ``` 5 | 6 | ``` 7 | npm run deploy 8 | ``` 9 | -------------------------------------------------------------------------------- /backend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "backend", 3 | "scripts": { 4 | "dev": "wrangler dev src/index.ts", 5 | "deploy": "wrangler deploy --minify src/index.ts" 6 | }, 7 | "dependencies": { 8 | "@prisma/client": "^5.15.1", 9 | "@prisma/extension-accelerate": "^1.1.0", 10 | "@syedahmedullahjaser/zod-inference-medium-blog": "^1.0.6", 11 | "hono": "^4.4.7", 12 | "prisma": "^5.15.1", 13 | "zod": "^3.23.8" 14 | }, 15 | "devDependencies": { 16 | "@cloudflare/workers-types": "^4.20240529.0", 17 | "wrangler": "^3.57.2" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /backend/prisma/migrations/20240620091118_init_schema/migration.sql: -------------------------------------------------------------------------------- 1 | -- CreateTable 2 | CREATE TABLE "User" ( 3 | "id" TEXT NOT NULL, 4 | "email" TEXT NOT NULL, 5 | "name" TEXT, 6 | "password" TEXT NOT NULL, 7 | 8 | CONSTRAINT "User_pkey" PRIMARY KEY ("id") 9 | ); 10 | 11 | -- CreateTable 12 | CREATE TABLE "Post" ( 13 | "id" TEXT NOT NULL, 14 | "title" TEXT NOT NULL, 15 | "content" TEXT NOT NULL, 16 | "published" BOOLEAN NOT NULL DEFAULT false, 17 | "authorId" TEXT NOT NULL, 18 | 19 | CONSTRAINT "Post_pkey" PRIMARY KEY ("id") 20 | ); 21 | 22 | -- CreateIndex 23 | CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); 24 | 25 | -- AddForeignKey 26 | ALTER TABLE "Post" ADD CONSTRAINT "Post_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; 27 | -------------------------------------------------------------------------------- /backend/prisma/migrations/migration_lock.toml: -------------------------------------------------------------------------------- 1 | # Please do not edit this file manually 2 | # It should be added in your version-control system (i.e. Git) 3 | provider = "postgresql" -------------------------------------------------------------------------------- /backend/prisma/schema.prisma: -------------------------------------------------------------------------------- 1 | 2 | generator client { 3 | provider = "prisma-client-js" 4 | } 5 | 6 | datasource db { 7 | provider = "postgresql" 8 | url = env("DATABASE_URL") 9 | } 10 | model User { 11 | id String @id @default(uuid()) 12 | email String @unique 13 | name String? 14 | password String 15 | posts Post[] 16 | } 17 | 18 | model Post { 19 | id String @id @default(uuid()) 20 | title String 21 | content String 22 | published Boolean @default(false) 23 | author User @relation(fields: [authorId], references: [id]) 24 | authorId String 25 | } -------------------------------------------------------------------------------- /backend/src/index.ts: -------------------------------------------------------------------------------- 1 | import { Hono } from 'hono' 2 | import { userRouter } from './route/user' 3 | import { blogRouter } from './route/blog' 4 | import { cors } from 'hono/cors' 5 | // Create the main Hono app 6 | const app = new Hono<{ 7 | Bindings: { 8 | DATABASE_URL: string, 9 | JWT_SECRET: string, 10 | } 11 | }>(); 12 | 13 | app.use('/*', cors()) 14 | app.route("api/v1/user", userRouter) 15 | app.route("api/v1/blog", blogRouter) 16 | 17 | app.use('/message/*', async (c, next) => { 18 | await next() 19 | }) 20 | 21 | export default app 22 | -------------------------------------------------------------------------------- /backend/src/route/blog.ts: -------------------------------------------------------------------------------- 1 | import { Hono } from "hono"; 2 | import { PrismaClient } from '@prisma/client/edge' 3 | import { withAccelerate } from '@prisma/extension-accelerate' 4 | import { verify } from 'hono/jwt' 5 | import { createBlogInput, updateBlogInput } from "@syedahmedullahjaser/zod-inference-medium-blog"; 6 | 7 | export const blogRouter = new Hono<{ 8 | Bindings: { 9 | DATABASE_URL: string, 10 | JWT_SECRET: string, 11 | }, 12 | Variables: { 13 | userId: string 14 | } 15 | }>(); 16 | 17 | blogRouter.use("/*", async (c, next) => { 18 | const authHeader = c.req.header("Authorization") || "" 19 | const user = await verify(authHeader, c.env.JWT_SECRET) 20 | try { 21 | if(user){ 22 | //@ts-ignore 23 | c.set("userId", user.id); 24 | await next(); 25 | } 26 | else{ 27 | c.status(403) //unauthorized 28 | c.json({ 29 | msg: "You are not logged in" 30 | }) 31 | } 32 | } catch(e){ 33 | c.status(403) //unauthorized 34 | c.json({ 35 | msg: "You are not logged in" 36 | }) 37 | } 38 | 39 | }); 40 | 41 | blogRouter.post('/',async (c) => { 42 | const body = await c.req.json() 43 | const { success } = createBlogInput.safeParse(body) 44 | if(!success){ 45 | c.status(411); 46 | return c.json({ 47 | msg: "Inputs are Incorrect" 48 | }) 49 | } 50 | const authorId = c.get("userId") 51 | const prisma = new PrismaClient({ 52 | datasourceUrl: c.env?.DATABASE_URL, 53 | }).$extends(withAccelerate()); 54 | 55 | const blog = await prisma.post.create({ 56 | data:{ 57 | title: body.title, 58 | content: body.content, 59 | authorId: authorId 60 | } 61 | }) 62 | return c.json({ 63 | id: blog.id 64 | }) 65 | }) 66 | 67 | blogRouter.put('/',async (c) => { 68 | const body = await c.req.json() 69 | const { success } = updateBlogInput.safeParse(body) 70 | if(!success){ 71 | c.status(411); 72 | return c.json({ 73 | msg: "Inputs are Incorrect" 74 | }) 75 | } 76 | const prisma = new PrismaClient({ 77 | datasourceUrl: c.env?.DATABASE_URL, 78 | }).$extends(withAccelerate()); 79 | 80 | const blog = await prisma.post.update({ 81 | where: { 82 | id: body.id 83 | }, 84 | 85 | data:{ 86 | title: body.title, 87 | content: body.content, 88 | } 89 | }) 90 | return c.json({ 91 | id: blog.id 92 | }) 93 | }) 94 | 95 | //TODO pagination 96 | blogRouter.get('/bulk',async (c) => { 97 | const prisma = new PrismaClient({ 98 | datasourceUrl: c.env?.DATABASE_URL, 99 | }).$extends(withAccelerate()); 100 | const blogs = await prisma.post.findMany({ 101 | select:{ 102 | content: true, 103 | title: true, 104 | id: true, 105 | author: { 106 | select: { 107 | name: true 108 | } 109 | } 110 | 111 | } 112 | }); 113 | 114 | return c.json({ 115 | blogs 116 | }) 117 | }) 118 | 119 | blogRouter.get('/:id',async (c) => { 120 | const id = c.req.param("id") 121 | // const body = await c.req.json() 122 | const prisma = new PrismaClient({ 123 | datasourceUrl: c.env?.DATABASE_URL, 124 | }).$extends(withAccelerate()); 125 | 126 | try { 127 | const blog = await prisma.post.findFirst({ 128 | where: { 129 | id: id 130 | }, 131 | select: { 132 | id: true, 133 | title: true, 134 | content: true, 135 | author: { 136 | select: { 137 | name: true 138 | } 139 | } 140 | } 141 | }) 142 | return c.json({ 143 | blog 144 | }); 145 | } catch(e){ 146 | c.status(411); 147 | return c.json({ 148 | msg: "Error while fecthing the blog post" 149 | }) 150 | } 151 | }) 152 | 153 | 154 | -------------------------------------------------------------------------------- /backend/src/route/user.ts: -------------------------------------------------------------------------------- 1 | import { Hono } from "hono"; 2 | import { PrismaClient } from '@prisma/client/edge' 3 | import { withAccelerate } from '@prisma/extension-accelerate' 4 | import { sign } from 'hono/jwt' 5 | import { signinInput, signupInput } from "@syedahmedullahjaser/zod-inference-medium-blog"; 6 | 7 | export const userRouter = new Hono<{ 8 | Bindings: { 9 | DATABASE_URL: string, 10 | JWT_SECRET: string, 11 | } 12 | }>(); 13 | 14 | userRouter.post('/signup', async (c) => { 15 | const body = await c.req.json(); 16 | console.log(body) 17 | const { success } = signupInput.safeParse(body); 18 | console.log(success) 19 | if(!success){ 20 | c.status(411); 21 | return c.json({ 22 | msg: "Inputs are incorrect" 23 | }) 24 | } 25 | const prisma = new PrismaClient({ 26 | datasourceUrl: c.env?.DATABASE_URL, 27 | }).$extends(withAccelerate()); 28 | 29 | try { 30 | const user = await prisma.user.create({ 31 | data: { 32 | email: body.email, 33 | password: body.password, 34 | name: body.name, 35 | } 36 | }); 37 | 38 | const jwt = await sign({id: user.id}, c.env.JWT_SECRET) 39 | return c.text(jwt); 40 | 41 | } catch(e) { 42 | c.status(411); 43 | return c.text("Invalid") 44 | } 45 | }) 46 | 47 | userRouter.post('/signin', async (c) => { 48 | 49 | const body = await c.req.json(); 50 | const { success } = signinInput.safeParse(body); 51 | if(!success){ 52 | c.status(411); 53 | return c.json({ 54 | msg: "Inputs are incorrect" 55 | }) 56 | } 57 | const prisma = new PrismaClient({ 58 | datasourceUrl: c.env?.DATABASE_URL, 59 | }).$extends(withAccelerate()); 60 | 61 | try { 62 | const user = await prisma.user.findFirst({ 63 | where: { 64 | email: body.email, 65 | password: body.password 66 | } 67 | }); 68 | 69 | if (!user) { 70 | c.status(403); //unauthorised 71 | return c.json({ msg: "Incorrect credentials" }); 72 | } 73 | 74 | const jwt = await sign({ id: user.id }, c.env.JWT_SECRET); 75 | return c.json({ jwt }); 76 | 77 | } catch(e){ 78 | c.status(411); 79 | return c.text("Invalid") 80 | } 81 | 82 | }) 83 | -------------------------------------------------------------------------------- /backend/steps.md: -------------------------------------------------------------------------------- 1 | ### Make a root directory 2 | 3 | ## mkdir backend and intialize a hono project 4 | 5 | ## make two folder in the root folder i.e backend and frontend 6 | 7 | ## add common routes in src/index.ts 8 | 9 | ## get database url and connection pool url from neon and prisma accelerate respectively. 10 | 11 | # put connection pool url in wrangler.toml and main database url in .env 12 | 13 | # migrate database using npx prisma migrate dev --name init_schema 14 | 15 | # generate prisma client npx prisma generate --no-engine 16 | 17 | # Add the accelerate extensionnpm install @prisma/extension-accelerate 18 | 19 | # Initialize the prisma client 20 | # import { PrismaClient } from '@prisma/client/edge' 21 | # import { withAccelerate } from '@prisma/extension-accelerate' -------------------------------------------------------------------------------- /backend/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ESNext", 4 | "module": "ESNext", 5 | "moduleResolution": "Bundler", 6 | "strict": true, 7 | "skipLibCheck": true, 8 | "lib": [ 9 | "ESNext" 10 | ], 11 | "types": [ 12 | "@cloudflare/workers-types" 13 | ], 14 | "jsx": "react-jsx", 15 | "jsxImportSource": "hono/jsx" 16 | }, 17 | } -------------------------------------------------------------------------------- /backend/wrangler.toml: -------------------------------------------------------------------------------- 1 | name = "backend" 2 | compatibility_date = "2023-12-01" 3 | 4 | [vars] 5 | DATABASE_URL="prisma://accelerate.prisma-data.net/?api_key=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcGlfa2V5IjoiMWYxZGVlOWItZDdlZS00N2Y5LWJmMGYtZjlkYWZkZTA3ZWJhIiwidGVuYW50X2lkIjoiMzZmNDY1ZDczZWE1MTc3OWM2NDQ5YzdhNWEwYWVhODk0MGQxNjkzYTY2MjczYTM2OTIwYTk4YjU5OTQzYjM1ZSIsImludGVybmFsX3NlY3JldCI6ImUxZGI2ZTI0LWY2MTEtNGZhYy1iNGIzLTg1YTFmNWYxZTc2NCJ9.Fo8zsm1X6MK3wTAqtlIO-Uzf6PDiEThVJb4Fn6-_qO4" 6 | JWT_SECRET = "jaser" 7 | 8 | # [[kv_namespaces]] 9 | # binding = "MY_KV_NAMESPACE" 10 | # id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 11 | 12 | # [[r2_buckets]] 13 | # binding = "MY_BUCKET" 14 | # bucket_name = "my-bucket" 15 | 16 | # [[d1_databases]] 17 | # binding = "DB" 18 | # database_name = "my-database" 19 | # database_id = "" 20 | 21 | # [ai] 22 | # binding = "AI" -------------------------------------------------------------------------------- /common/.npmignore: -------------------------------------------------------------------------------- 1 | src -------------------------------------------------------------------------------- /common/dist/index.d.ts: -------------------------------------------------------------------------------- 1 | import z from "zod"; 2 | export declare const signupInput: z.ZodObject<{ 3 | email: z.ZodString; 4 | password: z.ZodString; 5 | name: z.ZodOptional; 6 | }, "strip", z.ZodTypeAny, { 7 | email: string; 8 | password: string; 9 | name?: string | undefined; 10 | }, { 11 | email: string; 12 | password: string; 13 | name?: string | undefined; 14 | }>; 15 | export type SignupInput = z.infer; 16 | export declare const signinInput: z.ZodObject<{ 17 | email: z.ZodString; 18 | password: z.ZodString; 19 | name: z.ZodOptional; 20 | }, "strip", z.ZodTypeAny, { 21 | email: string; 22 | password: string; 23 | name?: string | undefined; 24 | }, { 25 | email: string; 26 | password: string; 27 | name?: string | undefined; 28 | }>; 29 | export type SigninInput = z.infer; 30 | export declare const createBlogInput: z.ZodObject<{ 31 | title: z.ZodString; 32 | content: z.ZodString; 33 | }, "strip", z.ZodTypeAny, { 34 | title: string; 35 | content: string; 36 | }, { 37 | title: string; 38 | content: string; 39 | }>; 40 | export type CreateBlogInput = z.infer; 41 | export declare const updateBlogInput: z.ZodObject<{ 42 | title: z.ZodString; 43 | content: z.ZodString; 44 | id: z.ZodNumber; 45 | }, "strip", z.ZodTypeAny, { 46 | title: string; 47 | content: string; 48 | id: number; 49 | }, { 50 | title: string; 51 | content: string; 52 | id: number; 53 | }>; 54 | export type UpdateBlogInput = z.infer; 55 | -------------------------------------------------------------------------------- /common/dist/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | exports.updateBlogInput = exports.createBlogInput = exports.signinInput = exports.signupInput = void 0; 7 | const zod_1 = __importDefault(require("zod")); 8 | exports.signupInput = zod_1.default.object({ 9 | email: zod_1.default.string().email(), 10 | password: zod_1.default.string().min(6), 11 | name: zod_1.default.string().optional() 12 | }); 13 | exports.signinInput = zod_1.default.object({ 14 | email: zod_1.default.string().email(), 15 | password: zod_1.default.string().min(6), 16 | name: zod_1.default.string().optional() 17 | }); 18 | exports.createBlogInput = zod_1.default.object({ 19 | title: zod_1.default.string(), 20 | content: zod_1.default.string() 21 | }); 22 | exports.updateBlogInput = zod_1.default.object({ 23 | title: zod_1.default.string(), 24 | content: zod_1.default.string(), 25 | id: zod_1.default.number(), 26 | }); 27 | -------------------------------------------------------------------------------- /common/node_modules/.package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "common", 3 | "version": "1.0.0", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "node_modules/zod": { 8 | "version": "3.23.8", 9 | "resolved": "https://registry.npmjs.org/zod/-/zod-3.23.8.tgz", 10 | "integrity": "sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==", 11 | "license": "MIT", 12 | "funding": { 13 | "url": "https://github.com/sponsors/colinhacks" 14 | } 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /common/node_modules/zod/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Colin McDonnell 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /common/node_modules/zod/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from "./lib"; 2 | export as namespace Zod; 3 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/ZodError.d.ts: -------------------------------------------------------------------------------- 1 | import type { TypeOf, ZodType } from "."; 2 | import { Primitive } from "./helpers/typeAliases"; 3 | import { util, ZodParsedType } from "./helpers/util"; 4 | declare type allKeys = T extends any ? keyof T : never; 5 | export declare type inferFlattenedErrors, U = string> = typeToFlattenedError, U>; 6 | export declare type typeToFlattenedError = { 7 | formErrors: U[]; 8 | fieldErrors: { 9 | [P in allKeys]?: U[]; 10 | }; 11 | }; 12 | export declare const ZodIssueCode: { 13 | invalid_type: "invalid_type"; 14 | invalid_literal: "invalid_literal"; 15 | custom: "custom"; 16 | invalid_union: "invalid_union"; 17 | invalid_union_discriminator: "invalid_union_discriminator"; 18 | invalid_enum_value: "invalid_enum_value"; 19 | unrecognized_keys: "unrecognized_keys"; 20 | invalid_arguments: "invalid_arguments"; 21 | invalid_return_type: "invalid_return_type"; 22 | invalid_date: "invalid_date"; 23 | invalid_string: "invalid_string"; 24 | too_small: "too_small"; 25 | too_big: "too_big"; 26 | invalid_intersection_types: "invalid_intersection_types"; 27 | not_multiple_of: "not_multiple_of"; 28 | not_finite: "not_finite"; 29 | }; 30 | export declare type ZodIssueCode = keyof typeof ZodIssueCode; 31 | export declare type ZodIssueBase = { 32 | path: (string | number)[]; 33 | message?: string; 34 | }; 35 | export interface ZodInvalidTypeIssue extends ZodIssueBase { 36 | code: typeof ZodIssueCode.invalid_type; 37 | expected: ZodParsedType; 38 | received: ZodParsedType; 39 | } 40 | export interface ZodInvalidLiteralIssue extends ZodIssueBase { 41 | code: typeof ZodIssueCode.invalid_literal; 42 | expected: unknown; 43 | received: unknown; 44 | } 45 | export interface ZodUnrecognizedKeysIssue extends ZodIssueBase { 46 | code: typeof ZodIssueCode.unrecognized_keys; 47 | keys: string[]; 48 | } 49 | export interface ZodInvalidUnionIssue extends ZodIssueBase { 50 | code: typeof ZodIssueCode.invalid_union; 51 | unionErrors: ZodError[]; 52 | } 53 | export interface ZodInvalidUnionDiscriminatorIssue extends ZodIssueBase { 54 | code: typeof ZodIssueCode.invalid_union_discriminator; 55 | options: Primitive[]; 56 | } 57 | export interface ZodInvalidEnumValueIssue extends ZodIssueBase { 58 | received: string | number; 59 | code: typeof ZodIssueCode.invalid_enum_value; 60 | options: (string | number)[]; 61 | } 62 | export interface ZodInvalidArgumentsIssue extends ZodIssueBase { 63 | code: typeof ZodIssueCode.invalid_arguments; 64 | argumentsError: ZodError; 65 | } 66 | export interface ZodInvalidReturnTypeIssue extends ZodIssueBase { 67 | code: typeof ZodIssueCode.invalid_return_type; 68 | returnTypeError: ZodError; 69 | } 70 | export interface ZodInvalidDateIssue extends ZodIssueBase { 71 | code: typeof ZodIssueCode.invalid_date; 72 | } 73 | export declare type StringValidation = "email" | "url" | "emoji" | "uuid" | "nanoid" | "regex" | "cuid" | "cuid2" | "ulid" | "datetime" | "date" | "time" | "duration" | "ip" | "base64" | { 74 | includes: string; 75 | position?: number; 76 | } | { 77 | startsWith: string; 78 | } | { 79 | endsWith: string; 80 | }; 81 | export interface ZodInvalidStringIssue extends ZodIssueBase { 82 | code: typeof ZodIssueCode.invalid_string; 83 | validation: StringValidation; 84 | } 85 | export interface ZodTooSmallIssue extends ZodIssueBase { 86 | code: typeof ZodIssueCode.too_small; 87 | minimum: number | bigint; 88 | inclusive: boolean; 89 | exact?: boolean; 90 | type: "array" | "string" | "number" | "set" | "date" | "bigint"; 91 | } 92 | export interface ZodTooBigIssue extends ZodIssueBase { 93 | code: typeof ZodIssueCode.too_big; 94 | maximum: number | bigint; 95 | inclusive: boolean; 96 | exact?: boolean; 97 | type: "array" | "string" | "number" | "set" | "date" | "bigint"; 98 | } 99 | export interface ZodInvalidIntersectionTypesIssue extends ZodIssueBase { 100 | code: typeof ZodIssueCode.invalid_intersection_types; 101 | } 102 | export interface ZodNotMultipleOfIssue extends ZodIssueBase { 103 | code: typeof ZodIssueCode.not_multiple_of; 104 | multipleOf: number | bigint; 105 | } 106 | export interface ZodNotFiniteIssue extends ZodIssueBase { 107 | code: typeof ZodIssueCode.not_finite; 108 | } 109 | export interface ZodCustomIssue extends ZodIssueBase { 110 | code: typeof ZodIssueCode.custom; 111 | params?: { 112 | [k: string]: any; 113 | }; 114 | } 115 | export declare type DenormalizedError = { 116 | [k: string]: DenormalizedError | string[]; 117 | }; 118 | export declare type ZodIssueOptionalMessage = ZodInvalidTypeIssue | ZodInvalidLiteralIssue | ZodUnrecognizedKeysIssue | ZodInvalidUnionIssue | ZodInvalidUnionDiscriminatorIssue | ZodInvalidEnumValueIssue | ZodInvalidArgumentsIssue | ZodInvalidReturnTypeIssue | ZodInvalidDateIssue | ZodInvalidStringIssue | ZodTooSmallIssue | ZodTooBigIssue | ZodInvalidIntersectionTypesIssue | ZodNotMultipleOfIssue | ZodNotFiniteIssue | ZodCustomIssue; 119 | export declare type ZodIssue = ZodIssueOptionalMessage & { 120 | fatal?: boolean; 121 | message: string; 122 | }; 123 | export declare const quotelessJson: (obj: any) => string; 124 | declare type recursiveZodFormattedError = T extends [any, ...any[]] ? { 125 | [K in keyof T]?: ZodFormattedError; 126 | } : T extends any[] ? { 127 | [k: number]: ZodFormattedError; 128 | } : T extends object ? { 129 | [K in keyof T]?: ZodFormattedError; 130 | } : unknown; 131 | export declare type ZodFormattedError = { 132 | _errors: U[]; 133 | } & recursiveZodFormattedError>; 134 | export declare type inferFormattedError, U = string> = ZodFormattedError, U>; 135 | export declare class ZodError extends Error { 136 | issues: ZodIssue[]; 137 | get errors(): ZodIssue[]; 138 | constructor(issues: ZodIssue[]); 139 | format(): ZodFormattedError; 140 | format(mapper: (issue: ZodIssue) => U): ZodFormattedError; 141 | static create: (issues: ZodIssue[]) => ZodError; 142 | static assert(value: unknown): asserts value is ZodError; 143 | toString(): string; 144 | get message(): string; 145 | get isEmpty(): boolean; 146 | addIssue: (sub: ZodIssue) => void; 147 | addIssues: (subs?: ZodIssue[]) => void; 148 | flatten(): typeToFlattenedError; 149 | flatten(mapper?: (issue: ZodIssue) => U): typeToFlattenedError; 150 | get formErrors(): typeToFlattenedError; 151 | } 152 | declare type stripPath = T extends any ? util.OmitKeys : never; 153 | export declare type IssueData = stripPath & { 154 | path?: (string | number)[]; 155 | fatal?: boolean; 156 | }; 157 | export declare type ErrorMapCtx = { 158 | defaultError: string; 159 | data: any; 160 | }; 161 | export declare type ZodErrorMap = (issue: ZodIssueOptionalMessage, _ctx: ErrorMapCtx) => { 162 | message: string; 163 | }; 164 | export {}; 165 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/ZodError.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.ZodError = exports.quotelessJson = exports.ZodIssueCode = void 0; 4 | const util_1 = require("./helpers/util"); 5 | exports.ZodIssueCode = util_1.util.arrayToEnum([ 6 | "invalid_type", 7 | "invalid_literal", 8 | "custom", 9 | "invalid_union", 10 | "invalid_union_discriminator", 11 | "invalid_enum_value", 12 | "unrecognized_keys", 13 | "invalid_arguments", 14 | "invalid_return_type", 15 | "invalid_date", 16 | "invalid_string", 17 | "too_small", 18 | "too_big", 19 | "invalid_intersection_types", 20 | "not_multiple_of", 21 | "not_finite", 22 | ]); 23 | const quotelessJson = (obj) => { 24 | const json = JSON.stringify(obj, null, 2); 25 | return json.replace(/"([^"]+)":/g, "$1:"); 26 | }; 27 | exports.quotelessJson = quotelessJson; 28 | class ZodError extends Error { 29 | constructor(issues) { 30 | super(); 31 | this.issues = []; 32 | this.addIssue = (sub) => { 33 | this.issues = [...this.issues, sub]; 34 | }; 35 | this.addIssues = (subs = []) => { 36 | this.issues = [...this.issues, ...subs]; 37 | }; 38 | const actualProto = new.target.prototype; 39 | if (Object.setPrototypeOf) { 40 | // eslint-disable-next-line ban/ban 41 | Object.setPrototypeOf(this, actualProto); 42 | } 43 | else { 44 | this.__proto__ = actualProto; 45 | } 46 | this.name = "ZodError"; 47 | this.issues = issues; 48 | } 49 | get errors() { 50 | return this.issues; 51 | } 52 | format(_mapper) { 53 | const mapper = _mapper || 54 | function (issue) { 55 | return issue.message; 56 | }; 57 | const fieldErrors = { _errors: [] }; 58 | const processError = (error) => { 59 | for (const issue of error.issues) { 60 | if (issue.code === "invalid_union") { 61 | issue.unionErrors.map(processError); 62 | } 63 | else if (issue.code === "invalid_return_type") { 64 | processError(issue.returnTypeError); 65 | } 66 | else if (issue.code === "invalid_arguments") { 67 | processError(issue.argumentsError); 68 | } 69 | else if (issue.path.length === 0) { 70 | fieldErrors._errors.push(mapper(issue)); 71 | } 72 | else { 73 | let curr = fieldErrors; 74 | let i = 0; 75 | while (i < issue.path.length) { 76 | const el = issue.path[i]; 77 | const terminal = i === issue.path.length - 1; 78 | if (!terminal) { 79 | curr[el] = curr[el] || { _errors: [] }; 80 | // if (typeof el === "string") { 81 | // curr[el] = curr[el] || { _errors: [] }; 82 | // } else if (typeof el === "number") { 83 | // const errorArray: any = []; 84 | // errorArray._errors = []; 85 | // curr[el] = curr[el] || errorArray; 86 | // } 87 | } 88 | else { 89 | curr[el] = curr[el] || { _errors: [] }; 90 | curr[el]._errors.push(mapper(issue)); 91 | } 92 | curr = curr[el]; 93 | i++; 94 | } 95 | } 96 | } 97 | }; 98 | processError(this); 99 | return fieldErrors; 100 | } 101 | static assert(value) { 102 | if (!(value instanceof ZodError)) { 103 | throw new Error(`Not a ZodError: ${value}`); 104 | } 105 | } 106 | toString() { 107 | return this.message; 108 | } 109 | get message() { 110 | return JSON.stringify(this.issues, util_1.util.jsonStringifyReplacer, 2); 111 | } 112 | get isEmpty() { 113 | return this.issues.length === 0; 114 | } 115 | flatten(mapper = (issue) => issue.message) { 116 | const fieldErrors = {}; 117 | const formErrors = []; 118 | for (const sub of this.issues) { 119 | if (sub.path.length > 0) { 120 | fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || []; 121 | fieldErrors[sub.path[0]].push(mapper(sub)); 122 | } 123 | else { 124 | formErrors.push(mapper(sub)); 125 | } 126 | } 127 | return { formErrors, fieldErrors }; 128 | } 129 | get formErrors() { 130 | return this.flatten(); 131 | } 132 | } 133 | exports.ZodError = ZodError; 134 | ZodError.create = (issues) => { 135 | const error = new ZodError(issues); 136 | return error; 137 | }; 138 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/__tests__/Mocker.d.ts: -------------------------------------------------------------------------------- 1 | export declare class Mocker { 2 | pick: (...args: any[]) => any; 3 | get string(): string; 4 | get number(): number; 5 | get bigint(): bigint; 6 | get boolean(): boolean; 7 | get date(): Date; 8 | get symbol(): symbol; 9 | get null(): null; 10 | get undefined(): undefined; 11 | get stringOptional(): any; 12 | get stringNullable(): any; 13 | get numberOptional(): any; 14 | get numberNullable(): any; 15 | get booleanOptional(): any; 16 | get booleanNullable(): any; 17 | } 18 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/__tests__/Mocker.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.Mocker = void 0; 4 | function getRandomInt(max) { 5 | return Math.floor(Math.random() * Math.floor(max)); 6 | } 7 | const testSymbol = Symbol("test"); 8 | class Mocker { 9 | constructor() { 10 | this.pick = (...args) => { 11 | return args[getRandomInt(args.length)]; 12 | }; 13 | } 14 | get string() { 15 | return Math.random().toString(36).substring(7); 16 | } 17 | get number() { 18 | return Math.random() * 100; 19 | } 20 | get bigint() { 21 | return BigInt(Math.floor(Math.random() * 10000)); 22 | } 23 | get boolean() { 24 | return Math.random() < 0.5; 25 | } 26 | get date() { 27 | return new Date(Math.floor(Date.now() * Math.random())); 28 | } 29 | get symbol() { 30 | return testSymbol; 31 | } 32 | get null() { 33 | return null; 34 | } 35 | get undefined() { 36 | return undefined; 37 | } 38 | get stringOptional() { 39 | return this.pick(this.string, this.undefined); 40 | } 41 | get stringNullable() { 42 | return this.pick(this.string, this.null); 43 | } 44 | get numberOptional() { 45 | return this.pick(this.number, this.undefined); 46 | } 47 | get numberNullable() { 48 | return this.pick(this.number, this.null); 49 | } 50 | get booleanOptional() { 51 | return this.pick(this.boolean, this.undefined); 52 | } 53 | get booleanNullable() { 54 | return this.pick(this.boolean, this.null); 55 | } 56 | } 57 | exports.Mocker = Mocker; 58 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/benchmarks/datetime.d.ts: -------------------------------------------------------------------------------- 1 | import Benchmark from "benchmark"; 2 | declare const _default: { 3 | suites: Benchmark.Suite[]; 4 | }; 5 | export default _default; 6 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/benchmarks/datetime.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const benchmark_1 = __importDefault(require("benchmark")); 7 | const datetimeValidationSuite = new benchmark_1.default.Suite("datetime"); 8 | const DATA = "2021-01-01"; 9 | const MONTHS_31 = new Set([1, 3, 5, 7, 8, 10, 12]); 10 | const MONTHS_30 = new Set([4, 6, 9, 11]); 11 | const simpleDatetimeRegex = /^(\d{4})-(\d{2})-(\d{2})$/; 12 | const datetimeRegexNoLeapYearValidation = /^\d{4}-((0[13578]|10|12)-31|(0[13-9]|1[0-2])-30|(0[1-9]|1[0-2])-(0[1-9]|1\d|2\d))$/; 13 | const datetimeRegexWithLeapYearValidation = /^((\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\d|3[01])|(0[469]|11)-(0[1-9]|[12]\d|30)|(02)-(0[1-9]|1\d|2[0-8])))$/; 14 | datetimeValidationSuite 15 | .add("new Date()", () => { 16 | return !isNaN(new Date(DATA).getTime()); 17 | }) 18 | .add("regex (no validation)", () => { 19 | return simpleDatetimeRegex.test(DATA); 20 | }) 21 | .add("regex (no leap year)", () => { 22 | return datetimeRegexNoLeapYearValidation.test(DATA); 23 | }) 24 | .add("regex (w/ leap year)", () => { 25 | return datetimeRegexWithLeapYearValidation.test(DATA); 26 | }) 27 | .add("capture groups + code", () => { 28 | const match = DATA.match(simpleDatetimeRegex); 29 | if (!match) 30 | return false; 31 | // Extract year, month, and day from the capture groups 32 | const year = Number.parseInt(match[1], 10); 33 | const month = Number.parseInt(match[2], 10); // month is 0-indexed in JavaScript Date, so subtract 1 34 | const day = Number.parseInt(match[3], 10); 35 | if (month === 2) { 36 | if ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0) { 37 | return day <= 29; 38 | } 39 | return day <= 28; 40 | } 41 | if (MONTHS_30.has(month)) { 42 | return day <= 30; 43 | } 44 | if (MONTHS_31.has(month)) { 45 | return day <= 31; 46 | } 47 | return false; 48 | }) 49 | .on("cycle", (e) => { 50 | console.log(`${datetimeValidationSuite.name}: ${e.target}`); 51 | }); 52 | exports.default = { 53 | suites: [datetimeValidationSuite], 54 | }; 55 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/benchmarks/discriminatedUnion.d.ts: -------------------------------------------------------------------------------- 1 | import Benchmark from "benchmark"; 2 | declare const _default: { 3 | suites: Benchmark.Suite[]; 4 | }; 5 | export default _default; 6 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/benchmarks/discriminatedUnion.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const benchmark_1 = __importDefault(require("benchmark")); 7 | const index_1 = require("../index"); 8 | const doubleSuite = new benchmark_1.default.Suite("z.discriminatedUnion: double"); 9 | const manySuite = new benchmark_1.default.Suite("z.discriminatedUnion: many"); 10 | const aSchema = index_1.z.object({ 11 | type: index_1.z.literal("a"), 12 | }); 13 | const objA = { 14 | type: "a", 15 | }; 16 | const bSchema = index_1.z.object({ 17 | type: index_1.z.literal("b"), 18 | }); 19 | const objB = { 20 | type: "b", 21 | }; 22 | const cSchema = index_1.z.object({ 23 | type: index_1.z.literal("c"), 24 | }); 25 | const objC = { 26 | type: "c", 27 | }; 28 | const dSchema = index_1.z.object({ 29 | type: index_1.z.literal("d"), 30 | }); 31 | const double = index_1.z.discriminatedUnion("type", [aSchema, bSchema]); 32 | const many = index_1.z.discriminatedUnion("type", [aSchema, bSchema, cSchema, dSchema]); 33 | doubleSuite 34 | .add("valid: a", () => { 35 | double.parse(objA); 36 | }) 37 | .add("valid: b", () => { 38 | double.parse(objB); 39 | }) 40 | .add("invalid: null", () => { 41 | try { 42 | double.parse(null); 43 | } 44 | catch (err) { } 45 | }) 46 | .add("invalid: wrong shape", () => { 47 | try { 48 | double.parse(objC); 49 | } 50 | catch (err) { } 51 | }) 52 | .on("cycle", (e) => { 53 | console.log(`${doubleSuite.name}: ${e.target}`); 54 | }); 55 | manySuite 56 | .add("valid: a", () => { 57 | many.parse(objA); 58 | }) 59 | .add("valid: c", () => { 60 | many.parse(objC); 61 | }) 62 | .add("invalid: null", () => { 63 | try { 64 | many.parse(null); 65 | } 66 | catch (err) { } 67 | }) 68 | .add("invalid: wrong shape", () => { 69 | try { 70 | many.parse({ type: "unknown" }); 71 | } 72 | catch (err) { } 73 | }) 74 | .on("cycle", (e) => { 75 | console.log(`${manySuite.name}: ${e.target}`); 76 | }); 77 | exports.default = { 78 | suites: [doubleSuite, manySuite], 79 | }; 80 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/benchmarks/index.d.ts: -------------------------------------------------------------------------------- 1 | export {}; 2 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/benchmarks/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const datetime_1 = __importDefault(require("./datetime")); 7 | const discriminatedUnion_1 = __importDefault(require("./discriminatedUnion")); 8 | const ipv4_1 = __importDefault(require("./ipv4")); 9 | const object_1 = __importDefault(require("./object")); 10 | const primitives_1 = __importDefault(require("./primitives")); 11 | const realworld_1 = __importDefault(require("./realworld")); 12 | const string_1 = __importDefault(require("./string")); 13 | const union_1 = __importDefault(require("./union")); 14 | const argv = process.argv.slice(2); 15 | let suites = []; 16 | if (!argv.length) { 17 | suites = [ 18 | ...realworld_1.default.suites, 19 | ...primitives_1.default.suites, 20 | ...string_1.default.suites, 21 | ...object_1.default.suites, 22 | ...union_1.default.suites, 23 | ...discriminatedUnion_1.default.suites, 24 | ]; 25 | } 26 | else { 27 | if (argv.includes("--realworld")) { 28 | suites.push(...realworld_1.default.suites); 29 | } 30 | if (argv.includes("--primitives")) { 31 | suites.push(...primitives_1.default.suites); 32 | } 33 | if (argv.includes("--string")) { 34 | suites.push(...string_1.default.suites); 35 | } 36 | if (argv.includes("--object")) { 37 | suites.push(...object_1.default.suites); 38 | } 39 | if (argv.includes("--union")) { 40 | suites.push(...union_1.default.suites); 41 | } 42 | if (argv.includes("--discriminatedUnion")) { 43 | suites.push(...datetime_1.default.suites); 44 | } 45 | if (argv.includes("--datetime")) { 46 | suites.push(...datetime_1.default.suites); 47 | } 48 | if (argv.includes("--ipv4")) { 49 | suites.push(...ipv4_1.default.suites); 50 | } 51 | } 52 | for (const suite of suites) { 53 | suite.run({}); 54 | } 55 | // exit on Ctrl-C 56 | process.on("SIGINT", function () { 57 | console.log("Exiting..."); 58 | process.exit(); 59 | }); 60 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/benchmarks/ipv4.d.ts: -------------------------------------------------------------------------------- 1 | import Benchmark from "benchmark"; 2 | declare const _default: { 3 | suites: Benchmark.Suite[]; 4 | }; 5 | export default _default; 6 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/benchmarks/ipv4.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const benchmark_1 = __importDefault(require("benchmark")); 7 | const suite = new benchmark_1.default.Suite("ipv4"); 8 | const DATA = "127.0.0.1"; 9 | const ipv4RegexA = /^(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))$/; 10 | const ipv4RegexB = /^(?:(?:(?=(25[0-5]))\1|(?=(2[0-4][0-9]))\2|(?=(1[0-9]{2}))\3|(?=([0-9]{1,2}))\4)\.){3}(?:(?=(25[0-5]))\5|(?=(2[0-4][0-9]))\6|(?=(1[0-9]{2}))\7|(?=([0-9]{1,2}))\8)$/; 11 | const ipv4RegexC = /^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/; 12 | const ipv4RegexD = /^(\b25[0-5]|\b2[0-4][0-9]|\b[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/; 13 | const ipv4RegexE = /^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.){3}(25[0-5]|(2[0-4]|1\d|[1-9]|)\d)$/; 14 | const ipv4RegexF = /^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$/; 15 | const ipv4RegexG = /^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)(\.(?!$)|$)){4}$/; 16 | const ipv4RegexH = /^((25[0-5]|(2[0-4]|1[0-9]|[1-9]|)[0-9])(\.(?!$)|$)){4}$/; 17 | const ipv4RegexI = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/; 18 | suite 19 | .add("A", () => { 20 | return ipv4RegexA.test(DATA); 21 | }) 22 | .add("B", () => { 23 | return ipv4RegexB.test(DATA); 24 | }) 25 | .add("C", () => { 26 | return ipv4RegexC.test(DATA); 27 | }) 28 | .add("D", () => { 29 | return ipv4RegexD.test(DATA); 30 | }) 31 | .add("E", () => { 32 | return ipv4RegexE.test(DATA); 33 | }) 34 | .add("F", () => { 35 | return ipv4RegexF.test(DATA); 36 | }) 37 | .add("G", () => { 38 | return ipv4RegexG.test(DATA); 39 | }) 40 | .add("H", () => { 41 | return ipv4RegexH.test(DATA); 42 | }) 43 | .add("I", () => { 44 | return ipv4RegexI.test(DATA); 45 | }) 46 | .on("cycle", (e) => { 47 | console.log(`${suite.name}: ${e.target}`); 48 | }); 49 | exports.default = { 50 | suites: [suite], 51 | }; 52 | if (require.main === module) { 53 | suite.run(); 54 | } 55 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/benchmarks/object.d.ts: -------------------------------------------------------------------------------- 1 | import Benchmark from "benchmark"; 2 | declare const _default: { 3 | suites: Benchmark.Suite[]; 4 | }; 5 | export default _default; 6 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/benchmarks/object.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const benchmark_1 = __importDefault(require("benchmark")); 7 | const index_1 = require("../index"); 8 | const emptySuite = new benchmark_1.default.Suite("z.object: empty"); 9 | const shortSuite = new benchmark_1.default.Suite("z.object: short"); 10 | const longSuite = new benchmark_1.default.Suite("z.object: long"); 11 | const empty = index_1.z.object({}); 12 | const short = index_1.z.object({ 13 | string: index_1.z.string(), 14 | }); 15 | const long = index_1.z.object({ 16 | string: index_1.z.string(), 17 | number: index_1.z.number(), 18 | boolean: index_1.z.boolean(), 19 | }); 20 | emptySuite 21 | .add("valid", () => { 22 | empty.parse({}); 23 | }) 24 | .add("valid: extra keys", () => { 25 | empty.parse({ string: "string" }); 26 | }) 27 | .add("invalid: null", () => { 28 | try { 29 | empty.parse(null); 30 | } 31 | catch (err) { } 32 | }) 33 | .on("cycle", (e) => { 34 | console.log(`${emptySuite.name}: ${e.target}`); 35 | }); 36 | shortSuite 37 | .add("valid", () => { 38 | short.parse({ string: "string" }); 39 | }) 40 | .add("valid: extra keys", () => { 41 | short.parse({ string: "string", number: 42 }); 42 | }) 43 | .add("invalid: null", () => { 44 | try { 45 | short.parse(null); 46 | } 47 | catch (err) { } 48 | }) 49 | .on("cycle", (e) => { 50 | console.log(`${shortSuite.name}: ${e.target}`); 51 | }); 52 | longSuite 53 | .add("valid", () => { 54 | long.parse({ string: "string", number: 42, boolean: true }); 55 | }) 56 | .add("valid: extra keys", () => { 57 | long.parse({ string: "string", number: 42, boolean: true, list: [] }); 58 | }) 59 | .add("invalid: null", () => { 60 | try { 61 | long.parse(null); 62 | } 63 | catch (err) { } 64 | }) 65 | .on("cycle", (e) => { 66 | console.log(`${longSuite.name}: ${e.target}`); 67 | }); 68 | exports.default = { 69 | suites: [emptySuite, shortSuite, longSuite], 70 | }; 71 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/benchmarks/primitives.d.ts: -------------------------------------------------------------------------------- 1 | import Benchmark from "benchmark"; 2 | declare const _default: { 3 | suites: Benchmark.Suite[]; 4 | }; 5 | export default _default; 6 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/benchmarks/primitives.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const benchmark_1 = __importDefault(require("benchmark")); 7 | const Mocker_1 = require("../__tests__/Mocker"); 8 | const index_1 = require("../index"); 9 | const val = new Mocker_1.Mocker(); 10 | const enumSuite = new benchmark_1.default.Suite("z.enum"); 11 | const enumSchema = index_1.z.enum(["a", "b", "c"]); 12 | enumSuite 13 | .add("valid", () => { 14 | enumSchema.parse("a"); 15 | }) 16 | .add("invalid", () => { 17 | try { 18 | enumSchema.parse("x"); 19 | } 20 | catch (e) { } 21 | }) 22 | .on("cycle", (e) => { 23 | console.log(`z.enum: ${e.target}`); 24 | }); 25 | const longEnumSuite = new benchmark_1.default.Suite("long z.enum"); 26 | const longEnumSchema = index_1.z.enum([ 27 | "one", 28 | "two", 29 | "three", 30 | "four", 31 | "five", 32 | "six", 33 | "seven", 34 | "eight", 35 | "nine", 36 | "ten", 37 | "eleven", 38 | "twelve", 39 | "thirteen", 40 | "fourteen", 41 | "fifteen", 42 | "sixteen", 43 | "seventeen", 44 | ]); 45 | longEnumSuite 46 | .add("valid", () => { 47 | longEnumSchema.parse("five"); 48 | }) 49 | .add("invalid", () => { 50 | try { 51 | longEnumSchema.parse("invalid"); 52 | } 53 | catch (e) { } 54 | }) 55 | .on("cycle", (e) => { 56 | console.log(`long z.enum: ${e.target}`); 57 | }); 58 | const undefinedSuite = new benchmark_1.default.Suite("z.undefined"); 59 | const undefinedSchema = index_1.z.undefined(); 60 | undefinedSuite 61 | .add("valid", () => { 62 | undefinedSchema.parse(undefined); 63 | }) 64 | .add("invalid", () => { 65 | try { 66 | undefinedSchema.parse(1); 67 | } 68 | catch (e) { } 69 | }) 70 | .on("cycle", (e) => { 71 | console.log(`z.undefined: ${e.target}`); 72 | }); 73 | const literalSuite = new benchmark_1.default.Suite("z.literal"); 74 | const short = "short"; 75 | const bad = "bad"; 76 | const literalSchema = index_1.z.literal("short"); 77 | literalSuite 78 | .add("valid", () => { 79 | literalSchema.parse(short); 80 | }) 81 | .add("invalid", () => { 82 | try { 83 | literalSchema.parse(bad); 84 | } 85 | catch (e) { } 86 | }) 87 | .on("cycle", (e) => { 88 | console.log(`z.literal: ${e.target}`); 89 | }); 90 | const numberSuite = new benchmark_1.default.Suite("z.number"); 91 | const numberSchema = index_1.z.number().int(); 92 | numberSuite 93 | .add("valid", () => { 94 | numberSchema.parse(1); 95 | }) 96 | .add("invalid type", () => { 97 | try { 98 | numberSchema.parse("bad"); 99 | } 100 | catch (e) { } 101 | }) 102 | .add("invalid number", () => { 103 | try { 104 | numberSchema.parse(0.5); 105 | } 106 | catch (e) { } 107 | }) 108 | .on("cycle", (e) => { 109 | console.log(`z.number: ${e.target}`); 110 | }); 111 | const dateSuite = new benchmark_1.default.Suite("z.date"); 112 | const plainDate = index_1.z.date(); 113 | const minMaxDate = index_1.z 114 | .date() 115 | .min(new Date("2021-01-01")) 116 | .max(new Date("2030-01-01")); 117 | dateSuite 118 | .add("valid", () => { 119 | plainDate.parse(new Date()); 120 | }) 121 | .add("invalid", () => { 122 | try { 123 | plainDate.parse(1); 124 | } 125 | catch (e) { } 126 | }) 127 | .add("valid min and max", () => { 128 | minMaxDate.parse(new Date("2023-01-01")); 129 | }) 130 | .add("invalid min", () => { 131 | try { 132 | minMaxDate.parse(new Date("2019-01-01")); 133 | } 134 | catch (e) { } 135 | }) 136 | .add("invalid max", () => { 137 | try { 138 | minMaxDate.parse(new Date("2031-01-01")); 139 | } 140 | catch (e) { } 141 | }) 142 | .on("cycle", (e) => { 143 | console.log(`z.date: ${e.target}`); 144 | }); 145 | const symbolSuite = new benchmark_1.default.Suite("z.symbol"); 146 | const symbolSchema = index_1.z.symbol(); 147 | symbolSuite 148 | .add("valid", () => { 149 | symbolSchema.parse(val.symbol); 150 | }) 151 | .add("invalid", () => { 152 | try { 153 | symbolSchema.parse(1); 154 | } 155 | catch (e) { } 156 | }) 157 | .on("cycle", (e) => { 158 | console.log(`z.symbol: ${e.target}`); 159 | }); 160 | exports.default = { 161 | suites: [ 162 | enumSuite, 163 | longEnumSuite, 164 | undefinedSuite, 165 | literalSuite, 166 | numberSuite, 167 | dateSuite, 168 | symbolSuite, 169 | ], 170 | }; 171 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/benchmarks/realworld.d.ts: -------------------------------------------------------------------------------- 1 | import Benchmark from "benchmark"; 2 | declare const _default: { 3 | suites: Benchmark.Suite[]; 4 | }; 5 | export default _default; 6 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/benchmarks/realworld.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const benchmark_1 = __importDefault(require("benchmark")); 7 | const index_1 = require("../index"); 8 | const shortSuite = new benchmark_1.default.Suite("realworld"); 9 | const People = index_1.z.array(index_1.z.object({ 10 | type: index_1.z.literal("person"), 11 | hair: index_1.z.enum(["blue", "brown"]), 12 | active: index_1.z.boolean(), 13 | name: index_1.z.string(), 14 | age: index_1.z.number().int(), 15 | hobbies: index_1.z.array(index_1.z.string()), 16 | address: index_1.z.object({ 17 | street: index_1.z.string(), 18 | zip: index_1.z.string(), 19 | country: index_1.z.string(), 20 | }), 21 | })); 22 | let i = 0; 23 | function num() { 24 | return ++i; 25 | } 26 | function str() { 27 | return (++i % 100).toString(16); 28 | } 29 | function array(fn) { 30 | return Array.from({ length: ++i % 10 }, () => fn()); 31 | } 32 | const people = Array.from({ length: 100 }, () => { 33 | return { 34 | type: "person", 35 | hair: i % 2 ? "blue" : "brown", 36 | active: !!(i % 2), 37 | name: str(), 38 | age: num(), 39 | hobbies: array(str), 40 | address: { 41 | street: str(), 42 | zip: str(), 43 | country: str(), 44 | }, 45 | }; 46 | }); 47 | shortSuite 48 | .add("valid", () => { 49 | People.parse(people); 50 | }) 51 | .on("cycle", (e) => { 52 | console.log(`${shortSuite.name}: ${e.target}`); 53 | }); 54 | exports.default = { 55 | suites: [shortSuite], 56 | }; 57 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/benchmarks/string.d.ts: -------------------------------------------------------------------------------- 1 | import Benchmark from "benchmark"; 2 | declare const _default: { 3 | suites: Benchmark.Suite[]; 4 | }; 5 | export default _default; 6 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/benchmarks/string.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const benchmark_1 = __importDefault(require("benchmark")); 7 | const index_1 = require("../index"); 8 | const SUITE_NAME = "z.string"; 9 | const suite = new benchmark_1.default.Suite(SUITE_NAME); 10 | const empty = ""; 11 | const short = "short"; 12 | const long = "long".repeat(256); 13 | const manual = (str) => { 14 | if (typeof str !== "string") { 15 | throw new Error("Not a string"); 16 | } 17 | return str; 18 | }; 19 | const stringSchema = index_1.z.string(); 20 | const optionalStringSchema = index_1.z.string().optional(); 21 | const optionalNullableStringSchema = index_1.z.string().optional().nullable(); 22 | suite 23 | .add("empty string", () => { 24 | stringSchema.parse(empty); 25 | }) 26 | .add("short string", () => { 27 | stringSchema.parse(short); 28 | }) 29 | .add("long string", () => { 30 | stringSchema.parse(long); 31 | }) 32 | .add("optional string", () => { 33 | optionalStringSchema.parse(long); 34 | }) 35 | .add("nullable string", () => { 36 | optionalNullableStringSchema.parse(long); 37 | }) 38 | .add("nullable (null) string", () => { 39 | optionalNullableStringSchema.parse(null); 40 | }) 41 | .add("invalid: null", () => { 42 | try { 43 | stringSchema.parse(null); 44 | } 45 | catch (err) { } 46 | }) 47 | .add("manual parser: long", () => { 48 | manual(long); 49 | }) 50 | .on("cycle", (e) => { 51 | console.log(`${SUITE_NAME}: ${e.target}`); 52 | }); 53 | exports.default = { 54 | suites: [suite], 55 | }; 56 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/benchmarks/union.d.ts: -------------------------------------------------------------------------------- 1 | import Benchmark from "benchmark"; 2 | declare const _default: { 3 | suites: Benchmark.Suite[]; 4 | }; 5 | export default _default; 6 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/benchmarks/union.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const benchmark_1 = __importDefault(require("benchmark")); 7 | const index_1 = require("../index"); 8 | const doubleSuite = new benchmark_1.default.Suite("z.union: double"); 9 | const manySuite = new benchmark_1.default.Suite("z.union: many"); 10 | const aSchema = index_1.z.object({ 11 | type: index_1.z.literal("a"), 12 | }); 13 | const objA = { 14 | type: "a", 15 | }; 16 | const bSchema = index_1.z.object({ 17 | type: index_1.z.literal("b"), 18 | }); 19 | const objB = { 20 | type: "b", 21 | }; 22 | const cSchema = index_1.z.object({ 23 | type: index_1.z.literal("c"), 24 | }); 25 | const objC = { 26 | type: "c", 27 | }; 28 | const dSchema = index_1.z.object({ 29 | type: index_1.z.literal("d"), 30 | }); 31 | const double = index_1.z.union([aSchema, bSchema]); 32 | const many = index_1.z.union([aSchema, bSchema, cSchema, dSchema]); 33 | doubleSuite 34 | .add("valid: a", () => { 35 | double.parse(objA); 36 | }) 37 | .add("valid: b", () => { 38 | double.parse(objB); 39 | }) 40 | .add("invalid: null", () => { 41 | try { 42 | double.parse(null); 43 | } 44 | catch (err) { } 45 | }) 46 | .add("invalid: wrong shape", () => { 47 | try { 48 | double.parse(objC); 49 | } 50 | catch (err) { } 51 | }) 52 | .on("cycle", (e) => { 53 | console.log(`${doubleSuite.name}: ${e.target}`); 54 | }); 55 | manySuite 56 | .add("valid: a", () => { 57 | many.parse(objA); 58 | }) 59 | .add("valid: c", () => { 60 | many.parse(objC); 61 | }) 62 | .add("invalid: null", () => { 63 | try { 64 | many.parse(null); 65 | } 66 | catch (err) { } 67 | }) 68 | .add("invalid: wrong shape", () => { 69 | try { 70 | many.parse({ type: "unknown" }); 71 | } 72 | catch (err) { } 73 | }) 74 | .on("cycle", (e) => { 75 | console.log(`${manySuite.name}: ${e.target}`); 76 | }); 77 | exports.default = { 78 | suites: [doubleSuite, manySuite], 79 | }; 80 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/errors.d.ts: -------------------------------------------------------------------------------- 1 | import defaultErrorMap from "./locales/en"; 2 | import type { ZodErrorMap } from "./ZodError"; 3 | export { defaultErrorMap }; 4 | export declare function setErrorMap(map: ZodErrorMap): void; 5 | export declare function getErrorMap(): ZodErrorMap; 6 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/errors.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | exports.getErrorMap = exports.setErrorMap = exports.defaultErrorMap = void 0; 7 | const en_1 = __importDefault(require("./locales/en")); 8 | exports.defaultErrorMap = en_1.default; 9 | let overrideErrorMap = en_1.default; 10 | function setErrorMap(map) { 11 | overrideErrorMap = map; 12 | } 13 | exports.setErrorMap = setErrorMap; 14 | function getErrorMap() { 15 | return overrideErrorMap; 16 | } 17 | exports.getErrorMap = getErrorMap; 18 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/external.d.ts: -------------------------------------------------------------------------------- 1 | export * from "./errors"; 2 | export * from "./helpers/parseUtil"; 3 | export * from "./helpers/typeAliases"; 4 | export * from "./helpers/util"; 5 | export * from "./types"; 6 | export * from "./ZodError"; 7 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/external.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { 3 | if (k2 === undefined) k2 = k; 4 | Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); 5 | }) : (function(o, m, k, k2) { 6 | if (k2 === undefined) k2 = k; 7 | o[k2] = m[k]; 8 | })); 9 | var __exportStar = (this && this.__exportStar) || function(m, exports) { 10 | for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); 11 | }; 12 | Object.defineProperty(exports, "__esModule", { value: true }); 13 | __exportStar(require("./errors"), exports); 14 | __exportStar(require("./helpers/parseUtil"), exports); 15 | __exportStar(require("./helpers/typeAliases"), exports); 16 | __exportStar(require("./helpers/util"), exports); 17 | __exportStar(require("./types"), exports); 18 | __exportStar(require("./ZodError"), exports); 19 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/helpers/enumUtil.d.ts: -------------------------------------------------------------------------------- 1 | export declare namespace enumUtil { 2 | type UnionToIntersectionFn = (T extends unknown ? (k: () => T) => void : never) extends (k: infer Intersection) => void ? Intersection : never; 3 | type GetUnionLast = UnionToIntersectionFn extends () => infer Last ? Last : never; 4 | type UnionToTuple = [T] extends [never] ? Tuple : UnionToTuple>, [GetUnionLast, ...Tuple]>; 5 | type CastToStringTuple = T extends [string, ...string[]] ? T : never; 6 | export type UnionToTupleString = CastToStringTuple>; 7 | export {}; 8 | } 9 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/helpers/enumUtil.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/helpers/errorUtil.d.ts: -------------------------------------------------------------------------------- 1 | export declare namespace errorUtil { 2 | type ErrMessage = string | { 3 | message?: string; 4 | }; 5 | const errToObj: (message?: ErrMessage | undefined) => { 6 | message?: string | undefined; 7 | }; 8 | const toString: (message?: ErrMessage | undefined) => string | undefined; 9 | } 10 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/helpers/errorUtil.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.errorUtil = void 0; 4 | var errorUtil; 5 | (function (errorUtil) { 6 | errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {}; 7 | errorUtil.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message; 8 | })(errorUtil = exports.errorUtil || (exports.errorUtil = {})); 9 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/helpers/parseUtil.d.ts: -------------------------------------------------------------------------------- 1 | import type { IssueData, ZodErrorMap, ZodIssue } from "../ZodError"; 2 | import type { ZodParsedType } from "./util"; 3 | export declare const makeIssue: (params: { 4 | data: any; 5 | path: (string | number)[]; 6 | errorMaps: ZodErrorMap[]; 7 | issueData: IssueData; 8 | }) => ZodIssue; 9 | export declare type ParseParams = { 10 | path: (string | number)[]; 11 | errorMap: ZodErrorMap; 12 | async: boolean; 13 | }; 14 | export declare type ParsePathComponent = string | number; 15 | export declare type ParsePath = ParsePathComponent[]; 16 | export declare const EMPTY_PATH: ParsePath; 17 | export interface ParseContext { 18 | readonly common: { 19 | readonly issues: ZodIssue[]; 20 | readonly contextualErrorMap?: ZodErrorMap; 21 | readonly async: boolean; 22 | }; 23 | readonly path: ParsePath; 24 | readonly schemaErrorMap?: ZodErrorMap; 25 | readonly parent: ParseContext | null; 26 | readonly data: any; 27 | readonly parsedType: ZodParsedType; 28 | } 29 | export declare type ParseInput = { 30 | data: any; 31 | path: (string | number)[]; 32 | parent: ParseContext; 33 | }; 34 | export declare function addIssueToContext(ctx: ParseContext, issueData: IssueData): void; 35 | export declare type ObjectPair = { 36 | key: SyncParseReturnType; 37 | value: SyncParseReturnType; 38 | }; 39 | export declare class ParseStatus { 40 | value: "aborted" | "dirty" | "valid"; 41 | dirty(): void; 42 | abort(): void; 43 | static mergeArray(status: ParseStatus, results: SyncParseReturnType[]): SyncParseReturnType; 44 | static mergeObjectAsync(status: ParseStatus, pairs: { 45 | key: ParseReturnType; 46 | value: ParseReturnType; 47 | }[]): Promise>; 48 | static mergeObjectSync(status: ParseStatus, pairs: { 49 | key: SyncParseReturnType; 50 | value: SyncParseReturnType; 51 | alwaysSet?: boolean; 52 | }[]): SyncParseReturnType; 53 | } 54 | export interface ParseResult { 55 | status: "aborted" | "dirty" | "valid"; 56 | data: any; 57 | } 58 | export declare type INVALID = { 59 | status: "aborted"; 60 | }; 61 | export declare const INVALID: INVALID; 62 | export declare type DIRTY = { 63 | status: "dirty"; 64 | value: T; 65 | }; 66 | export declare const DIRTY: (value: T) => DIRTY; 67 | export declare type OK = { 68 | status: "valid"; 69 | value: T; 70 | }; 71 | export declare const OK: (value: T) => OK; 72 | export declare type SyncParseReturnType = OK | DIRTY | INVALID; 73 | export declare type AsyncParseReturnType = Promise>; 74 | export declare type ParseReturnType = SyncParseReturnType | AsyncParseReturnType; 75 | export declare const isAborted: (x: ParseReturnType) => x is INVALID; 76 | export declare const isDirty: (x: ParseReturnType) => x is OK | DIRTY; 77 | export declare const isValid: (x: ParseReturnType) => x is OK; 78 | export declare const isAsync: (x: ParseReturnType) => x is AsyncParseReturnType; 79 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/helpers/parseUtil.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | exports.isAsync = exports.isValid = exports.isDirty = exports.isAborted = exports.OK = exports.DIRTY = exports.INVALID = exports.ParseStatus = exports.addIssueToContext = exports.EMPTY_PATH = exports.makeIssue = void 0; 7 | const errors_1 = require("../errors"); 8 | const en_1 = __importDefault(require("../locales/en")); 9 | const makeIssue = (params) => { 10 | const { data, path, errorMaps, issueData } = params; 11 | const fullPath = [...path, ...(issueData.path || [])]; 12 | const fullIssue = { 13 | ...issueData, 14 | path: fullPath, 15 | }; 16 | if (issueData.message !== undefined) { 17 | return { 18 | ...issueData, 19 | path: fullPath, 20 | message: issueData.message, 21 | }; 22 | } 23 | let errorMessage = ""; 24 | const maps = errorMaps 25 | .filter((m) => !!m) 26 | .slice() 27 | .reverse(); 28 | for (const map of maps) { 29 | errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message; 30 | } 31 | return { 32 | ...issueData, 33 | path: fullPath, 34 | message: errorMessage, 35 | }; 36 | }; 37 | exports.makeIssue = makeIssue; 38 | exports.EMPTY_PATH = []; 39 | function addIssueToContext(ctx, issueData) { 40 | const overrideMap = (0, errors_1.getErrorMap)(); 41 | const issue = (0, exports.makeIssue)({ 42 | issueData: issueData, 43 | data: ctx.data, 44 | path: ctx.path, 45 | errorMaps: [ 46 | ctx.common.contextualErrorMap, 47 | ctx.schemaErrorMap, 48 | overrideMap, 49 | overrideMap === en_1.default ? undefined : en_1.default, // then global default map 50 | ].filter((x) => !!x), 51 | }); 52 | ctx.common.issues.push(issue); 53 | } 54 | exports.addIssueToContext = addIssueToContext; 55 | class ParseStatus { 56 | constructor() { 57 | this.value = "valid"; 58 | } 59 | dirty() { 60 | if (this.value === "valid") 61 | this.value = "dirty"; 62 | } 63 | abort() { 64 | if (this.value !== "aborted") 65 | this.value = "aborted"; 66 | } 67 | static mergeArray(status, results) { 68 | const arrayValue = []; 69 | for (const s of results) { 70 | if (s.status === "aborted") 71 | return exports.INVALID; 72 | if (s.status === "dirty") 73 | status.dirty(); 74 | arrayValue.push(s.value); 75 | } 76 | return { status: status.value, value: arrayValue }; 77 | } 78 | static async mergeObjectAsync(status, pairs) { 79 | const syncPairs = []; 80 | for (const pair of pairs) { 81 | const key = await pair.key; 82 | const value = await pair.value; 83 | syncPairs.push({ 84 | key, 85 | value, 86 | }); 87 | } 88 | return ParseStatus.mergeObjectSync(status, syncPairs); 89 | } 90 | static mergeObjectSync(status, pairs) { 91 | const finalObject = {}; 92 | for (const pair of pairs) { 93 | const { key, value } = pair; 94 | if (key.status === "aborted") 95 | return exports.INVALID; 96 | if (value.status === "aborted") 97 | return exports.INVALID; 98 | if (key.status === "dirty") 99 | status.dirty(); 100 | if (value.status === "dirty") 101 | status.dirty(); 102 | if (key.value !== "__proto__" && 103 | (typeof value.value !== "undefined" || pair.alwaysSet)) { 104 | finalObject[key.value] = value.value; 105 | } 106 | } 107 | return { status: status.value, value: finalObject }; 108 | } 109 | } 110 | exports.ParseStatus = ParseStatus; 111 | exports.INVALID = Object.freeze({ 112 | status: "aborted", 113 | }); 114 | const DIRTY = (value) => ({ status: "dirty", value }); 115 | exports.DIRTY = DIRTY; 116 | const OK = (value) => ({ status: "valid", value }); 117 | exports.OK = OK; 118 | const isAborted = (x) => x.status === "aborted"; 119 | exports.isAborted = isAborted; 120 | const isDirty = (x) => x.status === "dirty"; 121 | exports.isDirty = isDirty; 122 | const isValid = (x) => x.status === "valid"; 123 | exports.isValid = isValid; 124 | const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise; 125 | exports.isAsync = isAsync; 126 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/helpers/partialUtil.d.ts: -------------------------------------------------------------------------------- 1 | import type { ZodArray, ZodNullable, ZodObject, ZodOptional, ZodRawShape, ZodTuple, ZodTupleItems, ZodTypeAny } from "../index"; 2 | export declare namespace partialUtil { 3 | type DeepPartial = T extends ZodObject ? ZodObject<{ 4 | [k in keyof T["shape"]]: ZodOptional>; 5 | }, T["_def"]["unknownKeys"], T["_def"]["catchall"]> : T extends ZodArray ? ZodArray, Card> : T extends ZodOptional ? ZodOptional> : T extends ZodNullable ? ZodNullable> : T extends ZodTuple ? { 6 | [k in keyof Items]: Items[k] extends ZodTypeAny ? DeepPartial : never; 7 | } extends infer PI ? PI extends ZodTupleItems ? ZodTuple : never : never : T; 8 | } 9 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/helpers/partialUtil.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/helpers/typeAliases.d.ts: -------------------------------------------------------------------------------- 1 | export declare type Primitive = string | number | symbol | bigint | boolean | null | undefined; 2 | export declare type Scalars = Primitive | Primitive[]; 3 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/helpers/typeAliases.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/helpers/util.d.ts: -------------------------------------------------------------------------------- 1 | export declare namespace util { 2 | type AssertEqual = (() => V extends T ? 1 : 2) extends () => V extends U ? 1 : 2 ? true : false; 3 | export type isAny = 0 extends 1 & T ? true : false; 4 | export const assertEqual: (val: AssertEqual) => AssertEqual; 5 | export function assertIs(_arg: T): void; 6 | export function assertNever(_x: never): never; 7 | export type Omit = Pick>; 8 | export type OmitKeys = Pick>; 9 | export type MakePartial = Omit & Partial>; 10 | export type Exactly = T & Record, never>; 11 | export const arrayToEnum: (items: U) => { [k in U[number]]: k; }; 12 | export const getValidEnumValues: (obj: any) => any[]; 13 | export const objectValues: (obj: any) => any[]; 14 | export const objectKeys: ObjectConstructor["keys"]; 15 | export const find: (arr: T[], checker: (arg: T) => any) => T | undefined; 16 | export type identity = objectUtil.identity; 17 | export type flatten = objectUtil.flatten; 18 | export type noUndefined = T extends undefined ? never : T; 19 | export const isInteger: NumberConstructor["isInteger"]; 20 | export function joinValues(array: T, separator?: string): string; 21 | export const jsonStringifyReplacer: (_: string, value: any) => any; 22 | export {}; 23 | } 24 | export declare namespace objectUtil { 25 | export type MergeShapes = { 26 | [k in Exclude]: U[k]; 27 | } & V; 28 | type optionalKeys = { 29 | [k in keyof T]: undefined extends T[k] ? k : never; 30 | }[keyof T]; 31 | type requiredKeys = { 32 | [k in keyof T]: undefined extends T[k] ? never : k; 33 | }[keyof T]; 34 | export type addQuestionMarks = { 35 | [K in requiredKeys]: T[K]; 36 | } & { 37 | [K in optionalKeys]?: T[K]; 38 | } & { 39 | [k in keyof T]?: unknown; 40 | }; 41 | export type identity = T; 42 | export type flatten = identity<{ 43 | [k in keyof T]: T[k]; 44 | }>; 45 | export type noNeverKeys = { 46 | [k in keyof T]: [T[k]] extends [never] ? never : k; 47 | }[keyof T]; 48 | export type noNever = identity<{ 49 | [k in noNeverKeys]: k extends keyof T ? T[k] : never; 50 | }>; 51 | export const mergeShapes: (first: U, second: T) => T & U; 52 | export type extendShape = { 53 | [K in keyof A as K extends keyof B ? never : K]: A[K]; 54 | } & { 55 | [K in keyof B]: B[K]; 56 | }; 57 | export {}; 58 | } 59 | export declare const ZodParsedType: { 60 | function: "function"; 61 | number: "number"; 62 | string: "string"; 63 | nan: "nan"; 64 | integer: "integer"; 65 | float: "float"; 66 | boolean: "boolean"; 67 | date: "date"; 68 | bigint: "bigint"; 69 | symbol: "symbol"; 70 | undefined: "undefined"; 71 | null: "null"; 72 | array: "array"; 73 | object: "object"; 74 | unknown: "unknown"; 75 | promise: "promise"; 76 | void: "void"; 77 | never: "never"; 78 | map: "map"; 79 | set: "set"; 80 | }; 81 | export declare type ZodParsedType = keyof typeof ZodParsedType; 82 | export declare const getParsedType: (data: any) => ZodParsedType; 83 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/helpers/util.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.getParsedType = exports.ZodParsedType = exports.objectUtil = exports.util = void 0; 4 | var util; 5 | (function (util) { 6 | util.assertEqual = (val) => val; 7 | function assertIs(_arg) { } 8 | util.assertIs = assertIs; 9 | function assertNever(_x) { 10 | throw new Error(); 11 | } 12 | util.assertNever = assertNever; 13 | util.arrayToEnum = (items) => { 14 | const obj = {}; 15 | for (const item of items) { 16 | obj[item] = item; 17 | } 18 | return obj; 19 | }; 20 | util.getValidEnumValues = (obj) => { 21 | const validKeys = util.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number"); 22 | const filtered = {}; 23 | for (const k of validKeys) { 24 | filtered[k] = obj[k]; 25 | } 26 | return util.objectValues(filtered); 27 | }; 28 | util.objectValues = (obj) => { 29 | return util.objectKeys(obj).map(function (e) { 30 | return obj[e]; 31 | }); 32 | }; 33 | util.objectKeys = typeof Object.keys === "function" // eslint-disable-line ban/ban 34 | ? (obj) => Object.keys(obj) // eslint-disable-line ban/ban 35 | : (object) => { 36 | const keys = []; 37 | for (const key in object) { 38 | if (Object.prototype.hasOwnProperty.call(object, key)) { 39 | keys.push(key); 40 | } 41 | } 42 | return keys; 43 | }; 44 | util.find = (arr, checker) => { 45 | for (const item of arr) { 46 | if (checker(item)) 47 | return item; 48 | } 49 | return undefined; 50 | }; 51 | util.isInteger = typeof Number.isInteger === "function" 52 | ? (val) => Number.isInteger(val) // eslint-disable-line ban/ban 53 | : (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val; 54 | function joinValues(array, separator = " | ") { 55 | return array 56 | .map((val) => (typeof val === "string" ? `'${val}'` : val)) 57 | .join(separator); 58 | } 59 | util.joinValues = joinValues; 60 | util.jsonStringifyReplacer = (_, value) => { 61 | if (typeof value === "bigint") { 62 | return value.toString(); 63 | } 64 | return value; 65 | }; 66 | })(util = exports.util || (exports.util = {})); 67 | var objectUtil; 68 | (function (objectUtil) { 69 | objectUtil.mergeShapes = (first, second) => { 70 | return { 71 | ...first, 72 | ...second, // second overwrites first 73 | }; 74 | }; 75 | })(objectUtil = exports.objectUtil || (exports.objectUtil = {})); 76 | exports.ZodParsedType = util.arrayToEnum([ 77 | "string", 78 | "nan", 79 | "number", 80 | "integer", 81 | "float", 82 | "boolean", 83 | "date", 84 | "bigint", 85 | "symbol", 86 | "function", 87 | "undefined", 88 | "null", 89 | "array", 90 | "object", 91 | "unknown", 92 | "promise", 93 | "void", 94 | "never", 95 | "map", 96 | "set", 97 | ]); 98 | const getParsedType = (data) => { 99 | const t = typeof data; 100 | switch (t) { 101 | case "undefined": 102 | return exports.ZodParsedType.undefined; 103 | case "string": 104 | return exports.ZodParsedType.string; 105 | case "number": 106 | return isNaN(data) ? exports.ZodParsedType.nan : exports.ZodParsedType.number; 107 | case "boolean": 108 | return exports.ZodParsedType.boolean; 109 | case "function": 110 | return exports.ZodParsedType.function; 111 | case "bigint": 112 | return exports.ZodParsedType.bigint; 113 | case "symbol": 114 | return exports.ZodParsedType.symbol; 115 | case "object": 116 | if (Array.isArray(data)) { 117 | return exports.ZodParsedType.array; 118 | } 119 | if (data === null) { 120 | return exports.ZodParsedType.null; 121 | } 122 | if (data.then && 123 | typeof data.then === "function" && 124 | data.catch && 125 | typeof data.catch === "function") { 126 | return exports.ZodParsedType.promise; 127 | } 128 | if (typeof Map !== "undefined" && data instanceof Map) { 129 | return exports.ZodParsedType.map; 130 | } 131 | if (typeof Set !== "undefined" && data instanceof Set) { 132 | return exports.ZodParsedType.set; 133 | } 134 | if (typeof Date !== "undefined" && data instanceof Date) { 135 | return exports.ZodParsedType.date; 136 | } 137 | return exports.ZodParsedType.object; 138 | default: 139 | return exports.ZodParsedType.unknown; 140 | } 141 | }; 142 | exports.getParsedType = getParsedType; 143 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/index.d.ts: -------------------------------------------------------------------------------- 1 | import * as z from "./external"; 2 | export * from "./external"; 3 | export { z }; 4 | export default z; 5 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { 3 | if (k2 === undefined) k2 = k; 4 | Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); 5 | }) : (function(o, m, k, k2) { 6 | if (k2 === undefined) k2 = k; 7 | o[k2] = m[k]; 8 | })); 9 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { 10 | Object.defineProperty(o, "default", { enumerable: true, value: v }); 11 | }) : function(o, v) { 12 | o["default"] = v; 13 | }); 14 | var __importStar = (this && this.__importStar) || function (mod) { 15 | if (mod && mod.__esModule) return mod; 16 | var result = {}; 17 | if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); 18 | __setModuleDefault(result, mod); 19 | return result; 20 | }; 21 | var __exportStar = (this && this.__exportStar) || function(m, exports) { 22 | for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); 23 | }; 24 | Object.defineProperty(exports, "__esModule", { value: true }); 25 | exports.z = void 0; 26 | const z = __importStar(require("./external")); 27 | exports.z = z; 28 | __exportStar(require("./external"), exports); 29 | exports.default = z; 30 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/locales/en.d.ts: -------------------------------------------------------------------------------- 1 | import { ZodErrorMap } from "../ZodError"; 2 | declare const errorMap: ZodErrorMap; 3 | export default errorMap; 4 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/locales/en.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | const util_1 = require("../helpers/util"); 4 | const ZodError_1 = require("../ZodError"); 5 | const errorMap = (issue, _ctx) => { 6 | let message; 7 | switch (issue.code) { 8 | case ZodError_1.ZodIssueCode.invalid_type: 9 | if (issue.received === util_1.ZodParsedType.undefined) { 10 | message = "Required"; 11 | } 12 | else { 13 | message = `Expected ${issue.expected}, received ${issue.received}`; 14 | } 15 | break; 16 | case ZodError_1.ZodIssueCode.invalid_literal: 17 | message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util_1.util.jsonStringifyReplacer)}`; 18 | break; 19 | case ZodError_1.ZodIssueCode.unrecognized_keys: 20 | message = `Unrecognized key(s) in object: ${util_1.util.joinValues(issue.keys, ", ")}`; 21 | break; 22 | case ZodError_1.ZodIssueCode.invalid_union: 23 | message = `Invalid input`; 24 | break; 25 | case ZodError_1.ZodIssueCode.invalid_union_discriminator: 26 | message = `Invalid discriminator value. Expected ${util_1.util.joinValues(issue.options)}`; 27 | break; 28 | case ZodError_1.ZodIssueCode.invalid_enum_value: 29 | message = `Invalid enum value. Expected ${util_1.util.joinValues(issue.options)}, received '${issue.received}'`; 30 | break; 31 | case ZodError_1.ZodIssueCode.invalid_arguments: 32 | message = `Invalid function arguments`; 33 | break; 34 | case ZodError_1.ZodIssueCode.invalid_return_type: 35 | message = `Invalid function return type`; 36 | break; 37 | case ZodError_1.ZodIssueCode.invalid_date: 38 | message = `Invalid date`; 39 | break; 40 | case ZodError_1.ZodIssueCode.invalid_string: 41 | if (typeof issue.validation === "object") { 42 | if ("includes" in issue.validation) { 43 | message = `Invalid input: must include "${issue.validation.includes}"`; 44 | if (typeof issue.validation.position === "number") { 45 | message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`; 46 | } 47 | } 48 | else if ("startsWith" in issue.validation) { 49 | message = `Invalid input: must start with "${issue.validation.startsWith}"`; 50 | } 51 | else if ("endsWith" in issue.validation) { 52 | message = `Invalid input: must end with "${issue.validation.endsWith}"`; 53 | } 54 | else { 55 | util_1.util.assertNever(issue.validation); 56 | } 57 | } 58 | else if (issue.validation !== "regex") { 59 | message = `Invalid ${issue.validation}`; 60 | } 61 | else { 62 | message = "Invalid"; 63 | } 64 | break; 65 | case ZodError_1.ZodIssueCode.too_small: 66 | if (issue.type === "array") 67 | message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`; 68 | else if (issue.type === "string") 69 | message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`; 70 | else if (issue.type === "number") 71 | message = `Number must be ${issue.exact 72 | ? `exactly equal to ` 73 | : issue.inclusive 74 | ? `greater than or equal to ` 75 | : `greater than `}${issue.minimum}`; 76 | else if (issue.type === "date") 77 | message = `Date must be ${issue.exact 78 | ? `exactly equal to ` 79 | : issue.inclusive 80 | ? `greater than or equal to ` 81 | : `greater than `}${new Date(Number(issue.minimum))}`; 82 | else 83 | message = "Invalid input"; 84 | break; 85 | case ZodError_1.ZodIssueCode.too_big: 86 | if (issue.type === "array") 87 | message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`; 88 | else if (issue.type === "string") 89 | message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`; 90 | else if (issue.type === "number") 91 | message = `Number must be ${issue.exact 92 | ? `exactly` 93 | : issue.inclusive 94 | ? `less than or equal to` 95 | : `less than`} ${issue.maximum}`; 96 | else if (issue.type === "bigint") 97 | message = `BigInt must be ${issue.exact 98 | ? `exactly` 99 | : issue.inclusive 100 | ? `less than or equal to` 101 | : `less than`} ${issue.maximum}`; 102 | else if (issue.type === "date") 103 | message = `Date must be ${issue.exact 104 | ? `exactly` 105 | : issue.inclusive 106 | ? `smaller than or equal to` 107 | : `smaller than`} ${new Date(Number(issue.maximum))}`; 108 | else 109 | message = "Invalid input"; 110 | break; 111 | case ZodError_1.ZodIssueCode.custom: 112 | message = `Invalid input`; 113 | break; 114 | case ZodError_1.ZodIssueCode.invalid_intersection_types: 115 | message = `Intersection results could not be merged`; 116 | break; 117 | case ZodError_1.ZodIssueCode.not_multiple_of: 118 | message = `Number must be a multiple of ${issue.multipleOf}`; 119 | break; 120 | case ZodError_1.ZodIssueCode.not_finite: 121 | message = "Number must be finite"; 122 | break; 123 | default: 124 | message = _ctx.defaultError; 125 | util_1.util.assertNever(issue); 126 | } 127 | return { message }; 128 | }; 129 | exports.default = errorMap; 130 | -------------------------------------------------------------------------------- /common/node_modules/zod/lib/types.d.ts: -------------------------------------------------------------------------------- 1 | import { enumUtil } from "./helpers/enumUtil"; 2 | import { errorUtil } from "./helpers/errorUtil"; 3 | import { AsyncParseReturnType, ParseContext, ParseInput, ParseParams, ParseReturnType, ParseStatus, SyncParseReturnType } from "./helpers/parseUtil"; 4 | import { partialUtil } from "./helpers/partialUtil"; 5 | import { Primitive } from "./helpers/typeAliases"; 6 | import { objectUtil, util } from "./helpers/util"; 7 | import { IssueData, StringValidation, ZodCustomIssue, ZodError, ZodErrorMap } from "./ZodError"; 8 | export interface RefinementCtx { 9 | addIssue: (arg: IssueData) => void; 10 | path: (string | number)[]; 11 | } 12 | export declare type ZodRawShape = { 13 | [k: string]: ZodTypeAny; 14 | }; 15 | export declare type ZodTypeAny = ZodType; 16 | export declare type TypeOf> = T["_output"]; 17 | export declare type input> = T["_input"]; 18 | export declare type output> = T["_output"]; 19 | export type { TypeOf as infer }; 20 | export declare type CustomErrorParams = Partial>; 21 | export interface ZodTypeDef { 22 | errorMap?: ZodErrorMap; 23 | description?: string; 24 | } 25 | export declare type RawCreateParams = { 26 | errorMap?: ZodErrorMap; 27 | invalid_type_error?: string; 28 | required_error?: string; 29 | message?: string; 30 | description?: string; 31 | } | undefined; 32 | export declare type ProcessedCreateParams = { 33 | errorMap?: ZodErrorMap; 34 | description?: string; 35 | }; 36 | export declare type SafeParseSuccess = { 37 | success: true; 38 | data: Output; 39 | error?: never; 40 | }; 41 | export declare type SafeParseError = { 42 | success: false; 43 | error: ZodError; 44 | data?: never; 45 | }; 46 | export declare type SafeParseReturnType = SafeParseSuccess | SafeParseError; 47 | export declare abstract class ZodType { 48 | readonly _type: Output; 49 | readonly _output: Output; 50 | readonly _input: Input; 51 | readonly _def: Def; 52 | get description(): string | undefined; 53 | abstract _parse(input: ParseInput): ParseReturnType; 54 | _getType(input: ParseInput): string; 55 | _getOrReturnCtx(input: ParseInput, ctx?: ParseContext | undefined): ParseContext; 56 | _processInputParams(input: ParseInput): { 57 | status: ParseStatus; 58 | ctx: ParseContext; 59 | }; 60 | _parseSync(input: ParseInput): SyncParseReturnType; 61 | _parseAsync(input: ParseInput): AsyncParseReturnType; 62 | parse(data: unknown, params?: Partial): Output; 63 | safeParse(data: unknown, params?: Partial): SafeParseReturnType; 64 | parseAsync(data: unknown, params?: Partial): Promise; 65 | safeParseAsync(data: unknown, params?: Partial): Promise>; 66 | /** Alias of safeParseAsync */ 67 | spa: (data: unknown, params?: Partial | undefined) => Promise>; 68 | refine(check: (arg: Output) => arg is RefinedOutput, message?: string | CustomErrorParams | ((arg: Output) => CustomErrorParams)): ZodEffects; 69 | refine(check: (arg: Output) => unknown | Promise, message?: string | CustomErrorParams | ((arg: Output) => CustomErrorParams)): ZodEffects; 70 | refinement(check: (arg: Output) => arg is RefinedOutput, refinementData: IssueData | ((arg: Output, ctx: RefinementCtx) => IssueData)): ZodEffects; 71 | refinement(check: (arg: Output) => boolean, refinementData: IssueData | ((arg: Output, ctx: RefinementCtx) => IssueData)): ZodEffects; 72 | _refinement(refinement: RefinementEffect["refinement"]): ZodEffects; 73 | superRefine(refinement: (arg: Output, ctx: RefinementCtx) => arg is RefinedOutput): ZodEffects; 74 | superRefine(refinement: (arg: Output, ctx: RefinementCtx) => void): ZodEffects; 75 | superRefine(refinement: (arg: Output, ctx: RefinementCtx) => Promise): ZodEffects; 76 | constructor(def: Def); 77 | optional(): ZodOptional; 78 | nullable(): ZodNullable; 79 | nullish(): ZodOptional>; 80 | array(): ZodArray; 81 | promise(): ZodPromise; 82 | or(option: T): ZodUnion<[this, T]>; 83 | and(incoming: T): ZodIntersection; 84 | transform(transform: (arg: Output, ctx: RefinementCtx) => NewOut | Promise): ZodEffects; 85 | default(def: util.noUndefined): ZodDefault; 86 | default(def: () => util.noUndefined): ZodDefault; 87 | brand(brand?: B): ZodBranded; 88 | catch(def: Output): ZodCatch; 89 | catch(def: (ctx: { 90 | error: ZodError; 91 | input: Input; 92 | }) => Output): ZodCatch; 93 | describe(description: string): this; 94 | pipe(target: T): ZodPipeline; 95 | readonly(): ZodReadonly; 96 | isOptional(): boolean; 97 | isNullable(): boolean; 98 | } 99 | export declare type IpVersion = "v4" | "v6"; 100 | export declare type ZodStringCheck = { 101 | kind: "min"; 102 | value: number; 103 | message?: string; 104 | } | { 105 | kind: "max"; 106 | value: number; 107 | message?: string; 108 | } | { 109 | kind: "length"; 110 | value: number; 111 | message?: string; 112 | } | { 113 | kind: "email"; 114 | message?: string; 115 | } | { 116 | kind: "url"; 117 | message?: string; 118 | } | { 119 | kind: "emoji"; 120 | message?: string; 121 | } | { 122 | kind: "uuid"; 123 | message?: string; 124 | } | { 125 | kind: "nanoid"; 126 | message?: string; 127 | } | { 128 | kind: "cuid"; 129 | message?: string; 130 | } | { 131 | kind: "includes"; 132 | value: string; 133 | position?: number; 134 | message?: string; 135 | } | { 136 | kind: "cuid2"; 137 | message?: string; 138 | } | { 139 | kind: "ulid"; 140 | message?: string; 141 | } | { 142 | kind: "startsWith"; 143 | value: string; 144 | message?: string; 145 | } | { 146 | kind: "endsWith"; 147 | value: string; 148 | message?: string; 149 | } | { 150 | kind: "regex"; 151 | regex: RegExp; 152 | message?: string; 153 | } | { 154 | kind: "trim"; 155 | message?: string; 156 | } | { 157 | kind: "toLowerCase"; 158 | message?: string; 159 | } | { 160 | kind: "toUpperCase"; 161 | message?: string; 162 | } | { 163 | kind: "datetime"; 164 | offset: boolean; 165 | local: boolean; 166 | precision: number | null; 167 | message?: string; 168 | } | { 169 | kind: "date"; 170 | message?: string; 171 | } | { 172 | kind: "time"; 173 | precision: number | null; 174 | message?: string; 175 | } | { 176 | kind: "duration"; 177 | message?: string; 178 | } | { 179 | kind: "ip"; 180 | version?: IpVersion; 181 | message?: string; 182 | } | { 183 | kind: "base64"; 184 | message?: string; 185 | }; 186 | export interface ZodStringDef extends ZodTypeDef { 187 | checks: ZodStringCheck[]; 188 | typeName: ZodFirstPartyTypeKind.ZodString; 189 | coerce: boolean; 190 | } 191 | export declare function datetimeRegex(args: { 192 | precision?: number | null; 193 | offset?: boolean; 194 | local?: boolean; 195 | }): RegExp; 196 | export declare class ZodString extends ZodType { 197 | _parse(input: ParseInput): ParseReturnType; 198 | protected _regex(regex: RegExp, validation: StringValidation, message?: errorUtil.ErrMessage): ZodEffects; 199 | _addCheck(check: ZodStringCheck): ZodString; 200 | email(message?: errorUtil.ErrMessage): ZodString; 201 | url(message?: errorUtil.ErrMessage): ZodString; 202 | emoji(message?: errorUtil.ErrMessage): ZodString; 203 | uuid(message?: errorUtil.ErrMessage): ZodString; 204 | nanoid(message?: errorUtil.ErrMessage): ZodString; 205 | cuid(message?: errorUtil.ErrMessage): ZodString; 206 | cuid2(message?: errorUtil.ErrMessage): ZodString; 207 | ulid(message?: errorUtil.ErrMessage): ZodString; 208 | base64(message?: errorUtil.ErrMessage): ZodString; 209 | ip(options?: string | { 210 | version?: "v4" | "v6"; 211 | message?: string; 212 | }): ZodString; 213 | datetime(options?: string | { 214 | message?: string | undefined; 215 | precision?: number | null; 216 | offset?: boolean; 217 | local?: boolean; 218 | }): ZodString; 219 | date(message?: string): ZodString; 220 | time(options?: string | { 221 | message?: string | undefined; 222 | precision?: number | null; 223 | }): ZodString; 224 | duration(message?: errorUtil.ErrMessage): ZodString; 225 | regex(regex: RegExp, message?: errorUtil.ErrMessage): ZodString; 226 | includes(value: string, options?: { 227 | message?: string; 228 | position?: number; 229 | }): ZodString; 230 | startsWith(value: string, message?: errorUtil.ErrMessage): ZodString; 231 | endsWith(value: string, message?: errorUtil.ErrMessage): ZodString; 232 | min(minLength: number, message?: errorUtil.ErrMessage): ZodString; 233 | max(maxLength: number, message?: errorUtil.ErrMessage): ZodString; 234 | length(len: number, message?: errorUtil.ErrMessage): ZodString; 235 | /** 236 | * @deprecated Use z.string().min(1) instead. 237 | * @see {@link ZodString.min} 238 | */ 239 | nonempty(message?: errorUtil.ErrMessage): ZodString; 240 | trim(): ZodString; 241 | toLowerCase(): ZodString; 242 | toUpperCase(): ZodString; 243 | get isDatetime(): boolean; 244 | get isDate(): boolean; 245 | get isTime(): boolean; 246 | get isDuration(): boolean; 247 | get isEmail(): boolean; 248 | get isURL(): boolean; 249 | get isEmoji(): boolean; 250 | get isUUID(): boolean; 251 | get isNANOID(): boolean; 252 | get isCUID(): boolean; 253 | get isCUID2(): boolean; 254 | get isULID(): boolean; 255 | get isIP(): boolean; 256 | get isBase64(): boolean; 257 | get minLength(): number | null; 258 | get maxLength(): number | null; 259 | static create: (params?: ({ 260 | errorMap?: ZodErrorMap | undefined; 261 | invalid_type_error?: string | undefined; 262 | required_error?: string | undefined; 263 | message?: string | undefined; 264 | description?: string | undefined; 265 | } & { 266 | coerce?: true | undefined; 267 | }) | undefined) => ZodString; 268 | } 269 | export declare type ZodNumberCheck = { 270 | kind: "min"; 271 | value: number; 272 | inclusive: boolean; 273 | message?: string; 274 | } | { 275 | kind: "max"; 276 | value: number; 277 | inclusive: boolean; 278 | message?: string; 279 | } | { 280 | kind: "int"; 281 | message?: string; 282 | } | { 283 | kind: "multipleOf"; 284 | value: number; 285 | message?: string; 286 | } | { 287 | kind: "finite"; 288 | message?: string; 289 | }; 290 | export interface ZodNumberDef extends ZodTypeDef { 291 | checks: ZodNumberCheck[]; 292 | typeName: ZodFirstPartyTypeKind.ZodNumber; 293 | coerce: boolean; 294 | } 295 | export declare class ZodNumber extends ZodType { 296 | _parse(input: ParseInput): ParseReturnType; 297 | static create: (params?: ({ 298 | errorMap?: ZodErrorMap | undefined; 299 | invalid_type_error?: string | undefined; 300 | required_error?: string | undefined; 301 | message?: string | undefined; 302 | description?: string | undefined; 303 | } & { 304 | coerce?: boolean | undefined; 305 | }) | undefined) => ZodNumber; 306 | gte(value: number, message?: errorUtil.ErrMessage): ZodNumber; 307 | min: (value: number, message?: errorUtil.ErrMessage | undefined) => ZodNumber; 308 | gt(value: number, message?: errorUtil.ErrMessage): ZodNumber; 309 | lte(value: number, message?: errorUtil.ErrMessage): ZodNumber; 310 | max: (value: number, message?: errorUtil.ErrMessage | undefined) => ZodNumber; 311 | lt(value: number, message?: errorUtil.ErrMessage): ZodNumber; 312 | protected setLimit(kind: "min" | "max", value: number, inclusive: boolean, message?: string): ZodNumber; 313 | _addCheck(check: ZodNumberCheck): ZodNumber; 314 | int(message?: errorUtil.ErrMessage): ZodNumber; 315 | positive(message?: errorUtil.ErrMessage): ZodNumber; 316 | negative(message?: errorUtil.ErrMessage): ZodNumber; 317 | nonpositive(message?: errorUtil.ErrMessage): ZodNumber; 318 | nonnegative(message?: errorUtil.ErrMessage): ZodNumber; 319 | multipleOf(value: number, message?: errorUtil.ErrMessage): ZodNumber; 320 | step: (value: number, message?: errorUtil.ErrMessage | undefined) => ZodNumber; 321 | finite(message?: errorUtil.ErrMessage): ZodNumber; 322 | safe(message?: errorUtil.ErrMessage): ZodNumber; 323 | get minValue(): number | null; 324 | get maxValue(): number | null; 325 | get isInt(): boolean; 326 | get isFinite(): boolean; 327 | } 328 | export declare type ZodBigIntCheck = { 329 | kind: "min"; 330 | value: bigint; 331 | inclusive: boolean; 332 | message?: string; 333 | } | { 334 | kind: "max"; 335 | value: bigint; 336 | inclusive: boolean; 337 | message?: string; 338 | } | { 339 | kind: "multipleOf"; 340 | value: bigint; 341 | message?: string; 342 | }; 343 | export interface ZodBigIntDef extends ZodTypeDef { 344 | checks: ZodBigIntCheck[]; 345 | typeName: ZodFirstPartyTypeKind.ZodBigInt; 346 | coerce: boolean; 347 | } 348 | export declare class ZodBigInt extends ZodType { 349 | _parse(input: ParseInput): ParseReturnType; 350 | static create: (params?: ({ 351 | errorMap?: ZodErrorMap | undefined; 352 | invalid_type_error?: string | undefined; 353 | required_error?: string | undefined; 354 | message?: string | undefined; 355 | description?: string | undefined; 356 | } & { 357 | coerce?: boolean | undefined; 358 | }) | undefined) => ZodBigInt; 359 | gte(value: bigint, message?: errorUtil.ErrMessage): ZodBigInt; 360 | min: (value: bigint, message?: errorUtil.ErrMessage | undefined) => ZodBigInt; 361 | gt(value: bigint, message?: errorUtil.ErrMessage): ZodBigInt; 362 | lte(value: bigint, message?: errorUtil.ErrMessage): ZodBigInt; 363 | max: (value: bigint, message?: errorUtil.ErrMessage | undefined) => ZodBigInt; 364 | lt(value: bigint, message?: errorUtil.ErrMessage): ZodBigInt; 365 | protected setLimit(kind: "min" | "max", value: bigint, inclusive: boolean, message?: string): ZodBigInt; 366 | _addCheck(check: ZodBigIntCheck): ZodBigInt; 367 | positive(message?: errorUtil.ErrMessage): ZodBigInt; 368 | negative(message?: errorUtil.ErrMessage): ZodBigInt; 369 | nonpositive(message?: errorUtil.ErrMessage): ZodBigInt; 370 | nonnegative(message?: errorUtil.ErrMessage): ZodBigInt; 371 | multipleOf(value: bigint, message?: errorUtil.ErrMessage): ZodBigInt; 372 | get minValue(): bigint | null; 373 | get maxValue(): bigint | null; 374 | } 375 | export interface ZodBooleanDef extends ZodTypeDef { 376 | typeName: ZodFirstPartyTypeKind.ZodBoolean; 377 | coerce: boolean; 378 | } 379 | export declare class ZodBoolean extends ZodType { 380 | _parse(input: ParseInput): ParseReturnType; 381 | static create: (params?: ({ 382 | errorMap?: ZodErrorMap | undefined; 383 | invalid_type_error?: string | undefined; 384 | required_error?: string | undefined; 385 | message?: string | undefined; 386 | description?: string | undefined; 387 | } & { 388 | coerce?: boolean | undefined; 389 | }) | undefined) => ZodBoolean; 390 | } 391 | export declare type ZodDateCheck = { 392 | kind: "min"; 393 | value: number; 394 | message?: string; 395 | } | { 396 | kind: "max"; 397 | value: number; 398 | message?: string; 399 | }; 400 | export interface ZodDateDef extends ZodTypeDef { 401 | checks: ZodDateCheck[]; 402 | coerce: boolean; 403 | typeName: ZodFirstPartyTypeKind.ZodDate; 404 | } 405 | export declare class ZodDate extends ZodType { 406 | _parse(input: ParseInput): ParseReturnType; 407 | _addCheck(check: ZodDateCheck): ZodDate; 408 | min(minDate: Date, message?: errorUtil.ErrMessage): ZodDate; 409 | max(maxDate: Date, message?: errorUtil.ErrMessage): ZodDate; 410 | get minDate(): Date | null; 411 | get maxDate(): Date | null; 412 | static create: (params?: ({ 413 | errorMap?: ZodErrorMap | undefined; 414 | invalid_type_error?: string | undefined; 415 | required_error?: string | undefined; 416 | message?: string | undefined; 417 | description?: string | undefined; 418 | } & { 419 | coerce?: boolean | undefined; 420 | }) | undefined) => ZodDate; 421 | } 422 | export interface ZodSymbolDef extends ZodTypeDef { 423 | typeName: ZodFirstPartyTypeKind.ZodSymbol; 424 | } 425 | export declare class ZodSymbol extends ZodType { 426 | _parse(input: ParseInput): ParseReturnType; 427 | static create: (params?: RawCreateParams) => ZodSymbol; 428 | } 429 | export interface ZodUndefinedDef extends ZodTypeDef { 430 | typeName: ZodFirstPartyTypeKind.ZodUndefined; 431 | } 432 | export declare class ZodUndefined extends ZodType { 433 | _parse(input: ParseInput): ParseReturnType; 434 | params?: RawCreateParams; 435 | static create: (params?: RawCreateParams) => ZodUndefined; 436 | } 437 | export interface ZodNullDef extends ZodTypeDef { 438 | typeName: ZodFirstPartyTypeKind.ZodNull; 439 | } 440 | export declare class ZodNull extends ZodType { 441 | _parse(input: ParseInput): ParseReturnType; 442 | static create: (params?: RawCreateParams) => ZodNull; 443 | } 444 | export interface ZodAnyDef extends ZodTypeDef { 445 | typeName: ZodFirstPartyTypeKind.ZodAny; 446 | } 447 | export declare class ZodAny extends ZodType { 448 | _any: true; 449 | _parse(input: ParseInput): ParseReturnType; 450 | static create: (params?: RawCreateParams) => ZodAny; 451 | } 452 | export interface ZodUnknownDef extends ZodTypeDef { 453 | typeName: ZodFirstPartyTypeKind.ZodUnknown; 454 | } 455 | export declare class ZodUnknown extends ZodType { 456 | _unknown: true; 457 | _parse(input: ParseInput): ParseReturnType; 458 | static create: (params?: RawCreateParams) => ZodUnknown; 459 | } 460 | export interface ZodNeverDef extends ZodTypeDef { 461 | typeName: ZodFirstPartyTypeKind.ZodNever; 462 | } 463 | export declare class ZodNever extends ZodType { 464 | _parse(input: ParseInput): ParseReturnType; 465 | static create: (params?: RawCreateParams) => ZodNever; 466 | } 467 | export interface ZodVoidDef extends ZodTypeDef { 468 | typeName: ZodFirstPartyTypeKind.ZodVoid; 469 | } 470 | export declare class ZodVoid extends ZodType { 471 | _parse(input: ParseInput): ParseReturnType; 472 | static create: (params?: RawCreateParams) => ZodVoid; 473 | } 474 | export interface ZodArrayDef extends ZodTypeDef { 475 | type: T; 476 | typeName: ZodFirstPartyTypeKind.ZodArray; 477 | exactLength: { 478 | value: number; 479 | message?: string; 480 | } | null; 481 | minLength: { 482 | value: number; 483 | message?: string; 484 | } | null; 485 | maxLength: { 486 | value: number; 487 | message?: string; 488 | } | null; 489 | } 490 | export declare type ArrayCardinality = "many" | "atleastone"; 491 | export declare type arrayOutputType = Cardinality extends "atleastone" ? [T["_output"], ...T["_output"][]] : T["_output"][]; 492 | export declare class ZodArray extends ZodType, ZodArrayDef, Cardinality extends "atleastone" ? [T["_input"], ...T["_input"][]] : T["_input"][]> { 493 | _parse(input: ParseInput): ParseReturnType; 494 | get element(): T; 495 | min(minLength: number, message?: errorUtil.ErrMessage): this; 496 | max(maxLength: number, message?: errorUtil.ErrMessage): this; 497 | length(len: number, message?: errorUtil.ErrMessage): this; 498 | nonempty(message?: errorUtil.ErrMessage): ZodArray; 499 | static create: (schema: T_1, params?: RawCreateParams) => ZodArray; 500 | } 501 | export declare type ZodNonEmptyArray = ZodArray; 502 | export declare type UnknownKeysParam = "passthrough" | "strict" | "strip"; 503 | export interface ZodObjectDef extends ZodTypeDef { 504 | typeName: ZodFirstPartyTypeKind.ZodObject; 505 | shape: () => T; 506 | catchall: Catchall; 507 | unknownKeys: UnknownKeys; 508 | } 509 | export declare type mergeTypes = { 510 | [k in keyof A | keyof B]: k extends keyof B ? B[k] : k extends keyof A ? A[k] : never; 511 | }; 512 | export declare type objectOutputType = objectUtil.flatten>> & CatchallOutput & PassthroughType; 513 | export declare type baseObjectOutputType = { 514 | [k in keyof Shape]: Shape[k]["_output"]; 515 | }; 516 | export declare type objectInputType = objectUtil.flatten> & CatchallInput & PassthroughType; 517 | export declare type baseObjectInputType = objectUtil.addQuestionMarks<{ 518 | [k in keyof Shape]: Shape[k]["_input"]; 519 | }>; 520 | export declare type CatchallOutput = ZodType extends T ? unknown : { 521 | [k: string]: T["_output"]; 522 | }; 523 | export declare type CatchallInput = ZodType extends T ? unknown : { 524 | [k: string]: T["_input"]; 525 | }; 526 | export declare type PassthroughType = T extends "passthrough" ? { 527 | [k: string]: unknown; 528 | } : unknown; 529 | export declare type deoptional = T extends ZodOptional ? deoptional : T extends ZodNullable ? ZodNullable> : T; 530 | export declare type SomeZodObject = ZodObject; 531 | export declare type noUnrecognized = { 532 | [k in keyof Obj]: k extends keyof Shape ? Obj[k] : never; 533 | }; 534 | export declare class ZodObject, Input = objectInputType> extends ZodType, Input> { 535 | private _cached; 536 | _getCached(): { 537 | shape: T; 538 | keys: string[]; 539 | }; 540 | _parse(input: ParseInput): ParseReturnType; 541 | get shape(): T; 542 | strict(message?: errorUtil.ErrMessage): ZodObject; 543 | strip(): ZodObject; 544 | passthrough(): ZodObject; 545 | /** 546 | * @deprecated In most cases, this is no longer needed - unknown properties are now silently stripped. 547 | * If you want to pass through unknown properties, use `.passthrough()` instead. 548 | */ 549 | nonstrict: () => ZodObject; 550 | extend(augmentation: Augmentation): ZodObject, UnknownKeys, Catchall>; 551 | /** 552 | * @deprecated Use `.extend` instead 553 | * */ 554 | augment: (augmentation: Augmentation) => ZodObject, UnknownKeys, Catchall, objectOutputType, Catchall, UnknownKeys>, objectInputType, Catchall, UnknownKeys>>; 555 | /** 556 | * Prior to zod@1.0.12 there was a bug in the 557 | * inferred type of merged objects. Please 558 | * upgrade if you are experiencing issues. 559 | */ 560 | merge(merging: Incoming): ZodObject, Incoming["_def"]["unknownKeys"], Incoming["_def"]["catchall"]>; 561 | setKey(key: Key, schema: Schema): ZodObject; 564 | catchall(index: Index): ZodObject; 565 | pick>(mask: Mask): ZodObject>, UnknownKeys, Catchall>; 568 | omit>(mask: Mask): ZodObject, UnknownKeys, Catchall>; 571 | /** 572 | * @deprecated 573 | */ 574 | deepPartial(): partialUtil.DeepPartial; 575 | partial(): ZodObject<{ 576 | [k in keyof T]: ZodOptional; 577 | }, UnknownKeys, Catchall>; 578 | partial>(mask: Mask): ZodObject : T[k]; 582 | }>, UnknownKeys, Catchall>; 583 | required(): ZodObject<{ 584 | [k in keyof T]: deoptional; 585 | }, UnknownKeys, Catchall>; 586 | required>(mask: Mask): ZodObject : T[k]; 590 | }>, UnknownKeys, Catchall>; 591 | keyof(): ZodEnum>; 592 | static create: (shape: T_1, params?: RawCreateParams) => ZodObject, any>]: objectUtil.addQuestionMarks, any>[k]; }, { [k_1 in keyof baseObjectInputType]: baseObjectInputType[k_1]; }>; 593 | static strictCreate: (shape: T_1, params?: RawCreateParams) => ZodObject, any>]: objectUtil.addQuestionMarks, any>[k]; }, { [k_1 in keyof baseObjectInputType]: baseObjectInputType[k_1]; }>; 594 | static lazycreate: (shape: () => T_1, params?: RawCreateParams) => ZodObject, any>]: objectUtil.addQuestionMarks, any>[k]; }, { [k_1 in keyof baseObjectInputType]: baseObjectInputType[k_1]; }>; 595 | } 596 | export declare type AnyZodObject = ZodObject; 597 | export declare type ZodUnionOptions = Readonly<[ZodTypeAny, ...ZodTypeAny[]]>; 598 | export interface ZodUnionDef> extends ZodTypeDef { 603 | options: T; 604 | typeName: ZodFirstPartyTypeKind.ZodUnion; 605 | } 606 | export declare class ZodUnion extends ZodType, T[number]["_input"]> { 607 | _parse(input: ParseInput): ParseReturnType; 608 | get options(): T; 609 | static create: (types: T_1, params?: RawCreateParams) => ZodUnion; 610 | } 611 | export declare type ZodDiscriminatedUnionOption = ZodObject<{ 612 | [key in Discriminator]: ZodTypeAny; 613 | } & ZodRawShape, UnknownKeysParam, ZodTypeAny>; 614 | export interface ZodDiscriminatedUnionDef[] = ZodDiscriminatedUnionOption[]> extends ZodTypeDef { 615 | discriminator: Discriminator; 616 | options: Options; 617 | optionsMap: Map>; 618 | typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion; 619 | } 620 | export declare class ZodDiscriminatedUnion[]> extends ZodType, ZodDiscriminatedUnionDef, input> { 621 | _parse(input: ParseInput): ParseReturnType; 622 | get discriminator(): Discriminator; 623 | get options(): Options; 624 | get optionsMap(): Map>; 625 | /** 626 | * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor. 627 | * However, it only allows a union of objects, all of which need to share a discriminator property. This property must 628 | * have a different value for each object in the union. 629 | * @param discriminator the name of the discriminator property 630 | * @param types an array of object schemas 631 | * @param params 632 | */ 633 | static create, 635 | ...ZodDiscriminatedUnionOption[] 636 | ]>(discriminator: Discriminator, options: Types, params?: RawCreateParams): ZodDiscriminatedUnion; 637 | } 638 | export interface ZodIntersectionDef extends ZodTypeDef { 639 | left: T; 640 | right: U; 641 | typeName: ZodFirstPartyTypeKind.ZodIntersection; 642 | } 643 | export declare class ZodIntersection extends ZodType, T["_input"] & U["_input"]> { 644 | _parse(input: ParseInput): ParseReturnType; 645 | static create: (left: T_1, right: U_1, params?: RawCreateParams) => ZodIntersection; 646 | } 647 | export declare type ZodTupleItems = [ZodTypeAny, ...ZodTypeAny[]]; 648 | export declare type AssertArray = T extends any[] ? T : never; 649 | export declare type OutputTypeOfTuple = AssertArray<{ 650 | [k in keyof T]: T[k] extends ZodType ? T[k]["_output"] : never; 651 | }>; 652 | export declare type OutputTypeOfTupleWithRest = Rest extends ZodTypeAny ? [...OutputTypeOfTuple, ...Rest["_output"][]] : OutputTypeOfTuple; 653 | export declare type InputTypeOfTuple = AssertArray<{ 654 | [k in keyof T]: T[k] extends ZodType ? T[k]["_input"] : never; 655 | }>; 656 | export declare type InputTypeOfTupleWithRest = Rest extends ZodTypeAny ? [...InputTypeOfTuple, ...Rest["_input"][]] : InputTypeOfTuple; 657 | export interface ZodTupleDef extends ZodTypeDef { 658 | items: T; 659 | rest: Rest; 660 | typeName: ZodFirstPartyTypeKind.ZodTuple; 661 | } 662 | export declare type AnyZodTuple = ZodTuple<[ 663 | ZodTypeAny, 664 | ...ZodTypeAny[] 665 | ] | [], ZodTypeAny | null>; 666 | export declare class ZodTuple extends ZodType, ZodTupleDef, InputTypeOfTupleWithRest> { 667 | _parse(input: ParseInput): ParseReturnType; 668 | get items(): T; 669 | rest(rest: Rest): ZodTuple; 670 | static create: (schemas: T_1, params?: RawCreateParams) => ZodTuple; 671 | } 672 | export interface ZodRecordDef extends ZodTypeDef { 673 | valueType: Value; 674 | keyType: Key; 675 | typeName: ZodFirstPartyTypeKind.ZodRecord; 676 | } 677 | export declare type KeySchema = ZodType; 678 | export declare type RecordType = [ 679 | string 680 | ] extends [K] ? Record : [number] extends [K] ? Record : [symbol] extends [K] ? Record : [BRAND] extends [K] ? Record : Partial>; 681 | export declare class ZodRecord extends ZodType, ZodRecordDef, RecordType> { 682 | get keySchema(): Key; 683 | get valueSchema(): Value; 684 | _parse(input: ParseInput): ParseReturnType; 685 | get element(): Value; 686 | static create(valueType: Value, params?: RawCreateParams): ZodRecord; 687 | static create(keySchema: Keys, valueType: Value, params?: RawCreateParams): ZodRecord; 688 | } 689 | export interface ZodMapDef extends ZodTypeDef { 690 | valueType: Value; 691 | keyType: Key; 692 | typeName: ZodFirstPartyTypeKind.ZodMap; 693 | } 694 | export declare class ZodMap extends ZodType, ZodMapDef, Map> { 695 | get keySchema(): Key; 696 | get valueSchema(): Value; 697 | _parse(input: ParseInput): ParseReturnType; 698 | static create: (keyType: Key_1, valueType: Value_1, params?: RawCreateParams) => ZodMap; 699 | } 700 | export interface ZodSetDef extends ZodTypeDef { 701 | valueType: Value; 702 | typeName: ZodFirstPartyTypeKind.ZodSet; 703 | minSize: { 704 | value: number; 705 | message?: string; 706 | } | null; 707 | maxSize: { 708 | value: number; 709 | message?: string; 710 | } | null; 711 | } 712 | export declare class ZodSet extends ZodType, ZodSetDef, Set> { 713 | _parse(input: ParseInput): ParseReturnType; 714 | min(minSize: number, message?: errorUtil.ErrMessage): this; 715 | max(maxSize: number, message?: errorUtil.ErrMessage): this; 716 | size(size: number, message?: errorUtil.ErrMessage): this; 717 | nonempty(message?: errorUtil.ErrMessage): ZodSet; 718 | static create: (valueType: Value_1, params?: RawCreateParams) => ZodSet; 719 | } 720 | export interface ZodFunctionDef = ZodTuple, Returns extends ZodTypeAny = ZodTypeAny> extends ZodTypeDef { 721 | args: Args; 722 | returns: Returns; 723 | typeName: ZodFirstPartyTypeKind.ZodFunction; 724 | } 725 | export declare type OuterTypeOfFunction, Returns extends ZodTypeAny> = Args["_input"] extends Array ? (...args: Args["_input"]) => Returns["_output"] : never; 726 | export declare type InnerTypeOfFunction, Returns extends ZodTypeAny> = Args["_output"] extends Array ? (...args: Args["_output"]) => Returns["_input"] : never; 727 | export declare class ZodFunction, Returns extends ZodTypeAny> extends ZodType, ZodFunctionDef, InnerTypeOfFunction> { 728 | _parse(input: ParseInput): ParseReturnType; 729 | parameters(): Args; 730 | returnType(): Returns; 731 | args[0]>(...items: Items): ZodFunction, Returns>; 732 | returns>(returnType: NewReturnType): ZodFunction; 733 | implement>(func: F): ReturnType extends Returns["_output"] ? (...args: Args["_input"]) => ReturnType : OuterTypeOfFunction; 734 | strictImplement(func: InnerTypeOfFunction): InnerTypeOfFunction; 735 | validate: >(func: F) => ReturnType extends Returns["_output"] ? (...args: Args["_input"]) => ReturnType : OuterTypeOfFunction; 736 | static create(): ZodFunction, ZodUnknown>; 737 | static create>(args: T): ZodFunction; 738 | static create(args: T, returns: U): ZodFunction; 739 | static create, U extends ZodTypeAny = ZodUnknown>(args: T, returns: U, params?: RawCreateParams): ZodFunction; 740 | } 741 | export interface ZodLazyDef extends ZodTypeDef { 742 | getter: () => T; 743 | typeName: ZodFirstPartyTypeKind.ZodLazy; 744 | } 745 | export declare class ZodLazy extends ZodType, ZodLazyDef, input> { 746 | get schema(): T; 747 | _parse(input: ParseInput): ParseReturnType; 748 | static create: (getter: () => T_1, params?: RawCreateParams) => ZodLazy; 749 | } 750 | export interface ZodLiteralDef extends ZodTypeDef { 751 | value: T; 752 | typeName: ZodFirstPartyTypeKind.ZodLiteral; 753 | } 754 | export declare class ZodLiteral extends ZodType, T> { 755 | _parse(input: ParseInput): ParseReturnType; 756 | get value(): T; 757 | static create: (value: T_1, params?: RawCreateParams) => ZodLiteral; 758 | } 759 | export declare type ArrayKeys = keyof any[]; 760 | export declare type Indices = Exclude; 761 | export declare type EnumValues = readonly [T, ...T[]]; 762 | export declare type Values = { 763 | [k in T[number]]: k; 764 | }; 765 | export interface ZodEnumDef extends ZodTypeDef { 766 | values: T; 767 | typeName: ZodFirstPartyTypeKind.ZodEnum; 768 | } 769 | export declare type Writeable = { 770 | -readonly [P in keyof T]: T[P]; 771 | }; 772 | export declare type FilterEnum = Values extends [] ? [] : Values extends [infer Head, ...infer Rest] ? Head extends ToExclude ? FilterEnum : [Head, ...FilterEnum] : never; 773 | export declare type typecast = A extends T ? A : never; 774 | declare function createZodEnum>(values: T, params?: RawCreateParams): ZodEnum>; 775 | declare function createZodEnum(values: T, params?: RawCreateParams): ZodEnum; 776 | export declare class ZodEnum extends ZodType, T[number]> { 777 | #private; 778 | _parse(input: ParseInput): ParseReturnType; 779 | get options(): T; 780 | get enum(): Values; 781 | get Values(): Values; 782 | get Enum(): Values; 783 | extract(values: ToExtract, newDef?: RawCreateParams): ZodEnum>; 784 | exclude(values: ToExclude, newDef?: RawCreateParams): ZodEnum>, [string, ...string[]]>>; 785 | static create: typeof createZodEnum; 786 | } 787 | export interface ZodNativeEnumDef extends ZodTypeDef { 788 | values: T; 789 | typeName: ZodFirstPartyTypeKind.ZodNativeEnum; 790 | } 791 | export declare type EnumLike = { 792 | [k: string]: string | number; 793 | [nu: number]: string; 794 | }; 795 | export declare class ZodNativeEnum extends ZodType, T[keyof T]> { 796 | #private; 797 | _parse(input: ParseInput): ParseReturnType; 798 | get enum(): T; 799 | static create: (values: T_1, params?: RawCreateParams) => ZodNativeEnum; 800 | } 801 | export interface ZodPromiseDef extends ZodTypeDef { 802 | type: T; 803 | typeName: ZodFirstPartyTypeKind.ZodPromise; 804 | } 805 | export declare class ZodPromise extends ZodType, ZodPromiseDef, Promise> { 806 | unwrap(): T; 807 | _parse(input: ParseInput): ParseReturnType; 808 | static create: (schema: T_1, params?: RawCreateParams) => ZodPromise; 809 | } 810 | export declare type Refinement = (arg: T, ctx: RefinementCtx) => any; 811 | export declare type SuperRefinement = (arg: T, ctx: RefinementCtx) => void | Promise; 812 | export declare type RefinementEffect = { 813 | type: "refinement"; 814 | refinement: (arg: T, ctx: RefinementCtx) => any; 815 | }; 816 | export declare type TransformEffect = { 817 | type: "transform"; 818 | transform: (arg: T, ctx: RefinementCtx) => any; 819 | }; 820 | export declare type PreprocessEffect = { 821 | type: "preprocess"; 822 | transform: (arg: T, ctx: RefinementCtx) => any; 823 | }; 824 | export declare type Effect = RefinementEffect | TransformEffect | PreprocessEffect; 825 | export interface ZodEffectsDef extends ZodTypeDef { 826 | schema: T; 827 | typeName: ZodFirstPartyTypeKind.ZodEffects; 828 | effect: Effect; 829 | } 830 | export declare class ZodEffects, Input = input> extends ZodType, Input> { 831 | innerType(): T; 832 | sourceType(): T; 833 | _parse(input: ParseInput): ParseReturnType; 834 | static create: (schema: I, effect: Effect, params?: RawCreateParams) => ZodEffects>; 835 | static createWithPreprocess: (preprocess: (arg: unknown, ctx: RefinementCtx) => unknown, schema: I, params?: RawCreateParams) => ZodEffects; 836 | } 837 | export { ZodEffects as ZodTransformer }; 838 | export interface ZodOptionalDef extends ZodTypeDef { 839 | innerType: T; 840 | typeName: ZodFirstPartyTypeKind.ZodOptional; 841 | } 842 | export declare type ZodOptionalType = ZodOptional; 843 | export declare class ZodOptional extends ZodType, T["_input"] | undefined> { 844 | _parse(input: ParseInput): ParseReturnType; 845 | unwrap(): T; 846 | static create: (type: T_1, params?: RawCreateParams) => ZodOptional; 847 | } 848 | export interface ZodNullableDef extends ZodTypeDef { 849 | innerType: T; 850 | typeName: ZodFirstPartyTypeKind.ZodNullable; 851 | } 852 | export declare type ZodNullableType = ZodNullable; 853 | export declare class ZodNullable extends ZodType, T["_input"] | null> { 854 | _parse(input: ParseInput): ParseReturnType; 855 | unwrap(): T; 856 | static create: (type: T_1, params?: RawCreateParams) => ZodNullable; 857 | } 858 | export interface ZodDefaultDef extends ZodTypeDef { 859 | innerType: T; 860 | defaultValue: () => util.noUndefined; 861 | typeName: ZodFirstPartyTypeKind.ZodDefault; 862 | } 863 | export declare class ZodDefault extends ZodType, ZodDefaultDef, T["_input"] | undefined> { 864 | _parse(input: ParseInput): ParseReturnType; 865 | removeDefault(): T; 866 | static create: (type: T_1, params: { 867 | errorMap?: ZodErrorMap | undefined; 868 | invalid_type_error?: string | undefined; 869 | required_error?: string | undefined; 870 | message?: string | undefined; 871 | description?: string | undefined; 872 | } & { 873 | default: T_1["_input"] | (() => util.noUndefined); 874 | }) => ZodDefault; 875 | } 876 | export interface ZodCatchDef extends ZodTypeDef { 877 | innerType: T; 878 | catchValue: (ctx: { 879 | error: ZodError; 880 | input: unknown; 881 | }) => T["_input"]; 882 | typeName: ZodFirstPartyTypeKind.ZodCatch; 883 | } 884 | export declare class ZodCatch extends ZodType, unknown> { 885 | _parse(input: ParseInput): ParseReturnType; 886 | removeCatch(): T; 887 | static create: (type: T_1, params: { 888 | errorMap?: ZodErrorMap | undefined; 889 | invalid_type_error?: string | undefined; 890 | required_error?: string | undefined; 891 | message?: string | undefined; 892 | description?: string | undefined; 893 | } & { 894 | catch: T_1["_output"] | (() => T_1["_output"]); 895 | }) => ZodCatch; 896 | } 897 | export interface ZodNaNDef extends ZodTypeDef { 898 | typeName: ZodFirstPartyTypeKind.ZodNaN; 899 | } 900 | export declare class ZodNaN extends ZodType { 901 | _parse(input: ParseInput): ParseReturnType; 902 | static create: (params?: RawCreateParams) => ZodNaN; 903 | } 904 | export interface ZodBrandedDef extends ZodTypeDef { 905 | type: T; 906 | typeName: ZodFirstPartyTypeKind.ZodBranded; 907 | } 908 | export declare const BRAND: unique symbol; 909 | export declare type BRAND = { 910 | [BRAND]: { 911 | [k in T]: true; 912 | }; 913 | }; 914 | export declare class ZodBranded extends ZodType, ZodBrandedDef, T["_input"]> { 915 | _parse(input: ParseInput): ParseReturnType; 916 | unwrap(): T; 917 | } 918 | export interface ZodPipelineDef extends ZodTypeDef { 919 | in: A; 920 | out: B; 921 | typeName: ZodFirstPartyTypeKind.ZodPipeline; 922 | } 923 | export declare class ZodPipeline extends ZodType, A["_input"]> { 924 | _parse(input: ParseInput): ParseReturnType; 925 | static create(a: A, b: B): ZodPipeline; 926 | } 927 | declare type BuiltIn = (((...args: any[]) => any) | (new (...args: any[]) => any)) | { 928 | readonly [Symbol.toStringTag]: string; 929 | } | Date | Error | Generator | Promise | RegExp; 930 | declare type MakeReadonly = T extends Map ? ReadonlyMap : T extends Set ? ReadonlySet : T extends [infer Head, ...infer Tail] ? readonly [Head, ...Tail] : T extends Array ? ReadonlyArray : T extends BuiltIn ? T : Readonly; 931 | export interface ZodReadonlyDef extends ZodTypeDef { 932 | innerType: T; 933 | typeName: ZodFirstPartyTypeKind.ZodReadonly; 934 | } 935 | export declare class ZodReadonly extends ZodType, ZodReadonlyDef, MakeReadonly> { 936 | _parse(input: ParseInput): ParseReturnType; 937 | static create: (type: T_1, params?: RawCreateParams) => ZodReadonly; 938 | unwrap(): T; 939 | } 940 | declare type CustomParams = CustomErrorParams & { 941 | fatal?: boolean; 942 | }; 943 | export declare function custom(check?: (data: any) => any, params?: string | CustomParams | ((input: any) => CustomParams), 944 | /** 945 | * @deprecated 946 | * 947 | * Pass `fatal` into the params object instead: 948 | * 949 | * ```ts 950 | * z.string().custom((val) => val.length > 5, { fatal: false }) 951 | * ``` 952 | * 953 | */ 954 | fatal?: boolean): ZodType; 955 | export { ZodType as Schema, ZodType as ZodSchema }; 956 | export declare const late: { 957 | object: (shape: () => T, params?: RawCreateParams) => ZodObject, any>]: objectUtil.addQuestionMarks, any>[k]; }, { [k_1 in keyof baseObjectInputType]: baseObjectInputType[k_1]; }>; 958 | }; 959 | export declare enum ZodFirstPartyTypeKind { 960 | ZodString = "ZodString", 961 | ZodNumber = "ZodNumber", 962 | ZodNaN = "ZodNaN", 963 | ZodBigInt = "ZodBigInt", 964 | ZodBoolean = "ZodBoolean", 965 | ZodDate = "ZodDate", 966 | ZodSymbol = "ZodSymbol", 967 | ZodUndefined = "ZodUndefined", 968 | ZodNull = "ZodNull", 969 | ZodAny = "ZodAny", 970 | ZodUnknown = "ZodUnknown", 971 | ZodNever = "ZodNever", 972 | ZodVoid = "ZodVoid", 973 | ZodArray = "ZodArray", 974 | ZodObject = "ZodObject", 975 | ZodUnion = "ZodUnion", 976 | ZodDiscriminatedUnion = "ZodDiscriminatedUnion", 977 | ZodIntersection = "ZodIntersection", 978 | ZodTuple = "ZodTuple", 979 | ZodRecord = "ZodRecord", 980 | ZodMap = "ZodMap", 981 | ZodSet = "ZodSet", 982 | ZodFunction = "ZodFunction", 983 | ZodLazy = "ZodLazy", 984 | ZodLiteral = "ZodLiteral", 985 | ZodEnum = "ZodEnum", 986 | ZodEffects = "ZodEffects", 987 | ZodNativeEnum = "ZodNativeEnum", 988 | ZodOptional = "ZodOptional", 989 | ZodNullable = "ZodNullable", 990 | ZodDefault = "ZodDefault", 991 | ZodCatch = "ZodCatch", 992 | ZodPromise = "ZodPromise", 993 | ZodBranded = "ZodBranded", 994 | ZodPipeline = "ZodPipeline", 995 | ZodReadonly = "ZodReadonly" 996 | } 997 | export declare type ZodFirstPartySchemaTypes = ZodString | ZodNumber | ZodNaN | ZodBigInt | ZodBoolean | ZodDate | ZodUndefined | ZodNull | ZodAny | ZodUnknown | ZodNever | ZodVoid | ZodArray | ZodObject | ZodUnion | ZodDiscriminatedUnion | ZodIntersection | ZodTuple | ZodRecord | ZodMap | ZodSet | ZodFunction | ZodLazy | ZodLiteral | ZodEnum | ZodEffects | ZodNativeEnum | ZodOptional | ZodNullable | ZodDefault | ZodCatch | ZodPromise | ZodBranded | ZodPipeline | ZodReadonly | ZodSymbol; 998 | declare abstract class Class { 999 | constructor(..._: any[]); 1000 | } 1001 | declare const instanceOfType: (cls: T, params?: CustomParams) => ZodType, ZodTypeDef, InstanceType>; 1002 | declare const stringType: (params?: ({ 1003 | errorMap?: ZodErrorMap | undefined; 1004 | invalid_type_error?: string | undefined; 1005 | required_error?: string | undefined; 1006 | message?: string | undefined; 1007 | description?: string | undefined; 1008 | } & { 1009 | coerce?: true | undefined; 1010 | }) | undefined) => ZodString; 1011 | declare const numberType: (params?: ({ 1012 | errorMap?: ZodErrorMap | undefined; 1013 | invalid_type_error?: string | undefined; 1014 | required_error?: string | undefined; 1015 | message?: string | undefined; 1016 | description?: string | undefined; 1017 | } & { 1018 | coerce?: boolean | undefined; 1019 | }) | undefined) => ZodNumber; 1020 | declare const nanType: (params?: RawCreateParams) => ZodNaN; 1021 | declare const bigIntType: (params?: ({ 1022 | errorMap?: ZodErrorMap | undefined; 1023 | invalid_type_error?: string | undefined; 1024 | required_error?: string | undefined; 1025 | message?: string | undefined; 1026 | description?: string | undefined; 1027 | } & { 1028 | coerce?: boolean | undefined; 1029 | }) | undefined) => ZodBigInt; 1030 | declare const booleanType: (params?: ({ 1031 | errorMap?: ZodErrorMap | undefined; 1032 | invalid_type_error?: string | undefined; 1033 | required_error?: string | undefined; 1034 | message?: string | undefined; 1035 | description?: string | undefined; 1036 | } & { 1037 | coerce?: boolean | undefined; 1038 | }) | undefined) => ZodBoolean; 1039 | declare const dateType: (params?: ({ 1040 | errorMap?: ZodErrorMap | undefined; 1041 | invalid_type_error?: string | undefined; 1042 | required_error?: string | undefined; 1043 | message?: string | undefined; 1044 | description?: string | undefined; 1045 | } & { 1046 | coerce?: boolean | undefined; 1047 | }) | undefined) => ZodDate; 1048 | declare const symbolType: (params?: RawCreateParams) => ZodSymbol; 1049 | declare const undefinedType: (params?: RawCreateParams) => ZodUndefined; 1050 | declare const nullType: (params?: RawCreateParams) => ZodNull; 1051 | declare const anyType: (params?: RawCreateParams) => ZodAny; 1052 | declare const unknownType: (params?: RawCreateParams) => ZodUnknown; 1053 | declare const neverType: (params?: RawCreateParams) => ZodNever; 1054 | declare const voidType: (params?: RawCreateParams) => ZodVoid; 1055 | declare const arrayType: (schema: T, params?: RawCreateParams) => ZodArray; 1056 | declare const objectType: (shape: T, params?: RawCreateParams) => ZodObject, any>]: objectUtil.addQuestionMarks, any>[k]; }, { [k_1 in keyof baseObjectInputType]: baseObjectInputType[k_1]; }>; 1057 | declare const strictObjectType: (shape: T, params?: RawCreateParams) => ZodObject, any>]: objectUtil.addQuestionMarks, any>[k]; }, { [k_1 in keyof baseObjectInputType]: baseObjectInputType[k_1]; }>; 1058 | declare const unionType: (types: T, params?: RawCreateParams) => ZodUnion; 1059 | declare const discriminatedUnionType: typeof ZodDiscriminatedUnion.create; 1060 | declare const intersectionType: (left: T, right: U, params?: RawCreateParams) => ZodIntersection; 1061 | declare const tupleType: (schemas: T, params?: RawCreateParams) => ZodTuple; 1062 | declare const recordType: typeof ZodRecord.create; 1063 | declare const mapType: (keyType: Key, valueType: Value, params?: RawCreateParams) => ZodMap; 1064 | declare const setType: (valueType: Value, params?: RawCreateParams) => ZodSet; 1065 | declare const functionType: typeof ZodFunction.create; 1066 | declare const lazyType: (getter: () => T, params?: RawCreateParams) => ZodLazy; 1067 | declare const literalType: (value: T, params?: RawCreateParams) => ZodLiteral; 1068 | declare const enumType: typeof createZodEnum; 1069 | declare const nativeEnumType: (values: T, params?: RawCreateParams) => ZodNativeEnum; 1070 | declare const promiseType: (schema: T, params?: RawCreateParams) => ZodPromise; 1071 | declare const effectsType: (schema: I, effect: Effect, params?: RawCreateParams) => ZodEffects>; 1072 | declare const optionalType: (type: T, params?: RawCreateParams) => ZodOptional; 1073 | declare const nullableType: (type: T, params?: RawCreateParams) => ZodNullable; 1074 | declare const preprocessType: (preprocess: (arg: unknown, ctx: RefinementCtx) => unknown, schema: I, params?: RawCreateParams) => ZodEffects; 1075 | declare const pipelineType: typeof ZodPipeline.create; 1076 | declare const ostring: () => ZodOptional; 1077 | declare const onumber: () => ZodOptional; 1078 | declare const oboolean: () => ZodOptional; 1079 | export declare const coerce: { 1080 | string: (params?: ({ 1081 | errorMap?: ZodErrorMap | undefined; 1082 | invalid_type_error?: string | undefined; 1083 | required_error?: string | undefined; 1084 | message?: string | undefined; 1085 | description?: string | undefined; 1086 | } & { 1087 | coerce?: true | undefined; 1088 | }) | undefined) => ZodString; 1089 | number: (params?: ({ 1090 | errorMap?: ZodErrorMap | undefined; 1091 | invalid_type_error?: string | undefined; 1092 | required_error?: string | undefined; 1093 | message?: string | undefined; 1094 | description?: string | undefined; 1095 | } & { 1096 | coerce?: boolean | undefined; 1097 | }) | undefined) => ZodNumber; 1098 | boolean: (params?: ({ 1099 | errorMap?: ZodErrorMap | undefined; 1100 | invalid_type_error?: string | undefined; 1101 | required_error?: string | undefined; 1102 | message?: string | undefined; 1103 | description?: string | undefined; 1104 | } & { 1105 | coerce?: boolean | undefined; 1106 | }) | undefined) => ZodBoolean; 1107 | bigint: (params?: ({ 1108 | errorMap?: ZodErrorMap | undefined; 1109 | invalid_type_error?: string | undefined; 1110 | required_error?: string | undefined; 1111 | message?: string | undefined; 1112 | description?: string | undefined; 1113 | } & { 1114 | coerce?: boolean | undefined; 1115 | }) | undefined) => ZodBigInt; 1116 | date: (params?: ({ 1117 | errorMap?: ZodErrorMap | undefined; 1118 | invalid_type_error?: string | undefined; 1119 | required_error?: string | undefined; 1120 | message?: string | undefined; 1121 | description?: string | undefined; 1122 | } & { 1123 | coerce?: boolean | undefined; 1124 | }) | undefined) => ZodDate; 1125 | }; 1126 | export { anyType as any, arrayType as array, bigIntType as bigint, booleanType as boolean, dateType as date, discriminatedUnionType as discriminatedUnion, effectsType as effect, enumType as enum, functionType as function, instanceOfType as instanceof, intersectionType as intersection, lazyType as lazy, literalType as literal, mapType as map, nanType as nan, nativeEnumType as nativeEnum, neverType as never, nullType as null, nullableType as nullable, numberType as number, objectType as object, oboolean, onumber, optionalType as optional, ostring, pipelineType as pipeline, preprocessType as preprocess, promiseType as promise, recordType as record, setType as set, strictObjectType as strictObject, stringType as string, symbolType as symbol, effectsType as transformer, tupleType as tuple, undefinedType as undefined, unionType as union, unknownType as unknown, voidType as void, }; 1127 | export declare const NEVER: never; 1128 | -------------------------------------------------------------------------------- /common/node_modules/zod/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "zod", 3 | "version": "3.23.8", 4 | "author": "Colin McDonnell ", 5 | "repository": { 6 | "type": "git", 7 | "url": "git+https://github.com/colinhacks/zod.git" 8 | }, 9 | "main": "./lib/index.js", 10 | "module": "./lib/index.mjs", 11 | "devDependencies": { 12 | "@babel/core": "^7.22.5", 13 | "@babel/preset-env": "^7.22.5", 14 | "@babel/preset-typescript": "^7.22.5", 15 | "@jest/globals": "^29.4.3", 16 | "@rollup/plugin-typescript": "^8.2.0", 17 | "@swc/core": "^1.3.66", 18 | "@swc/jest": "^0.2.26", 19 | "@types/benchmark": "^2.1.0", 20 | "@types/jest": "^29.2.2", 21 | "@types/node": "14", 22 | "@typescript-eslint/eslint-plugin": "^5.15.0", 23 | "@typescript-eslint/parser": "^5.15.0", 24 | "babel-jest": "^29.5.0", 25 | "benchmark": "^2.1.4", 26 | "dependency-cruiser": "^9.19.0", 27 | "eslint": "^8.11.0", 28 | "eslint-config-prettier": "^8.5.0", 29 | "eslint-plugin-ban": "^1.6.0", 30 | "eslint-plugin-import": "^2.25.4", 31 | "eslint-plugin-simple-import-sort": "^7.0.0", 32 | "eslint-plugin-unused-imports": "^2.0.0", 33 | "husky": "^7.0.4", 34 | "jest": "^29.3.1", 35 | "lint-staged": "^12.3.7", 36 | "nodemon": "^2.0.15", 37 | "prettier": "^2.6.0", 38 | "pretty-quick": "^3.1.3", 39 | "rollup": "^2.70.1", 40 | "ts-jest": "^29.1.0", 41 | "ts-morph": "^14.0.0", 42 | "ts-node": "^10.9.1", 43 | "tslib": "^2.3.1", 44 | "tsx": "^3.8.0", 45 | "typescript": "~4.5.5", 46 | "vitest": "^0.32.2" 47 | }, 48 | "exports": { 49 | ".": { 50 | "types": "./index.d.ts", 51 | "require": "./lib/index.js", 52 | "import": "./lib/index.mjs" 53 | }, 54 | "./package.json": "./package.json", 55 | "./locales/*": "./lib/locales/*" 56 | }, 57 | "bugs": { 58 | "url": "https://github.com/colinhacks/zod/issues" 59 | }, 60 | "description": "TypeScript-first schema declaration and validation library with static type inference", 61 | "files": [ 62 | "/lib", 63 | "/index.d.ts" 64 | ], 65 | "funding": "https://github.com/sponsors/colinhacks", 66 | "homepage": "https://zod.dev", 67 | "keywords": [ 68 | "typescript", 69 | "schema", 70 | "validation", 71 | "type", 72 | "inference" 73 | ], 74 | "license": "MIT", 75 | "lint-staged": { 76 | "src/*.ts": [ 77 | "eslint --cache --fix", 78 | "prettier --ignore-unknown --write" 79 | ], 80 | "*.md": [ 81 | "prettier --ignore-unknown --write" 82 | ] 83 | }, 84 | "scripts": { 85 | "prettier:check": "prettier --check src/**/*.ts deno/lib/**/*.ts *.md --no-error-on-unmatched-pattern", 86 | "prettier:fix": "prettier --write src/**/*.ts deno/lib/**/*.ts *.md --ignore-unknown --no-error-on-unmatched-pattern", 87 | "lint:check": "eslint --cache --ext .ts ./src", 88 | "lint:fix": "eslint --cache --fix --ext .ts ./src", 89 | "check": "yarn lint:check && yarn prettier:check", 90 | "fix": "yarn lint:fix && yarn prettier:fix", 91 | "clean": "rm -rf lib/* deno/lib/*", 92 | "build": "yarn run clean && npm run build:cjs && npm run build:esm && npm run build:deno", 93 | "build:deno": "node ./deno-build.mjs && cp ./README.md ./deno/lib", 94 | "build:esm": "rollup --config ./configs/rollup.config.js", 95 | "build:cjs": "tsc -p ./configs/tsconfig.cjs.json", 96 | "build:types": "tsc -p ./configs/tsconfig.types.json", 97 | "build:test": "tsc -p ./configs/tsconfig.test.json", 98 | "test:watch": "yarn test:ts-jest --watch", 99 | "test": "yarn test:ts-jest", 100 | "test:babel": "jest --coverage --config ./configs/babel-jest.config.json", 101 | "test:bun": "bun test src/", 102 | "test:vitest": "npx vitest --config ./configs/vitest.config.ts", 103 | "test:ts-jest": "npx jest --config ./configs/ts-jest.config.json", 104 | "test:swc": "npx jest --config ./configs/swc-jest.config.json", 105 | "test:deno": "cd deno && deno test", 106 | "prepublishOnly": "npm run test && npm run build && npm run build:deno", 107 | "play": "nodemon -e ts -w . -x tsx playground.ts", 108 | "depcruise": "depcruise -c .dependency-cruiser.js src", 109 | "benchmark": "tsx src/benchmarks/index.ts", 110 | "prepare": "husky install" 111 | }, 112 | "sideEffects": false, 113 | "support": { 114 | "backing": { 115 | "npm-funding": true 116 | } 117 | }, 118 | "types": "./index.d.ts" 119 | } 120 | -------------------------------------------------------------------------------- /common/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "common", 3 | "version": "1.0.0", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "common", 9 | "version": "1.0.0", 10 | "license": "ISC", 11 | "dependencies": { 12 | "zod": "^3.23.8" 13 | } 14 | }, 15 | "node_modules/zod": { 16 | "version": "3.23.8", 17 | "resolved": "https://registry.npmjs.org/zod/-/zod-3.23.8.tgz", 18 | "integrity": "sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==", 19 | "license": "MIT", 20 | "funding": { 21 | "url": "https://github.com/sponsors/colinhacks" 22 | } 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /common/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@syedahmedullahjaser/zod-inference-medium-blog", 3 | "version": "1.0.6", 4 | "main": "dist/index.js", 5 | "scripts": { 6 | "test": "echo \"Error: no test specified\" && exit 1" 7 | }, 8 | "keywords": [], 9 | "author": "", 10 | "license": "ISC", 11 | "description": "", 12 | "dependencies": { 13 | "zod": "^3.23.8" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /common/src/index.ts: -------------------------------------------------------------------------------- 1 | import z from "zod"; 2 | 3 | export const signupInput = z.object({ 4 | email: z.string().email(), 5 | password: z.string(), 6 | name: z.string().optional() 7 | }) 8 | 9 | //type inference in zod 10 | export type SignupInput = z.infer 11 | 12 | export const signinInput = z.object({ 13 | email: z.string().email(), 14 | password: z.string(), 15 | name: z.string().optional() 16 | }) 17 | 18 | export type SigninInput = z.infer 19 | 20 | export const createBlogInput = z.object({ 21 | title: z.string(), 22 | content: z.string() 23 | }) 24 | 25 | export type CreateBlogInput = z.infer 26 | 27 | export const updateBlogInput = z.object({ 28 | title: z.string(), 29 | content: z.string(), 30 | id: z.number(), 31 | }) 32 | 33 | export type UpdateBlogInput = z.infer 34 | -------------------------------------------------------------------------------- /common/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Visit https://aka.ms/tsconfig to read more about this file */ 4 | 5 | /* Projects */ 6 | // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ 7 | // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ 8 | // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ 9 | // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ 10 | // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ 11 | // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ 12 | 13 | /* Language and Environment */ 14 | "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ 15 | // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ 16 | // "jsx": "preserve", /* Specify what JSX code is generated. */ 17 | // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */ 18 | // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ 19 | // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ 20 | // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ 21 | // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ 22 | // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ 23 | // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ 24 | // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ 25 | // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ 26 | 27 | /* Modules */ 28 | "module": "commonjs", /* Specify what module code is generated. */ 29 | "rootDir": "./src", /* Specify the root folder within your source files. */ 30 | // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ 31 | // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ 32 | // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ 33 | // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ 34 | // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ 35 | // "types": [], /* Specify type package names to be included without being referenced in a source file. */ 36 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ 37 | // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ 38 | // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ 39 | // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ 40 | // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ 41 | // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ 42 | // "resolveJsonModule": true, /* Enable importing .json files. */ 43 | // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ 44 | // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ 45 | 46 | /* JavaScript Support */ 47 | // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ 48 | // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ 49 | // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ 50 | 51 | /* Emit */ 52 | "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ 53 | // "declarationMap": true, /* Create sourcemaps for d.ts files. */ 54 | // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ 55 | // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ 56 | // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ 57 | // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ 58 | "outDir": "./dist", /* Specify an output folder for all emitted files. */ 59 | // "removeComments": true, /* Disable emitting comments. */ 60 | // "noEmit": true, /* Disable emitting files from a compilation. */ 61 | // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ 62 | // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ 63 | // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ 64 | // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ 65 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ 66 | // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ 67 | // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ 68 | // "newLine": "crlf", /* Set the newline character for emitting files. */ 69 | // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ 70 | // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ 71 | // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ 72 | // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ 73 | // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ 74 | // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ 75 | 76 | /* Interop Constraints */ 77 | // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ 78 | // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ 79 | // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ 80 | "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ 81 | // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ 82 | "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ 83 | 84 | /* Type Checking */ 85 | "strict": true, /* Enable all strict type-checking options. */ 86 | // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ 87 | // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ 88 | // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ 89 | // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ 90 | // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ 91 | // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ 92 | // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ 93 | // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ 94 | // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ 95 | // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ 96 | // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ 97 | // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ 98 | // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ 99 | // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ 100 | // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ 101 | // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ 102 | // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ 103 | // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ 104 | 105 | /* Completeness */ 106 | // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ 107 | "skipLibCheck": true /* Skip type checking all .d.ts files. */ 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /frontend/.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { browser: true, es2020: true }, 4 | extends: [ 5 | 'eslint:recommended', 6 | 'plugin:@typescript-eslint/recommended', 7 | 'plugin:react-hooks/recommended', 8 | ], 9 | ignorePatterns: ['dist', '.eslintrc.cjs'], 10 | parser: '@typescript-eslint/parser', 11 | plugins: ['react-refresh'], 12 | rules: { 13 | 'react-refresh/only-export-components': [ 14 | 'warn', 15 | { allowConstantExport: true }, 16 | ], 17 | }, 18 | } 19 | -------------------------------------------------------------------------------- /frontend/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .vscode/* 17 | !.vscode/extensions.json 18 | .idea 19 | .DS_Store 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | -------------------------------------------------------------------------------- /frontend/README.md: -------------------------------------------------------------------------------- 1 | # React + TypeScript + Vite 2 | 3 | This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. 4 | 5 | Currently, two official plugins are available: 6 | 7 | - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh 8 | - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh 9 | 10 | ## Expanding the ESLint configuration 11 | 12 | If you are developing a production application, we recommend updating the configuration to enable type aware lint rules: 13 | 14 | - Configure the top-level `parserOptions` property like this: 15 | 16 | ```js 17 | export default { 18 | // other rules... 19 | parserOptions: { 20 | ecmaVersion: 'latest', 21 | sourceType: 'module', 22 | project: ['./tsconfig.json', './tsconfig.node.json'], 23 | tsconfigRootDir: __dirname, 24 | }, 25 | } 26 | ``` 27 | 28 | - Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked` 29 | - Optionally add `plugin:@typescript-eslint/stylistic-type-checked` 30 | - Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list 31 | -------------------------------------------------------------------------------- /frontend/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Medium 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /frontend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "frontend", 3 | "private": true, 4 | "version": "0.0.0", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite", 8 | "build": "tsc -b && vite build", 9 | "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", 10 | "preview": "vite preview" 11 | }, 12 | "dependencies": { 13 | "@syedahmedullahjaser/zod-inference-medium-blog": "^1.0.6", 14 | "axios": "^1.7.2", 15 | "react": "^18.3.1", 16 | "react-dom": "^18.3.1", 17 | "react-router-dom": "^6.23.1" 18 | }, 19 | "devDependencies": { 20 | "@types/react": "^18.3.3", 21 | "@types/react-dom": "^18.3.0", 22 | "@typescript-eslint/eslint-plugin": "^7.13.1", 23 | "@typescript-eslint/parser": "^7.13.1", 24 | "@vitejs/plugin-react": "^4.3.1", 25 | "autoprefixer": "^10.4.19", 26 | "eslint": "^8.57.0", 27 | "eslint-plugin-react-hooks": "^4.6.2", 28 | "eslint-plugin-react-refresh": "^0.4.7", 29 | "postcss": "^8.4.38", 30 | "tailwindcss": "^3.4.4", 31 | "typescript": "^5.2.2", 32 | "vite": "^5.3.1" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /frontend/postcss.config.js: -------------------------------------------------------------------------------- 1 | export default { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | } 7 | -------------------------------------------------------------------------------- /frontend/public/vite.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /frontend/src/App.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/syedahmedullah14/blogging-app-like-medium/be8d6a073a1a6ddebb56c8193e21b2f2d219394f/frontend/src/App.css -------------------------------------------------------------------------------- /frontend/src/App.tsx: -------------------------------------------------------------------------------- 1 | import { BrowserRouter, Route, Routes } from 'react-router-dom' 2 | import { Signup } from './pages/Signup' 3 | import { Signin } from './pages/Signin' 4 | import { Blog } from './pages/Blog' 5 | import { Blogs } from './pages/Blogs' 6 | import { Publish } from './pages/Publish' 7 | 8 | function App() { 9 | 10 | return ( 11 | <> 12 | 13 | 14 | } /> 15 | } /> 16 | } /> 17 | } /> 18 | } /> 19 | 20 | 21 | 22 | ) 23 | } 24 | 25 | export default App -------------------------------------------------------------------------------- /frontend/src/assets/react.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /frontend/src/components/Appbar.tsx: -------------------------------------------------------------------------------- 1 | import { Link } from "react-router-dom"; 2 | import { Avatar } from "./BlogCard"; 3 | import { Logout } from "./Logout"; 4 | // import { useBlogs } from "../hooks"; 5 | 6 | 7 | export const Appbar = () => { 8 | 9 | return ( 10 |
11 | 15 | {/* */} 16 | 17 | Medium 18 | 19 | 20 |
21 | 22 | 28 | 29 | 30 | 31 |
32 | 33 |
34 | ); 35 | }; 36 | -------------------------------------------------------------------------------- /frontend/src/components/Auth.tsx: -------------------------------------------------------------------------------- 1 | import { ChangeEvent, useState } from "react" 2 | import { Link, useNavigate } from "react-router-dom" 3 | import { BACKEND_URL } from "../config" 4 | import axios from "axios" 5 | import { SignupInput } from "@syedahmedullahjaser/zod-inference-medium-blog" 6 | 7 | export const Auth = ({type}: {type: "signup" | "signin"}) => { 8 | 9 | const navigate = useNavigate(); 10 | const [postInputs, setPostInputs] = useState({ 11 | name: "", 12 | email: "", 13 | password: "" 14 | }) 15 | 16 | async function sendRequest () { 17 | try{ 18 | const response = await axios.post(`${BACKEND_URL}/api/v1/user/${type === "signup" ? "signup" : "signin"}`, postInputs); 19 | const jwt = response.data; 20 | localStorage.setItem("token", jwt); 21 | navigate("/blogs") 22 | } catch (e){ 23 | alert("Error while signing up") 24 | } 25 | } 26 | 27 | return ( 28 |
29 |
30 |
31 |
32 | Welcome to Medium!
33 |
34 |
35 | Create an account 36 |
37 |
38 | {type === "signin" ? "Dont have an account:?" : "Already have an account?"} 39 | 40 | {type === "signin" ? "Sign Up" : "Sign In"} 41 | 42 |
43 | 44 | {type === "signup" ? { 45 | setPostInputs({ 46 | ...postInputs, 47 | name: e.target.value 48 | }) 49 | }}/> : null} 50 | 51 | { 52 | setPostInputs({ 53 | ...postInputs, 54 | email: e.target.value 55 | }) 56 | }}/> 57 | 58 | { 59 | setPostInputs({ 60 | ...postInputs, 61 | password: e.target.value 62 | }) 63 | }}/> 64 | 65 | 66 | 67 |
68 |
69 |
70 | 71 | ) 72 | } 73 | 74 | interface LabelledInputType{ 75 | label: string, 76 | placeholder: string, 77 | onChange: (e: ChangeEvent) => void; 78 | type?: string 79 | } 80 | 81 | function LabelledInput({label, placeholder, onChange, type}: LabelledInputType){ 82 | return
83 | 84 | 85 | 86 | 87 |
88 | } 89 | 90 | export default Auth -------------------------------------------------------------------------------- /frontend/src/components/BlogCard.tsx: -------------------------------------------------------------------------------- 1 | import { Link } from "react-router-dom" 2 | 3 | interface BlogCardProps{ 4 | authorname: string; 5 | title: string; 6 | content: string; 7 | publishedDate: string; 8 | id: number; 9 | } 10 | 11 | export const BlogCard = ({ 12 | authorname, 13 | title, 14 | content, 15 | publishedDate, 16 | id 17 | }: BlogCardProps) => { 18 | return ( 19 | 20 |
21 |
22 |
23 | 24 |
25 |
26 | {authorname} 27 |
28 |
29 | 30 |
31 |
32 | {publishedDate} 33 |
34 |
35 |
36 | {title} 37 |
38 |
39 | {content.slice(0,100)+"..."} 40 |
41 |
42 | {`${Math.ceil(content.length / 100)} minutes(s) read`} 43 |
44 | 45 |
46 | 47 | 48 | ) 49 | } 50 | 51 | export function Circle(){ 52 | return
53 | 54 |
55 | } 56 | 57 | export function Avatar({ name, size= "small"}: { name: string, size: "small" | "big"}){ 58 | return
60 | 61 | 62 | {name[0]} 63 | 64 |
65 | 66 | } -------------------------------------------------------------------------------- /frontend/src/components/BlogSkeleton.tsx: -------------------------------------------------------------------------------- 1 | import { Circle } from "./BlogCard" 2 | 3 | export const BlogSkeleton = () => { 4 | return ( 5 |
6 |
7 |
8 |
9 |
10 |
11 | 12 |
13 | 14 |
15 | 16 |
17 |
18 |
19 |
20 | 21 |
22 |
23 |
24 | 25 |
26 |
27 |
28 | 29 |
30 |
31 |
32 | 33 | Loading... 34 |
35 |
36 | 37 | ) 38 | } 39 | 40 | -------------------------------------------------------------------------------- /frontend/src/components/FullBlog.tsx: -------------------------------------------------------------------------------- 1 | import { Blog } from "../hooks"; 2 | import { Appbar } from "./Appbar"; 3 | import { Avatar } from "./BlogCard"; 4 | 5 | export const FullBlog = ({ blog }: { blog: Blog }) => { 6 | return ( 7 |
8 | 9 |
10 |
11 |
12 |
{blog.title}
13 |
Posten on 23rd June 2023
14 |
{blog.content}
15 |
16 | 17 |
18 |
19 | Author 20 |
21 | 22 |
23 |
24 | 25 |
26 |
27 |
28 | {blog.author.name || "Anonymous"} 29 |
30 |
31 | Random catch phrase about the author's ability to grab the 32 | user's attention 33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 | ); 41 | }; 42 | -------------------------------------------------------------------------------- /frontend/src/components/Logout.tsx: -------------------------------------------------------------------------------- 1 | // import { useState } from "react"; 2 | import { useNavigate } from "react-router-dom"; 3 | 4 | // export interface LogoutInputType{ 5 | // login: string, 6 | // logout: string, 7 | // } 8 | 9 | export const Logout = () => { 10 | // const [isLoggedin, setIsLoggedin] = useState(false); 11 | const navigate = useNavigate() 12 | // setIsLoggedin(true) 13 | 14 | const logout = () => { 15 | // localStorage.removeItem("token"); 16 | // setIsLoggedin(false); 17 | navigate('/') 18 | }; 19 | 20 | // const login = () =>{ 21 | // navigate("/signin") 22 | // } 23 | 24 | return ( 25 |
26 | 36 |
37 | ) 38 | } 39 | -------------------------------------------------------------------------------- /frontend/src/components/Quotes.tsx: -------------------------------------------------------------------------------- 1 | const Quotes = () => { 2 | return ( 3 |
4 |
5 |
6 |
7 | The customer service I recieved was exceptional. The support team went above and 8 | beyond to address my concerns. 9 |
10 |
11 | Jules Winfield 12 |
13 |
14 | CEO | Acme 15 |
16 |
17 |
18 | 19 |
20 | ) 21 | } 22 | 23 | export default Quotes -------------------------------------------------------------------------------- /frontend/src/config.ts: -------------------------------------------------------------------------------- 1 | export const BACKEND_URL ="https://backend.syedahmedullahjaser.workers.dev" -------------------------------------------------------------------------------- /frontend/src/hooks/index.ts: -------------------------------------------------------------------------------- 1 | import axios from "axios"; 2 | import { useEffect, useState } from "react" 3 | import { BACKEND_URL } from "../config"; 4 | 5 | export interface Blog{ 6 | "content": string; 7 | "title": string; 8 | "id": number; 9 | "author": { 10 | "name": string 11 | } 12 | } 13 | 14 | 15 | export const useBlog = ({ id }: { id: string }) =>{ 16 | const [loading, setLoading] = useState(true); 17 | const [blog, setBlog] = useState(); 18 | 19 | useEffect(() => { 20 | axios.get(`${BACKEND_URL}/api/v1/blog/${id}`, { 21 | headers:{ 22 | Authorization: localStorage.getItem("token") 23 | } 24 | }) 25 | .then(response => { 26 | setBlog(response.data.blog); 27 | setLoading(false) 28 | }) 29 | }) 30 | 31 | return { 32 | loading, 33 | blog 34 | } 35 | } 36 | 37 | export const useBlogs = () =>{ 38 | const [loading, setLoading] = useState(true); 39 | const [blogs, setBlogs] = useState([]); 40 | 41 | useEffect(() => { 42 | axios.get(`${BACKEND_URL}/api/v1/blog/bulk`, { 43 | headers:{ 44 | Authorization: localStorage.getItem("token") 45 | } 46 | }) 47 | .then(response => { 48 | setBlogs(response.data.blogs); 49 | setLoading(false) 50 | }) 51 | }) 52 | 53 | return { 54 | loading, 55 | blogs 56 | } 57 | } -------------------------------------------------------------------------------- /frontend/src/index.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; -------------------------------------------------------------------------------- /frontend/src/main.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import ReactDOM from 'react-dom/client' 3 | import App from './App.tsx' 4 | import './index.css' 5 | 6 | ReactDOM.createRoot(document.getElementById('root')!).render( 7 | 8 | 9 | , 10 | ) 11 | -------------------------------------------------------------------------------- /frontend/src/pages/Blog.tsx: -------------------------------------------------------------------------------- 1 | import { useParams } from "react-router-dom"; 2 | import { useBlog } from "../hooks" 3 | import { FullBlog } from "../components/FullBlog"; 4 | import { Appbar } from "../components/Appbar"; 5 | import { BlogSkeleton } from "../components/BlogSkeleton"; 6 | 7 | export const Blog = () => { 8 | 9 | const { id } = useParams() 10 | const {loading, blog} = useBlog({ 11 | id: id || "" 12 | }); 13 | 14 | if(loading || !blog){ 15 | return
16 | 17 |
18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 |
30 |
31 | } 32 | return ( 33 |
34 | 35 |
36 | ) 37 | } 38 | 39 | export default Blog -------------------------------------------------------------------------------- /frontend/src/pages/Blogs.tsx: -------------------------------------------------------------------------------- 1 | import { Appbar } from "../components/Appbar" 2 | import { BlogCard } from "../components/BlogCard" 3 | import { BlogSkeleton } from "../components/BlogSkeleton"; 4 | import { useBlogs } from "../hooks" 5 | 6 | export const Blogs = () => { 7 | 8 | const {loading, blogs} = useBlogs(); 9 | 10 | if (loading){ 11 | return
12 | 13 |
14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 |
26 |
27 | } 28 | 29 | 30 | return ( 31 |
32 | 33 |
34 |
35 | {blogs.map(blog => ) } 41 | 42 | 43 |
44 |
45 |
46 | 47 | ) 48 | } 49 | 50 | -------------------------------------------------------------------------------- /frontend/src/pages/Publish.tsx: -------------------------------------------------------------------------------- 1 | import axios from "axios" 2 | import { Appbar } from "../components/Appbar" 3 | import { BACKEND_URL } from "../config" 4 | import { ChangeEvent, useState } from "react" 5 | import { useNavigate } from "react-router-dom" 6 | 7 | export const Publish = () => { 8 | const [title, setTitle] = useState(""); 9 | const [description, setDescription] = useState(""); 10 | const navigate = useNavigate() 11 | 12 | return ( 13 |
14 |
15 |
16 | {/* */} 17 | { 18 | setTitle(e.target.value) 19 | }} type="text" className="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="Your Title"> 20 | 21 | { 22 | setDescription(e.target.value) 23 | }} /> 24 | 38 |
39 | 40 |
41 |
42 | ) 43 | } 44 | 45 | function TextEditor({ onChange }: { onChange: (e: ChangeEvent) => void}){ 46 | return( 47 |
48 |
49 |
50 | 51 |
52 | 53 | 54 |
55 |
56 | 57 |
58 |
59 | ) 60 | } -------------------------------------------------------------------------------- /frontend/src/pages/Signin.tsx: -------------------------------------------------------------------------------- 1 | 2 | import Auth from "../components/Auth" 3 | import Quotes from "../components/Quotes" 4 | 5 | export const Signin = () => { 6 | return ( 7 |
8 |
9 |
10 | 11 |
12 |
13 | 14 |
15 | 16 |
17 | 18 |
19 | ) 20 | } 21 | 22 | export default Signin -------------------------------------------------------------------------------- /frontend/src/pages/Signup.tsx: -------------------------------------------------------------------------------- 1 | // export import React from 'react' 2 | 3 | import Auth from "../components/Auth" 4 | import Quotes from "../components/Quotes" 5 | 6 | export const Signup = () => { 7 | return ( 8 |
9 |
10 |
11 | 12 |
13 |
14 | 15 |
16 | 17 |
18 | 19 |
20 | ) 21 | } 22 | 23 | export default Signup -------------------------------------------------------------------------------- /frontend/src/vite-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /frontend/tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | export default { 3 | content: [ 4 | "./index.html", 5 | "./src/**/*.{js,ts,jsx,tsx}", 6 | ], 7 | theme: { 8 | extend: {}, 9 | }, 10 | plugins: [], 11 | } 12 | -------------------------------------------------------------------------------- /frontend/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true, 4 | "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo", 5 | "target": "ES2020", 6 | "useDefineForClassFields": true, 7 | "lib": ["ES2020", "DOM", "DOM.Iterable"], 8 | "module": "ESNext", 9 | "skipLibCheck": true, 10 | 11 | /* Bundler mode */ 12 | "moduleResolution": "bundler", 13 | "allowImportingTsExtensions": true, 14 | "resolveJsonModule": true, 15 | "isolatedModules": true, 16 | "moduleDetection": "force", 17 | "noEmit": true, 18 | "jsx": "react-jsx", 19 | 20 | /* Linting */ 21 | "strict": true, 22 | "noUnusedLocals": true, 23 | "noUnusedParameters": true, 24 | "noFallthroughCasesInSwitch": true 25 | }, 26 | "include": ["src"] 27 | } 28 | -------------------------------------------------------------------------------- /frontend/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "files": [], 3 | "references": [ 4 | { 5 | "path": "./tsconfig.app.json" 6 | }, 7 | { 8 | "path": "./tsconfig.node.json" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /frontend/tsconfig.node.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true, 4 | "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo", 5 | "skipLibCheck": true, 6 | "module": "ESNext", 7 | "moduleResolution": "bundler", 8 | "allowSyntheticDefaultImports": true, 9 | "strict": true, 10 | "noEmit": true 11 | }, 12 | "include": ["vite.config.ts"] 13 | } 14 | -------------------------------------------------------------------------------- /frontend/vite.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite' 2 | import react from '@vitejs/plugin-react' 3 | 4 | // https://vitejs.dev/config/ 5 | export default defineConfig({ 6 | plugins: [react()], 7 | }) 8 | --------------------------------------------------------------------------------