- MongoDB storage: cwmp_exchanges collection with indexes (deviceId+timestamp, deviceId+sequenceNumber unique, TTL 24h) - ExchangeStoreService: CWMP method extraction, per-device queue for ordering, retry logic, message cap (5000/device) - Exchange API: GET/DELETE/SSE stream endpoints with Last-Event-ID reconnection - CwmpLoggerMiddleware: dual-write (MongoDB + legacy files) with fire-and-forget - Frontend: SequenceViewer (CPE↔ACS lifelines, arrows, auto-scroll, virtual scroll) + InspectorPanel (formatted XML, copy, syntax highlighting) - Tr069Trace page: integrated new viewer with col-6/col-6 layout - DeviceDetail page: collapsible exchange section when device is traced - 14 property-based tests, 40+ unit tests, 5 integration tests - Health check includes index verification - Config: feature flags, SSE timeouts, retry policy
52 lines
1.6 KiB
TypeScript
52 lines
1.6 KiB
TypeScript
/**
|
|
* Formatting helpers for the SequenceViewer component.
|
|
* Extracted for testability and reuse.
|
|
*/
|
|
|
|
/**
|
|
* Determines the CSS arrow direction class based on message direction.
|
|
* "CPE→ACS" messages point left-to-right (arrow-right).
|
|
* "ACS→CPE" messages point right-to-left (arrow-left).
|
|
*/
|
|
export function getArrowClass(direction: 'CPE→ACS' | 'ACS→CPE'): 'arrow-right' | 'arrow-left' {
|
|
return direction === 'CPE→ACS' ? 'arrow-right' : 'arrow-left'
|
|
}
|
|
|
|
/**
|
|
* Formats an ISO 8601 timestamp into HH:mm:ss.SSS display format.
|
|
* Uses UTC time to ensure consistent formatting regardless of timezone.
|
|
*/
|
|
export function formatTimestamp(isoTimestamp: string): string {
|
|
const date = new Date(isoTimestamp)
|
|
const hours = String(date.getUTCHours()).padStart(2, '0')
|
|
const minutes = String(date.getUTCMinutes()).padStart(2, '0')
|
|
const seconds = String(date.getUTCSeconds()).padStart(2, '0')
|
|
const millis = String(date.getUTCMilliseconds()).padStart(3, '0')
|
|
return `${hours}:${minutes}:${seconds}.${millis}`
|
|
}
|
|
|
|
/**
|
|
* Truncates a CWMP method name to 40 characters if it exceeds that length.
|
|
* Appends an ellipsis character (…) when truncated.
|
|
*/
|
|
export function truncateMethod(method: string): string {
|
|
if (method.length > 40) {
|
|
return method.substring(0, 40) + '…'
|
|
}
|
|
return method
|
|
}
|
|
|
|
/**
|
|
* Returns true if the method name exceeds 40 characters and needs truncation.
|
|
*/
|
|
export function needsTruncation(method: string): boolean {
|
|
return method.length > 40
|
|
}
|
|
|
|
/**
|
|
* Formats a trace start time ISO string into a localized display string.
|
|
*/
|
|
export function formatTraceStartTime(iso: string): string {
|
|
return new Date(iso).toLocaleString()
|
|
}
|