feat(core): add shared Zod config/WS schemas and SQLite WAL migrations

This commit is contained in:
tyuXX 2026-11-26 18:19:33 +00:00
parent 48676a1285
commit 2c60483a90
12 changed files with 1007 additions and 0 deletions

View file

@ -0,0 +1,36 @@
import { CronPattern } from 'croner';
import { z } from 'zod';
export const EntityIdSchema = z
.string()
.min(1, 'ID must not be empty')
.max(64, 'ID must be at most 64 characters')
.regex(/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,63}$/, 'ID must start with alphanumeric and contain only [a-zA-Z0-9._-]');
export const PortSchema = z.number().int().min(1).max(65535);
export const CronExpressionSchema = z
.string()
.min(1)
.superRefine((expr, ctx) => {
try {
new CronPattern(expr);
} catch (err) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `Invalid cron expression "${expr}": ${err instanceof Error ? err.message : String(err)}`,
});
}
});
export const InputDefSchema = z.object({
name: EntityIdSchema,
type: z.enum(['string', 'number', 'boolean', 'server', 'select']).default('string'),
label: z.string().min(1).optional(),
description: z.string().optional(),
required: z.boolean().default(false),
default: z.union([z.string(), z.number(), z.boolean()]).optional(),
options: z.array(z.string()).optional(),
});
export type InputDef = z.infer<typeof InputDefSchema>;