@@ -58,7 +58,8 @@ RELATIONSHIP = 0x52,
5858UNBOUND_RELATIONSHIP = 0x72 ,
5959PATH = 0x50 ,
6060//sent before version negotiation
61- MAGIC_PREAMBLE = 0x6060B017 ;
61+ MAGIC_PREAMBLE = 0x6060B017 ,
62+ DEBUG = false ;
6263
6364let URLREGEX = new RegExp ( [
6465 "[^/]+//" , // scheme
@@ -70,6 +71,20 @@ function host( url ) {
7071 return url . match ( URLREGEX ) [ 2 ] ;
7172}
7273
74+ /**
75+ * Very rudimentary log handling, should probably be replaced by something proper at some point.
76+ * @param actor the part that sent the message, 'S' for server and 'C' for client
77+ * @param msg the bolt message
78+ */
79+ function log ( actor , msg ) {
80+ if ( DEBUG ) {
81+ for ( var i = 2 ; i < arguments . length ; i ++ ) {
82+ msg += " " + JSON . stringify ( arguments [ i ] ) ;
83+ }
84+ console . log ( actor + ":" + msg ) ;
85+ }
86+ }
87+
7388function port ( url ) {
7489 return url . match ( URLREGEX ) [ 3 ] ;
7590}
@@ -186,8 +201,6 @@ class Connection {
186201 this . _unpacker . structMappers [ UNBOUND_RELATIONSHIP ] = _mappers . unboundRel ;
187202 this . _unpacker . structMappers [ PATH ] = _mappers . path ;
188203
189-
190-
191204 let self = this ;
192205 // TODO: Using `onmessage` and `onerror` came from the WebSocket API,
193206 // it reads poorly and has several annoying drawbacks. Swap to having
@@ -266,16 +279,19 @@ class Connection {
266279 _handleMessage ( msg ) {
267280 switch ( msg . signature ) {
268281 case RECORD :
282+ log ( "S" , "RECORD" , msg . fields [ 0 ] ) ;
269283 this . _currentObserver . onNext ( msg . fields [ 0 ] ) ;
270284 break ;
271285 case SUCCESS :
286+ log ( "S" , "SUCCESS" , msg . fields [ 0 ] ) ;
272287 try {
273288 this . _currentObserver . onCompleted ( msg . fields [ 0 ] ) ;
274289 } finally {
275290 this . _currentObserver = this . _pendingObservers . shift ( ) ;
276291 }
277292 break ;
278293 case FAILURE :
294+ log ( "S" , "FAILURE" , msg ) ;
279295 try {
280296 this . _currentObserver . onError ( msg ) ;
281297 this . _errorMsg = msg ;
@@ -303,6 +319,7 @@ class Connection {
303319 }
304320 break ;
305321 case IGNORED :
322+ log ( "S" , "IGNORED" ) ;
306323 try {
307324 if ( this . _errorMsg && this . _currentObserver . onError )
308325 this . _currentObserver . onError ( this . _errorMsg ) ;
@@ -319,6 +336,7 @@ class Connection {
319336
320337 /** Queue an INIT-message to be sent to the database */
321338 initialize ( clientName , token , observer ) {
339+ log ( "C" , "INIT" , clientName , token ) ;
322340 this . _queueObserver ( observer ) ;
323341 this . _packer . packStruct ( INIT , [ this . _packable ( clientName ) , this . _packable ( token ) ] ,
324342 ( err ) => this . _handleFatalError ( err ) ) ;
@@ -328,6 +346,7 @@ class Connection {
328346
329347 /** Queue a RUN-message to be sent to the database */
330348 run ( statement , params , observer ) {
349+ log ( "C" , "RUN" , statement , params ) ;
331350 this . _queueObserver ( observer ) ;
332351 this . _packer . packStruct ( RUN , [ this . _packable ( statement ) , this . _packable ( params ) ] ,
333352 ( err ) => this . _handleFatalError ( err ) ) ;
@@ -336,20 +355,23 @@ class Connection {
336355
337356 /** Queue a PULL_ALL-message to be sent to the database */
338357 pullAll ( observer ) {
358+ log ( "C" , "PULL_ALL" ) ;
339359 this . _queueObserver ( observer ) ;
340360 this . _packer . packStruct ( PULL_ALL , [ ] , ( err ) => this . _handleFatalError ( err ) ) ;
341361 this . _chunker . messageBoundary ( ) ;
342362 }
343363
344364 /** Queue a DISCARD_ALL-message to be sent to the database */
345365 discardAll ( observer ) {
366+ log ( "C" , "DISCARD_ALL" ) ;
346367 this . _queueObserver ( observer ) ;
347368 this . _packer . packStruct ( DISCARD_ALL , [ ] , ( err ) => this . _handleFatalError ( err ) ) ;
348369 this . _chunker . messageBoundary ( ) ;
349370 }
350371
351372 /** Queue a RESET-message to be sent to the database */
352373 reset ( observer ) {
374+ log ( "C" , "RESET" ) ;
353375 this . _isHandlingFailure = true ;
354376 let self = this ;
355377 let wrappedObs = {
@@ -369,6 +391,7 @@ class Connection {
369391
370392 /** Queue a ACK_FAILURE-message to be sent to the database */
371393 _ackFailure ( observer ) {
394+ log ( "C" , "ACK_FAILURE" ) ;
372395 this . _queueObserver ( observer ) ;
373396 this . _packer . packStruct ( ACK_FAILURE , [ ] , ( err ) => this . _handleFatalError ( err ) ) ;
374397 this . _chunker . messageBoundary ( ) ;
0 commit comments