(
content: string,
options?: {
path?: string;
backend?: LogBackend;
maxEntries?: number;
include?: NetworkIncludeMode;
maxPayloadChars?: number;
maxScanLines?: number;
},
)
| 105 | } |
| 106 | |
| 107 | export function readRecentNetworkTrafficFromText( |
| 108 | content: string, |
| 109 | options?: { |
| 110 | path?: string; |
| 111 | backend?: LogBackend; |
| 112 | maxEntries?: number; |
| 113 | include?: NetworkIncludeMode; |
| 114 | maxPayloadChars?: number; |
| 115 | maxScanLines?: number; |
| 116 | }, |
| 117 | ): NetworkDump { |
| 118 | const maxEntries = clampInt(options?.maxEntries, 25, 1, 200); |
| 119 | const backend = options?.backend; |
| 120 | const include = options?.include ?? 'summary'; |
| 121 | const maxPayloadChars = clampInt(options?.maxPayloadChars, 2048, 64, 16_384); |
| 122 | const maxScanLines = clampInt(options?.maxScanLines, 4000, 100, 20_000); |
| 123 | const allLines = content.split('\n'); |
| 124 | const startIndex = Math.max(0, allLines.length - maxScanLines); |
| 125 | const lines = allLines.slice(startIndex); |
| 126 | const entries: NetworkEntry[] = []; |
| 127 | |
| 128 | for (let i = lines.length - 1; i >= 0 && entries.length < maxEntries; i -= 1) { |
| 129 | const rawLine = lines[i]; |
| 130 | const trimmedLine = rawLine?.trim(); |
| 131 | if (!trimmedLine) continue; |
| 132 | const parsed = parseNetworkLine( |
| 133 | lines, |
| 134 | i, |
| 135 | startIndex + i + 1, |
| 136 | backend, |
| 137 | include, |
| 138 | maxPayloadChars, |
| 139 | ); |
| 140 | if (!parsed) continue; |
| 141 | entries.push(parsed); |
| 142 | } |
| 143 | |
| 144 | return { |
| 145 | path: options?.path ?? NETWORK_LOG_MEMORY_PATH, |
| 146 | exists: true, |
| 147 | scannedLines: lines.length, |
| 148 | matchedLines: entries.length, |
| 149 | entries, |
| 150 | include, |
| 151 | limits: { maxEntries, maxPayloadChars, maxScanLines }, |
| 152 | }; |
| 153 | } |
| 154 | |
| 155 | function parseNetworkLine( |
| 156 | lines: string[], |
no test coverage detected
searching dependent graphs…