Files
HealthLog/src/lib/validations/thresholds.ts
T
Marc-André BombeckandClaude Opus 4.7 02b99553b9 chore(style): repo-wide prettier sweep before v1.4.6 tag
Long-overdue prettier sweep; prettier had drifted vs. checked-in code
across ~130 files (mostly long-argument line-break wrapping in TS and
table-padding in markdown). Pure formatting — no semantic changes —
and required to clear the v1.4.6 release gate's `pnpm format:check`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 02:27:17 +02:00

38 lines
1.0 KiB
TypeScript

import { z } from "zod/v4";
import {
METRIC_BOUNDS,
type ThresholdMetric,
} from "@/lib/analytics/effective-range";
const metricKeys = Object.keys(METRIC_BOUNDS) as ThresholdMetric[];
function rangeSchemaFor(metric: ThresholdMetric) {
const { min, max } = METRIC_BOUNDS[metric];
return z
.object({
min: z.number().min(min).max(max),
max: z.number().min(min).max(max),
})
.refine((v) => v.min < v.max, {
message: "min must be strictly less than max",
});
}
/**
* Validates a partial override payload from the user.
* Unknown keys are rejected. Each range must be within the metric's
* physiological bounds and min < max.
*/
export const thresholdsUpdateSchema = z
.object(
Object.fromEntries(
metricKeys.map((m) => [m, rangeSchemaFor(m).optional()]),
),
)
.strict();
export type ThresholdsUpdatePayload = z.infer<typeof thresholdsUpdateSchema>;
/** Metric list kept exported here so admin and settings UI stay in sync. */
export const ALL_METRICS: ThresholdMetric[] = metricKeys;