diff --git a/src/model.mjs b/src/model.mjs new file mode 100644 index 0000000..5cb9227 --- /dev/null +++ b/src/model.mjs @@ -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 }; +}