feat: add src/model.mjs

This commit is contained in:
2026-09-25 11:57:06 +08:00
parent 7602ec7af4
commit 21eb6b320c

10
src/model.mjs Normal file
View File

@@ -0,0 +1,10 @@
export const TYPES = new Set(['ALARM', 'ACK', 'CLEAR']);
export function normalizeEvent(raw, index) {
if (!raw || !raw.device || !raw.alarmId || !TYPES.has(raw.type))
return { error: 'invalid event', index };
const time = Number(raw.time);
if (!Number.isFinite(time) || time < 0) return { error: 'invalid time', index };
return { device: String(raw.device), alarmId: String(raw.alarmId),
type: raw.type, time, index };
}