Created
May 1, 2024 16:43
-
-
Save noahzgordon/40a7c6c4e0b7f85b570d84ad621bd2ae to your computer and use it in GitHub Desktop.
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
const newTableViewBaseSchema = z.object({ | |
name: z.string(), | |
icon: z.string().nullable(), | |
}); | |
const basicVitallyObjectTypes = Object.values(VitallyObjectType).filter((type) => ( | |
type !== VitallyObjectType.customObject && | |
type !== VitallyObjectType.surveyResponse && | |
type !== VitallyObjectType.goal | |
)).map(type => z.literal(type)) as unknown as readonly [z.ZodTypeAny, z.ZodTypeAny, ...z.ZodTypeAny[]]; | |
const newTableViewSchema = z.union([ | |
z.object({ | |
type: z.literal(VitallyObjectType.customObject), | |
customObjectId: z.string(), | |
}).merge(newTableViewBaseSchema), | |
z.object({ | |
type: z.literal(VitallyObjectType.surveyResponse), | |
surveyId: z.string(), | |
}).merge(newTableViewBaseSchema), | |
z.object({ | |
type: z.literal(VitallyObjectType.goal), | |
goalTemplateId: z.string().nullable(), | |
}).merge(newTableViewBaseSchema), | |
// catch-all for other object types | |
z.object({ type: z.union(basicVitallyObjectTypes) }).merge(newTableViewBaseSchema), | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment