Skip to content

Commit

Permalink
refactor: enum resolution for other builders
Browse files Browse the repository at this point in the history
  • Loading branch information
Qjuh committed May 26, 2024
1 parent b58e44a commit 6b43f5b
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions packages/builders/src/components/Assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@ export const disabledValidator = z.boolean();

export const buttonLabelValidator = z.string().min(1).max(80);

export const buttonStyleValidator = z.nativeEnum(ButtonStyle);
export const buttonStyleValidator = z.union([
z.nativeEnum(ButtonStyle),
z
.enum(
Object.values(ButtonStyle).filter((value) => typeof value === 'string') as [
keyof typeof ButtonStyle,
...(keyof typeof ButtonStyle)[],
],
)
.transform((key) => ButtonStyle[key]),
]);

export const placeholderValidator = z.string().max(150);
export const minMaxValidator = z.number().int().gte(0).lte(25);
Expand Down Expand Up @@ -50,7 +60,19 @@ export function validateRequiredSelectMenuOptionParameters(label?: string, value
parse(labelValueDescriptionValidator, value);
}

export const channelTypesValidator = z.nativeEnum(ChannelType).array();
export const channelTypesValidator = z
.union([
z.nativeEnum(ChannelType),
z
.enum(
Object.values(ChannelType).filter((value) => typeof value === 'string') as [
keyof typeof ChannelType,
...(keyof typeof ChannelType)[],
],
)
.transform((key) => ChannelType[key]),
])
.array();

export const urlValidator = z
.string()
Expand Down

0 comments on commit 6b43f5b

Please sign in to comment.