openclaw / src /schema /dashboard.schema.js
getzero11's picture
Create src/schema/dashboard.schema.js
e70f810 verified
raw
history blame
1.08 kB
export function validateDashboard(d) {
if (!d) throw new Error("dashboard_view missing");
if (!d.marketTitle) {
throw new Error("dashboard_view.marketTitle missing");
}
if (!d.marketSummary) {
throw new Error("dashboard_view.marketSummary missing");
}
const ms = d.marketSummary;
requireNumber(ms.past2023, "past2023");
requireNumber(ms.current2025, "current2025");
requireNumber(ms.forecast2033, "forecast2033");
requireNumber(ms.cagr, "cagr");
if (!Array.isArray(d.forecast)) {
throw new Error("dashboard_view.forecast must be array");
}
if (!Array.isArray(d.regional)) {
throw new Error("dashboard_view.regional must be array");
}
if (!Array.isArray(d.segments)) {
throw new Error("dashboard_view.segments must be array");
}
if (!Array.isArray(d.competitive)) {
throw new Error("dashboard_view.competitive must be array");
}
}
function requireNumber(value, name) {
if (typeof value !== "number" || Number.isNaN(value)) {
throw new Error(`dashboard_view.marketSummary.${name} must be number`);
}
}