11import { requestClient } from '../request'
2+ import { createTraceStreamProcessor } from './data-trace-stream-parser'
23
34const BASE_URL = '/api/lineage/wide-table'
45
@@ -98,27 +99,9 @@ export function getTraceData(
9899 callbacks : TraceStreamCallbacks ,
99100) : AbortController {
100101 const controller = new AbortController ( )
101- let lastIndex = 0
102-
103- function processChunk ( text : string ) {
104- const newText = text . slice ( lastIndex )
105- lastIndex = text . length
106-
107- const lines = newText . split ( '\n' )
108- for ( const line of lines ) {
109- const trimmed = line . trim ( )
110- if ( ! trimmed ) continue
111- try {
112- const parsed = JSON . parse ( trimmed )
113- if ( parsed . nodeId !== undefined && parsed . type === 'TRACE_VALUE' ) {
114- console . log ( 'parsed' , parsed )
115- callbacks . onNodeData ?.( parsed . nodeId , parsed )
116- }
117- } catch {
118- // ignore incomplete line (will be completed in next chunk)
119- }
120- }
121- }
102+ const processChunk = createTraceStreamProcessor ( ( nodeId , parsed ) => {
103+ callbacks . onNodeData ?.( nodeId , parsed )
104+ } )
122105
123106 requestClient
124107 . post ( `${ BASE_URL } /trace/stream` , data , {
@@ -135,6 +118,7 @@ export function getTraceData(
135118 } ,
136119 } )
137120 . then ( ( ) => {
121+ processChunk . flush ( )
138122 callbacks . onDone ?.( )
139123 } )
140124 . catch ( ( error : any ) => {
0 commit comments