@@ -59,7 +59,8 @@ RELATIONSHIP = 0x52,
5959UNBOUND_RELATIONSHIP = 0x72 ,
6060PATH = 0x50 ,
6161//sent before version negotiation
62- MAGIC_PREAMBLE = 0x6060B017 ;
62+ MAGIC_PREAMBLE = 0x6060B017 ,
63+ DEBUG = false ;
6364
6465let URLREGEX = new RegExp ( [
6566 "[^/]+//" , // scheme
@@ -71,6 +72,20 @@ function host( url ) {
7172 return url . match ( URLREGEX ) [ 2 ] ;
7273}
7374
75+ /**
76+ * Very rudimentary log handling, should probably be replaced by something proper at some point.
77+ * @param actor the part that sent the message, 'S' for server and 'C' for client
78+ * @param msg the bolt message
79+ */
80+ function log ( actor , msg ) {
81+ if ( DEBUG ) {
82+ for ( var i = 2 ; i < arguments . length ; i ++ ) {
83+ msg += " " + JSON . stringify ( arguments [ i ] ) ;
84+ }
85+ console . log ( actor + ":" + msg ) ;
86+ }
87+ }
88+
7489function port ( url ) {
7590 return url . match ( URLREGEX ) [ 3 ] ;
7691}
@@ -187,8 +202,6 @@ class Connection {
187202 this . _unpacker . structMappers [ UNBOUND_RELATIONSHIP ] = _mappers . unboundRel ;
188203 this . _unpacker . structMappers [ PATH ] = _mappers . path ;
189204
190-
191-
192205 let self = this ;
193206 // TODO: Using `onmessage` and `onerror` came from the WebSocket API,
194207 // it reads poorly and has several annoying drawbacks. Swap to having
@@ -267,16 +280,19 @@ class Connection {
267280 _handleMessage ( msg ) {
268281 switch ( msg . signature ) {
269282 case RECORD :
283+ log ( "S" , "RECORD" , msg . fields [ 0 ] ) ;
270284 this . _currentObserver . onNext ( msg . fields [ 0 ] ) ;
271285 break ;
272286 case SUCCESS :
287+ log ( "S" , "SUCCESS" , msg . fields [ 0 ] ) ;
273288 try {
274289 this . _currentObserver . onCompleted ( msg . fields [ 0 ] ) ;
275290 } finally {
276291 this . _currentObserver = this . _pendingObservers . shift ( ) ;
277292 }
278293 break ;
279294 case FAILURE :
295+ log ( "S" , "FAILURE" , msg ) ;
280296 try {
281297 this . _currentObserver . onError ( msg ) ;
282298 this . _errorMsg = msg ;
@@ -304,6 +320,7 @@ class Connection {
304320 }
305321 break ;
306322 case IGNORED :
323+ log ( "S" , "IGNORED" ) ;
307324 try {
308325 if ( this . _errorMsg && this . _currentObserver . onError )
309326 this . _currentObserver . onError ( this . _errorMsg ) ;
@@ -320,6 +337,7 @@ class Connection {
320337
321338 /** Queue an INIT-message to be sent to the database */
322339 initialize ( clientName , token , observer ) {
340+ log ( "C" , "INIT" , clientName , token ) ;
323341 this . _queueObserver ( observer ) ;
324342 this . _packer . packStruct ( INIT , [ this . _packable ( clientName ) , this . _packable ( token ) ] ,
325343 ( err ) => this . _handleFatalError ( err ) ) ;
@@ -329,6 +347,7 @@ class Connection {
329347
330348 /** Queue a RUN-message to be sent to the database */
331349 run ( statement , params , observer ) {
350+ log ( "C" , "RUN" , statement , params ) ;
332351 this . _queueObserver ( observer ) ;
333352 this . _packer . packStruct ( RUN , [ this . _packable ( statement ) , this . _packable ( params ) ] ,
334353 ( err ) => this . _handleFatalError ( err ) ) ;
@@ -337,20 +356,23 @@ class Connection {
337356
338357 /** Queue a PULL_ALL-message to be sent to the database */
339358 pullAll ( observer ) {
359+ log ( "C" , "PULL_ALL" ) ;
340360 this . _queueObserver ( observer ) ;
341361 this . _packer . packStruct ( PULL_ALL , [ ] , ( err ) => this . _handleFatalError ( err ) ) ;
342362 this . _chunker . messageBoundary ( ) ;
343363 }
344364
345365 /** Queue a DISCARD_ALL-message to be sent to the database */
346366 discardAll ( observer ) {
367+ log ( "C" , "DISCARD_ALL" ) ;
347368 this . _queueObserver ( observer ) ;
348369 this . _packer . packStruct ( DISCARD_ALL , [ ] , ( err ) => this . _handleFatalError ( err ) ) ;
349370 this . _chunker . messageBoundary ( ) ;
350371 }
351372
352373 /** Queue a RESET-message to be sent to the database */
353374 reset ( observer ) {
375+ log ( "C" , "RESET" ) ;
354376 this . _isHandlingFailure = true ;
355377 let self = this ;
356378 let wrappedObs = {
@@ -370,6 +392,7 @@ class Connection {
370392
371393 /** Queue a ACK_FAILURE-message to be sent to the database */
372394 _ackFailure ( observer ) {
395+ log ( "C" , "ACK_FAILURE" ) ;
373396 this . _queueObserver ( observer ) ;
374397 this . _packer . packStruct ( ACK_FAILURE , [ ] , ( err ) => this . _handleFatalError ( err ) ) ;
375398 this . _chunker . messageBoundary ( ) ;
0 commit comments