2024-10-13 15:25:30 -07:00
|
|
|
import * as v from 'valibot';
|
2024-08-28 04:43:23 -07:00
|
|
|
|
2024-10-13 15:25:30 -07:00
|
|
|
const baseRuleSchema = v.object({
|
|
|
|
id: v.string(),
|
|
|
|
text: v.fallback(v.string(), ''),
|
|
|
|
hint: v.fallback(v.string(), ''),
|
2024-08-28 04:43:23 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
/** @see {@link https://docs.joinmastodon.org/entities/Rule/} */
|
2024-10-15 16:08:56 -07:00
|
|
|
const ruleSchema = v.pipe(
|
|
|
|
v.any(),
|
|
|
|
v.transform((data: any) => ({
|
|
|
|
...data,
|
|
|
|
hint: data.hint || data.subtext,
|
|
|
|
})),
|
|
|
|
baseRuleSchema,
|
|
|
|
);
|
2024-08-28 04:43:23 -07:00
|
|
|
|
2024-10-13 15:25:30 -07:00
|
|
|
type Rule = v.InferOutput<typeof ruleSchema>;
|
2024-08-28 04:43:23 -07:00
|
|
|
|
|
|
|
export { ruleSchema, type Rule };
|