Skip to content

Commit 0356b0d

Browse files
committed
refactor: move blockOrDiscriminatedUnionSchema logic inside of blockOrSchema
1 parent 63a2ffe commit 0356b0d

File tree

1 file changed

+13
-14
lines changed
  • packages/config-yaml/src/schemas

1 file changed

+13
-14
lines changed

packages/config-yaml/src/schemas/index.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,17 @@ export const blockItemWrapperSchema = <T extends z.AnyZodObject>(
7878
export const blockOrSchema = <T extends z.AnyZodObject>(
7979
schema: T,
8080
usesSchema: z.ZodTypeAny = defaultUsesSchema,
81-
) => z.union([schema, blockItemWrapperSchema(schema, usesSchema)]);
82-
83-
export const blockOrDiscriminatedUnionSchema = <T extends z.ZodType>(
84-
schema: T,
85-
usesSchema: z.ZodTypeAny = defaultUsesSchema,
86-
) => z.union([schema, z.object({
87-
uses: usesSchema,
88-
with: z.record(z.string()).optional(),
89-
// For a discriminated union, we can't easily create a partial version
90-
// So we'll use any for the override
91-
override: z.any().optional(),
92-
})]);
81+
isDiscriminatedUnion?: boolean,
82+
) => {
83+
if (isDiscriminatedUnion) {
84+
return z.union([schema, z.object({
85+
uses: usesSchema,
86+
with: z.record(z.string()).optional(),
87+
override: z.any().optional(),
88+
})]);
89+
}
90+
return z.union([schema, blockItemWrapperSchema(schema, usesSchema)]);
91+
};
9392

9493
export const commonMetadataSchema = z.object({
9594
tags: z.string().optional(),
@@ -126,7 +125,7 @@ export const configYamlSchema = baseConfigYamlSchema.extend({
126125
.optional(),
127126
context: z.array(blockOrSchema(contextSchema)).optional(),
128127
data: z.array(blockOrSchema(dataSchema)).optional(),
129-
mcpServers: z.array(blockOrDiscriminatedUnionSchema(mcpServerSchema)).optional(),
128+
mcpServers: z.array(blockOrSchema(mcpServerSchema as any, defaultUsesSchema, true)).optional(),
130129
rules: z
131130
.array(
132131
z.union([
@@ -251,4 +250,4 @@ export const configSchema = z.object({
251250
api_key: z.string().optional(),
252251
});
253252

254-
export type Config = z.infer<typeof configSchema>;
253+
export type Config = z.infer<typeof configSchema>;

0 commit comments

Comments
 (0)