From 21eb6b320c785a3fde61eb8909bf1ffb91a47172 Mon Sep 17 00:00:00 2001 From: xingchen <1098756313@qq.com> Date: Fri, 25 Sep 2026 11:57:06 +0800 Subject: [PATCH] feat: add src/model.mjs --- src/model.mjs | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/model.mjs 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 }; +}