Skip to content

Commit

Permalink
feat: added zod schema validation
Browse files Browse the repository at this point in the history
  • Loading branch information
keyurparalkar committed Apr 13, 2024
1 parent 690e890 commit 838a7ee
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"react-dom": "^18.2.0",
"react-hook-form": "^7.51.3",
"tailwind-merge": "^2.2.2",
"tailwindcss-animate": "^1.0.7"
"tailwindcss-animate": "^1.0.7",
"zod": "^3.22.4"
},
"devDependencies": {
"@types/node": "^20.12.7",
Expand Down
23 changes: 21 additions & 2 deletions src/interfaces/schema.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
import { GroupField } from "./group";
import { z } from "zod";

export type SchemaType = GroupField;
export const FieldTypeDef = z.object({
type: z.literal("field"),
dataType: z.enum(["text", "number", "email"]),
fieldName: z.string(),
accessorKey: z.string(),
});

type GroupFieldType = {
type: "group";
fields: (z.infer<typeof FieldTypeDef> | GroupFieldType)[];
};

export const GroupTypeDef: z.ZodType<GroupFieldType> = z.object({
type: z.literal("group"),
fields: z.array(z.union([FieldTypeDef, z.lazy(() => GroupTypeDef)])),
});

export const SchemaDef = GroupTypeDef;

export type SchemaType = z.infer<typeof SchemaDef>;
5 changes: 0 additions & 5 deletions src/schemas/forms/personal_info.d.json.ts

This file was deleted.

1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

/* Bundler mode */
"moduleResolution": "bundler",
"allowArbitraryExtensions": true,
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2226,3 +2226,8 @@ yocto-queue@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b"
integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==

zod@^3.22.4:
version "3.22.4"
resolved "https://registry.yarnpkg.com/zod/-/zod-3.22.4.tgz#f31c3a9386f61b1f228af56faa9255e845cf3fff"
integrity sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg==

0 comments on commit 838a7ee

Please sign in to comment.