Files
nadir-webui/src/lib/machines/schema.ts
T
2026-06-22 19:14:44 +02:00

38 lines
1.1 KiB
TypeScript

import { v } from '$lib';
import { m } from '$lib/paraglide/messages';
const nonEmpty = v.pipe(v.string(m.errors_non_empty()), v.nonEmpty(m.errors_non_empty()));
const address = v.pipe(
v.optional(v.string(), 'https://127.0.0.1:9999'),
v.transform((s) => {
const t = s.trim() || 'https://127.0.0.1:9999';
return /^https?:\/\//i.test(t) ? t : `https://${t}`;
}),
v.url(m.errors_address_invalid())
);
export const machineSchema = v.object({ address, name: nonEmpty, token: nonEmpty });
// On edit, any blank field means "keep the existing value" — the server resolves
// it against the current row. Avoids forcing the user to re-paste fields they
// aren't changing.
export const machineEditSchema = v.object({
address: v.pipe(
v.optional(v.string(), ''),
v.transform((s) => {
const t = s.trim();
if (!t) return t;
return /^https?:\/\//i.test(t) ? t : `https://${t}`;
})
),
id: nonEmpty,
name: v.pipe(
v.optional(v.string(), ''),
v.transform((s) => s.trim())
),
token: v.optional(v.string(), '')
});
export const machineDeleteSchema = v.object({ id: nonEmpty });