Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
fix: zodded typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
lishaduck committed Jan 9, 2024
1 parent dea8c46 commit e061674
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/data/data-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,28 @@ const roomSchemaHelper = z
.toUpperCase()
.trim()
.transform(normalizeRoomString)
.refine((val) => Object.hasOwn(rooms, val) || val === "");
.refine((val) => Object.hasOwn(rooms, val));

/**
* Represents the custom schema for a room.
*
* This schema is used to validate if a value is a valid room.
* A valid room, well, exists in the list of rooms.
* In addition, this allows an empty string to pass, so that that validation can be caught better.
*/
const roomSchema = z.custom<keyof typeof rooms | "">(
const roomSchema = z.custom<keyof typeof rooms>(
(val) => roomSchemaHelper.safeParse(val).success,
(val) => ({ message: `${val} is not a room` }),
);

/**
* Represents the custom schema for a room.
*
* This schema is used to validate if a value is a valid room.
* A valid room, well, exists in the list of rooms.
* In addition, this allows an empty string to pass, so that that validation can be caught better.
*/
const roomSchemaUnion = z.union([roomSchema, z.literal("")]);

/**
* Represents the schema for profiles data.
*/
Expand Down Expand Up @@ -97,7 +105,7 @@ const stairListSchema = z.record(

export {
profilesListSchema,
roomSchema,
roomSchemaUnion as roomSchema,
type Level,
type Lvl,
type ProfilesList,
Expand Down

0 comments on commit e061674

Please sign in to comment.