From 0356b0dd3a277d2d213d321a2e1028ce0ceb3f98 Mon Sep 17 00:00:00 2001 From: 04cfb1ed <12877898+04cfb1ed@users.noreply.github.com> Date: Sun, 18 May 2025 20:58:12 -0500 Subject: [PATCH] refactor: move blockOrDiscriminatedUnionSchema logic inside of blockOrSchema --- packages/config-yaml/src/schemas/index.ts | 27 +++++++++++------------ 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/packages/config-yaml/src/schemas/index.ts b/packages/config-yaml/src/schemas/index.ts index fa1f47e04..ce7ffaa4f 100644 --- a/packages/config-yaml/src/schemas/index.ts +++ b/packages/config-yaml/src/schemas/index.ts @@ -78,18 +78,17 @@ export const blockItemWrapperSchema = ( export const blockOrSchema = ( schema: T, usesSchema: z.ZodTypeAny = defaultUsesSchema, -) => z.union([schema, blockItemWrapperSchema(schema, usesSchema)]); - -export const blockOrDiscriminatedUnionSchema = ( - schema: T, - usesSchema: z.ZodTypeAny = defaultUsesSchema, -) => z.union([schema, z.object({ - uses: usesSchema, - with: z.record(z.string()).optional(), - // For a discriminated union, we can't easily create a partial version - // So we'll use any for the override - override: z.any().optional(), -})]); + isDiscriminatedUnion?: boolean, +) => { + if (isDiscriminatedUnion) { + return z.union([schema, z.object({ + uses: usesSchema, + with: z.record(z.string()).optional(), + override: z.any().optional(), + })]); + } + return z.union([schema, blockItemWrapperSchema(schema, usesSchema)]); +}; export const commonMetadataSchema = z.object({ tags: z.string().optional(), @@ -126,7 +125,7 @@ export const configYamlSchema = baseConfigYamlSchema.extend({ .optional(), context: z.array(blockOrSchema(contextSchema)).optional(), data: z.array(blockOrSchema(dataSchema)).optional(), - mcpServers: z.array(blockOrDiscriminatedUnionSchema(mcpServerSchema)).optional(), + mcpServers: z.array(blockOrSchema(mcpServerSchema as any, defaultUsesSchema, true)).optional(), rules: z .array( z.union([ @@ -251,4 +250,4 @@ export const configSchema = z.object({ api_key: z.string().optional(), }); -export type Config = z.infer; +export type Config = z.infer; \ No newline at end of file