@@ -18,8 +18,8 @@ export class ExecutionError {
1818 /**
1919 * The raw traceback of the error.
2020 **/
21- public tracebackRaw : string [ ] ,
22- ) { }
21+ public tracebackRaw : string [ ]
22+ ) { }
2323
2424 /**
2525 * Returns the traceback of the error as a string.
@@ -50,9 +50,9 @@ export type RawData = {
5050 * as a string, and the result can contain multiple types of data. The text representation is always present, and
5151 * the other representations are optional.
5252 */
53- export class Data {
53+ export class Result {
5454 /**
55- * Text representation of the data . Always present.
55+ * Text representation of the result . Always present.
5656 */
5757 readonly text : string
5858 /**
@@ -114,18 +114,20 @@ export class Data {
114114
115115 this . extra = { }
116116 for ( const key of Object . keys ( data ) ) {
117- if ( ! [
118- 'text/plain' ,
119- 'text/html' ,
120- 'text/markdown' ,
121- 'image/svg+xml' ,
122- 'image/png' ,
123- 'image/jpeg' ,
124- 'application/pdf' ,
125- 'text/latex' ,
126- 'application/json' ,
127- 'application/javascript'
128- ] . includes ( key ) ) {
117+ if (
118+ ! [
119+ 'text/plain' ,
120+ 'text/html' ,
121+ 'text/markdown' ,
122+ 'image/svg+xml' ,
123+ 'image/png' ,
124+ 'image/jpeg' ,
125+ 'application/pdf' ,
126+ 'text/latex' ,
127+ 'application/json' ,
128+ 'application/javascript'
129+ ] . includes ( key )
130+ ) {
129131 this . extra [ key ] = data [ key ]
130132 }
131133 }
@@ -149,27 +151,27 @@ export type Logs = {
149151/**
150152 * Represents the result of a cell execution.
151153 */
152- export class Result {
154+ export class Execution {
153155 constructor (
154156 /**
155- * List of result of the cell (interactively interpreted last line), display calls, e.g. matplotlib plots.
157+ * List of result of the cell (interactively interpreted last line), display calls ( e.g. matplotlib plots) .
156158 */
157- public data : Data [ ] ,
159+ public results : Result [ ] ,
158160 /**
159161 * Logs printed to stdout and stderr during execution.
160162 */
161163 public logs : Logs ,
162164 /**
163165 * An Error object if an error occurred, null otherwise.
164166 */
165- public error ?: ExecutionError ,
166- ) { }
167+ public error ?: ExecutionError
168+ ) { }
167169
168170 /**
169171 * Returns the text representation of the main result of the cell.
170172 */
171173 get text ( ) : string | undefined {
172- for ( const data of this . data ) {
174+ for ( const data of this . results ) {
173175 if ( data . isMainResult ) {
174176 return data . text
175177 }
@@ -182,18 +184,18 @@ export class Result {
182184 * It's an internal class used by JupyterKernelWebSocket.
183185 */
184186class CellExecution {
185- result : Result
187+ result : Execution
186188 onStdout ?: ( out : ProcessMessage ) => Promise < void > | void
187189 onStderr ?: ( out : ProcessMessage ) => Promise < void > | void
188- onDisplayData ?: ( data : Data ) => Promise < void > | void
190+ onDisplayData ?: ( data : Result ) => Promise < void > | void
189191 inputAccepted : boolean = false
190192
191193 constructor (
192194 onStdout ?: ( out : ProcessMessage ) => Promise < void > | void ,
193195 onStderr ?: ( out : ProcessMessage ) => Promise < void > | void ,
194- onDisplayData ?: ( data : Data ) => Promise < void > | void
196+ onDisplayData ?: ( data : Result ) => Promise < void > | void
195197 ) {
196- this . result = new Result ( [ ] , { stdout : [ ] , stderr : [ ] } )
198+ this . result = new Execution ( [ ] , { stdout : [ ] , stderr : [ ] } )
197199 this . onStdout = onStdout
198200 this . onStderr = onStderr
199201 this . onDisplayData = onDisplayData
@@ -230,7 +232,7 @@ export class JupyterKernelWebSocket {
230232 * Does not start WebSocket connection!
231233 * You need to call connect() method first.
232234 */
233- constructor ( private readonly url : string ) { }
235+ constructor ( private readonly url : string ) { }
234236
235237 // public
236238 /**
@@ -263,7 +265,7 @@ export class JupyterKernelWebSocket {
263265 result . error = new ExecutionError (
264266 message . content . ename ,
265267 message . content . evalue ,
266- message . content . traceback ,
268+ message . content . traceback
267269 )
268270 } else if ( message . msg_type == 'stream' ) {
269271 if ( message . content . name == 'stdout' ) {
@@ -290,12 +292,12 @@ export class JupyterKernelWebSocket {
290292 }
291293 }
292294 } else if ( message . msg_type == 'display_data' ) {
293- result . data . push ( new Data ( message . content . data , false ) )
295+ result . results . push ( new Result ( message . content . data , false ) )
294296 if ( cell . onDisplayData ) {
295- cell . onDisplayData ( new Data ( message . content . data , false ) )
297+ cell . onDisplayData ( new Result ( message . content . data , false ) )
296298 }
297299 } else if ( message . msg_type == 'execute_result' ) {
298- result . data . push ( new Data ( message . content . data , true ) )
300+ result . results . push ( new Result ( message . content . data , true ) )
299301 } else if ( message . msg_type == 'status' ) {
300302 if ( message . content . execution_state == 'idle' ) {
301303 if ( cell . inputAccepted ) {
@@ -305,7 +307,7 @@ export class JupyterKernelWebSocket {
305307 result . error = new ExecutionError (
306308 message . content . ename ,
307309 message . content . evalue ,
308- message . content . traceback ,
310+ message . content . traceback
309311 )
310312 this . idAwaiter [ parentMsgId ] ( result )
311313 }
@@ -314,15 +316,15 @@ export class JupyterKernelWebSocket {
314316 result . error = new ExecutionError (
315317 message . content . ename ,
316318 message . content . evalue ,
317- message . content . traceback ,
319+ message . content . traceback
318320 )
319321 } else if ( message . content . status == 'ok' ) {
320322 return
321323 }
322324 } else if ( message . msg_type == 'execute_input' ) {
323325 cell . inputAccepted = true
324326 } else {
325- console . log ( '[UNHANDLED MESSAGE TYPE]:' , message . msg_type )
327+ console . warn ( '[UNHANDLED MESSAGE TYPE]:' , message . msg_type )
326328 }
327329 }
328330 }
@@ -341,10 +343,10 @@ export class JupyterKernelWebSocket {
341343 code : string ,
342344 onStdout ?: ( out : ProcessMessage ) => Promise < void > | void ,
343345 onStderr ?: ( out : ProcessMessage ) => Promise < void > | void ,
344- onDisplayData ?: ( data : Data ) => Promise < void > | void ,
346+ onDisplayData ?: ( data : Result ) => Promise < void > | void ,
345347 timeout ?: number
346348 ) {
347- return new Promise < Result > ( ( resolve , reject ) => {
349+ return new Promise < Execution > ( ( resolve , reject ) => {
348350 const msg_id = crypto . randomUUID ( )
349351 const data = this . sendExecuteRequest ( msg_id , code )
350352
@@ -364,7 +366,7 @@ export class JupyterKernelWebSocket {
364366
365367 // expect response
366368 this . cells [ msg_id ] = new CellExecution ( onStdout , onStderr , onDisplayData )
367- this . idAwaiter [ msg_id ] = ( responseData : Result ) => {
369+ this . idAwaiter [ msg_id ] = ( responseData : Execution ) => {
368370 // stop timeout
369371 clearInterval ( timeoutSet as number )
370372 // stop waiting for response
@@ -383,7 +385,6 @@ export class JupyterKernelWebSocket {
383385 */
384386 private listen ( ) {
385387 return new Promise ( ( resolve , reject ) => {
386-
387388 this . ws . onopen = ( e : unknown ) => {
388389 resolve ( e )
389390 }
0 commit comments