Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions renderers/web_core/src/v0_8/schema/common-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import {z} from 'zod';
* Base primitives
*/

const exactlyOneKey = (val: any, ctx: z.RefinementCtx) => {
const atLeastOneKey = (val: any, ctx: z.RefinementCtx) => {
const keys = Object.keys(val).filter(k => val[k] !== undefined);
if (keys.length !== 1) {
if (keys.length < 1) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `Must define exactly one property, found ${keys.length} (${keys.join(', ')}).`,
message: `Must define at least one property, found ${keys.length}.`,
});
}
};
Expand All @@ -37,7 +37,7 @@ export const StringValueSchema = z
literal: z.string().optional(),
})
.strict()
.superRefine(exactlyOneKey);
.superRefine(atLeastOneKey);
export type StringValue = z.infer<typeof StringValueSchema>;

const DataValueMapItemSchema: z.ZodType<any> = z.lazy(() =>
Expand Down Expand Up @@ -95,7 +95,7 @@ export const NumberValueSchema = z
literal: z.number().optional(),
})
.strict()
.superRefine(exactlyOneKey);
.superRefine(atLeastOneKey);
export type NumberValue = z.infer<typeof NumberValueSchema>;

export const BooleanValueSchema = z
Expand All @@ -105,7 +105,7 @@ export const BooleanValueSchema = z
literal: z.boolean().optional(),
})
.strict()
.superRefine(exactlyOneKey);
.superRefine(atLeastOneKey);
export type BooleanValue = z.infer<typeof BooleanValueSchema>;

/**
Expand All @@ -129,9 +129,9 @@ export const ActionSchema = z.object({
literalNumber: z.number().optional(),
literalBoolean: z.boolean().optional(),
})
.describe('The dynamic value. Define EXACTLY ONE of the nested properties.')
.describe('The dynamic value. Define at least one of the nested properties.')
.strict()
.superRefine(exactlyOneKey),
.superRefine(atLeastOneKey),
}),
)
.describe('A key-value map of data bindings to be resolved when the action is triggered.')
Expand Down Expand Up @@ -200,7 +200,7 @@ export const TabsSchema = z.object({
});
}
if (val.title) {
exactlyOneKey(val.title, ctx);
atLeastOneKey(val.title, ctx);
}
}),
)
Expand Down Expand Up @@ -243,7 +243,7 @@ export const CheckboxSchema = z.object({
literalBoolean: z.boolean().optional(),
})
.strict()
.superRefine(exactlyOneKey),
.superRefine(atLeastOneKey),
});

export const TextFieldSchema = z.object({
Expand Down Expand Up @@ -273,7 +273,7 @@ export const MultipleChoiceSchema = z.object({
literalArray: z.array(z.string()).optional(),
})
.strict()
.superRefine(exactlyOneKey),
.superRefine(atLeastOneKey),
options: z
.array(
z.object({
Expand All @@ -288,7 +288,7 @@ export const MultipleChoiceSchema = z.object({
literalString: z.string().describe('A fixed, hardcoded string value.').optional(),
})
.strict()
.superRefine(exactlyOneKey),
.superRefine(atLeastOneKey),
value: z.string(),
}),
)
Expand All @@ -308,7 +308,7 @@ export const SliderSchema = z.object({
literalNumber: z.number().optional(),
})
.strict()
.superRefine(exactlyOneKey),
.superRefine(atLeastOneKey),
minValue: z.number().optional(),
maxValue: z.number().optional(),
label: StringValueSchema.optional(),
Expand All @@ -327,7 +327,7 @@ export const ComponentArrayReferenceSchema = z
).optional(),
})
.strict()
.superRefine(exactlyOneKey);
.superRefine(atLeastOneKey);

export const RowSchema = z.object({
children: ComponentArrayReferenceSchema,
Expand Down
Loading