MCPcopy Create free account
hub / github.com/bywwcnll/StreamPanel / normalizeMessage

Function normalizeMessage

devtools/modules/importManager.js:118–138  ·  view source on GitHub ↗
(message, index)

Source from the content-addressed store, hash-verified

116}
117
118function normalizeMessage(message, index) {
119 const fallbackTimestamp = Date.now();
120
121 if (!message || typeof message !== 'object') {
122 return {
123 id: index + 1,
124 eventType: 'message',
125 data: String(message ?? ''),
126 lastEventId: '',
127 timestamp: fallbackTimestamp
128 };
129 }
130
131 return {
132 id: Number.isFinite(Number(message.id)) ? Number(message.id) : index + 1,
133 eventType: message.eventType || 'message',
134 data: typeof message.data === 'string' ? message.data : JSON.stringify(message.data ?? ''),
135 lastEventId: message.lastEventId || '',
136 timestamp: parseTimestamp(message.timestamp, fallbackTimestamp)
137 };
138}
139
140function parseTimestamp(value, fallback) {
141 if (typeof value === 'number' && Number.isFinite(value)) {

Callers 1

normalizeConnectionFunction · 0.70

Calls 1

parseTimestampFunction · 0.70

Tested by

no test coverage detected