refactor: share reaction schemas and notes

This commit is contained in:
Peter Steinberger
2026-01-07 04:24:11 +01:00
parent 654e14df31
commit 8ef0609f8e
11 changed files with 81 additions and 40 deletions

View File

@@ -0,0 +1,24 @@
import { type TSchema, Type } from "@sinclair/typebox";
type ReactionSchemaOptions = {
action?: string;
ids: Record<string, TSchema>;
emoji?: TSchema;
includeRemove?: boolean;
extras?: Record<string, TSchema>;
};
export function createReactionSchema(options: ReactionSchemaOptions) {
const schema: Record<string, TSchema> = {
action: Type.Literal(options.action ?? "react"),
...options.ids,
emoji: options.emoji ?? Type.String(),
};
if (options.includeRemove) {
schema.remove = Type.Optional(Type.Boolean());
}
if (options.extras) {
Object.assign(schema, options.extras);
}
return Type.Object(schema);
}