(value, stream)
| 426 | }; |
| 427 | |
| 428 | const processChunk = (value, stream) => { |
| 429 | if (!value) return; |
| 430 | if (!shouldObserveStream(stream)) return; |
| 431 | |
| 432 | buffer += decoder.decode(value, { stream: true }); |
| 433 | |
| 434 | if (isSSE) { |
| 435 | const boundaryIndex = findCompleteSSEBoundary(buffer); |
| 436 | if (boundaryIndex !== null) { |
| 437 | const completeData = buffer.substring(0, boundaryIndex); |
| 438 | buffer = buffer.substring(boundaryIndex); |
| 439 | const events = parseSSEEvents(completeData); |
| 440 | for (const event of events) { |
| 441 | emitMessage(event.event, event.data, event.id); |
| 442 | } |
| 443 | } |
| 444 | } else if (isNDJSON) { |
| 445 | const lines = buffer.split(/\r?\n/); |
| 446 | buffer = lines.pop() || ''; |
| 447 | for (const line of lines) { |
| 448 | if (line.trim()) { |
| 449 | emitMessage('message', line); |
| 450 | } |
| 451 | } |
| 452 | } |
| 453 | }; |
| 454 | |
| 455 | const createObserverTransform = (stream) => new TransformStream({ |
| 456 | transform(chunk, controller) { |
no test coverage detected