feat: add src/model.mjs
This commit is contained in:
10
src/model.mjs
Normal file
10
src/model.mjs
Normal 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 };
|
||||
}
|
||||
Reference in New Issue
Block a user