-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added zod types for validation inside the JSON schema
- Loading branch information
1 parent
872b514
commit e637093
Showing
2 changed files
with
30 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,38 @@ | ||
import { z } from "zod"; | ||
|
||
const RequiredDef = z.object({ | ||
value: z.boolean(), | ||
message: z.string(), | ||
}); | ||
|
||
const MaxMinLengthDef = z.object({ | ||
value: z.number(), | ||
message: z.string(), | ||
}); | ||
|
||
const MaxMinDef = z.object({ | ||
value: z.number(), | ||
message: z.string(), | ||
}); | ||
|
||
const PatternDef = z.object({ | ||
value: z.string(), | ||
message: z.string(), | ||
}); | ||
|
||
export const FieldTypeDef = z.object({ | ||
type: z.literal("field"), | ||
dataType: z.enum(["text", "number", "email"]), | ||
fieldName: z.string(), | ||
accessorKey: z.string(), | ||
validation: z | ||
.object({ | ||
required: RequiredDef.optional(), | ||
maxLength: MaxMinLengthDef.optional(), | ||
minLength: MaxMinLengthDef.optional(), | ||
max: MaxMinDef.optional(), | ||
min: MaxMinDef.optional(), | ||
pattern: PatternDef.optional(), | ||
}) | ||
.optional(), | ||
}); |