From f97d23f77332fe785282ff57dc8f990747424976 Mon Sep 17 00:00:00 2001 From: Lachlan Collins <1667261+lachlancollins@users.noreply.github.com> Date: Tue, 7 Nov 2023 07:49:58 +1100 Subject: [PATCH] Stricter Zod validation --- src/lib/schemas.js | 48 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/src/lib/schemas.js b/src/lib/schemas.js index baf5fcb9a..01c0d04b7 100644 --- a/src/lib/schemas.js +++ b/src/lib/schemas.js @@ -3,11 +3,31 @@ import { z } from 'zod'; export const componentsSchema = z.array( z.object({ title: z.string(), - url: z.string().optional(), - repository: z.string(), + npm: z + .string() + .regex(/(@[\w-]+\/)?[\w-]+/) + .optional(), + url: z.string().url().optional(), + repository: z.string().url(), description: z.string(), - npm: z.string().optional(), - category: z.string(), + category: z.enum([ + 'Display Components', + 'Developer Experience', + 'Internationalization', + 'CSS and Layout', + 'Icons', + 'Multimedia', + 'Testing', + 'Data Visualisation', + 'Integration', + 'Design Pattern', + 'Stores', + 'Routers', + 'SvelteKit Adapters', + 'Design System', + 'User Interaction', + 'Forms & User Input' + ]), tags: z.array(z.string()).optional() }) ); @@ -15,9 +35,10 @@ export const componentsSchema = z.array( export const templatesSchema = z.array( z.object({ title: z.string(), - repository: z.string(), + url: z.string().url().optional(), + repository: z.string().url(), description: z.string(), - category: z.string(), + category: z.enum(['Svelte Add', 'SvelteKit', 'Svelte']), tags: z.array(z.string()).optional() }) ); @@ -25,9 +46,20 @@ export const templatesSchema = z.array( export const toolsSchema = z.array( z.object({ title: z.string(), - repository: z.string(), + npm: z + .string() + .regex(/(@[\w-]+\/)?[\w-]+/) + .optional(), + url: z.string().url().optional(), + repository: z.string().url(), description: z.string(), - category: z.string(), + category: z.enum([ + 'Debugging', + 'Linting and Formatting', + 'Editor Extensions', + 'Bundler Plugins', + 'Preprocessors' + ]), tags: z.array(z.string()).optional() }) );