From 0814e19a683176075147087b4e1f7dab94465660 Mon Sep 17 00:00:00 2001 From: John Costa Date: Wed, 26 Mar 2025 16:51:35 +0000 Subject: [PATCH] refactor(validators): frontend to new schema --- frontend/src/network/index.ts | 77 ++++++++++------------------------- 1 file changed, 22 insertions(+), 55 deletions(-) diff --git a/frontend/src/network/index.ts b/frontend/src/network/index.ts index 68df1b5..043cfc6 100644 --- a/frontend/src/network/index.ts +++ b/frontend/src/network/index.ts @@ -1,14 +1,15 @@ import { type InferOutput, - null as Null, array, nullable, object, parse, pipe, string, - undefinedable, + null_, uuid, + literal, + variant, } from "valibot"; type BaseRequestParams = Partial<{ @@ -56,60 +57,26 @@ const locationValidator = object({ Description: nullable(string()), }); -const getUserImagesResponseValidator = array( - object({ - ID: pipe(string(), uuid()), - Image: object({ - ID: pipe(string(), uuid()), - ImageName: string(), - Image: Null(), - }), - Tags: nullable( - array( - object({ - ID: pipe(string(), uuid()), - TagID: pipe(string(), uuid()), - ImageID: pipe(string(), uuid()), +const eventValidator = object({ + ID: pipe(string(), uuid()), + Name: string(), + Description: nullable(string()), + LocationID: nullable(pipe(string(), uuid())), + Location: null_(), +}); - Tag: object({ - ID: pipe(string(), uuid()), - Tag: string(), - UserID: pipe(string(), uuid()), - }), - }), - ), - ), - Links: nullable( - array( - object({ - ID: pipe(string(), uuid()), - Link: string(), - ImageID: pipe(string(), uuid()), - }), - ), - ), - Text: nullable( - array( - object({ - ID: pipe(string(), uuid()), - ImageText: string(), - ImageID: pipe(string(), uuid()), - }), - ), - ), - Locations: nullable(array(locationValidator)), - Events: nullable( - array( - object({ - ID: pipe(string(), uuid()), - Name: string(), - Description: nullable(string()), - Location: nullable(locationValidator), - }), - ), - ), - }), -); +const locationDataType = object({ + type: literal("location"), + data: locationValidator, +}); + +const eventDataType = object({ + type: literal("event"), + data: eventValidator, +}); + +const dataTypeValidator = variant("type", [locationDataType, eventDataType]); +const getUserImagesResponseValidator = array(dataTypeValidator); export const getUserImages = async (): Promise< InferOutput