Skip to content

Commit

Permalink
chore: fix some of the lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mrzzy committed Jan 30, 2024
1 parent c9702b9 commit 6841b87
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions apps/cms/src/utilities/zodInteropt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function toPayloadZodField(name: string, zodType: z.ZodTypeAny): Field {
...field,
type: "array",
// convert nested type stored in array
fields: toPayloadZod((zodType as z.ZodArray<any>).element),
fields: toPayloadZod((zodType as z.ZodArray<z.ZodObject<z.ZodRawShape>>).element),
};
} else if (typeName === "ZodNativeEnum") {
return {
Expand All @@ -36,15 +36,15 @@ function toPayloadZodField(name: string, zodType: z.ZodTypeAny): Field {
// typescript encodes enums are encoded as bidirectional dictionary
// with both entries from option -> value and value -> option
// use zod parsing to select only the options -> value entries
options: Object.entries((zodType as z.ZodNativeEnum<any>).enum)
options: Object.entries((zodType as z.ZodNativeEnum<z.EnumLike>).enum)
.filter(([_, right]) => zodType.safeParse(right).success)
.map(([option, value]) => {
return { label: option, value: `${value}` };
}),
};
} else if (typeName === "ZodOptional") {
return {
...toPayloadZodField(name, (zodType as z.ZodOptional<any>).unwrap()),
...toPayloadZodField(name, (zodType as z.ZodOptional<z.ZodTypeAny>).unwrap()),
// override nested field required true with false
...field,
};
Expand Down

0 comments on commit 6841b87

Please sign in to comment.