@@ -58,7 +58,8 @@ RELATIONSHIP = 0x52,
58
58
UNBOUND_RELATIONSHIP = 0x72 ,
59
59
PATH = 0x50 ,
60
60
//sent before version negotiation
61
- MAGIC_PREAMBLE = 0x6060B017 ;
61
+ MAGIC_PREAMBLE = 0x6060B017 ,
62
+ DEBUG = false ;
62
63
63
64
let URLREGEX = new RegExp ( [
64
65
"[^/]+//" , // scheme
@@ -70,6 +71,20 @@ function host( url ) {
70
71
return url . match ( URLREGEX ) [ 2 ] ;
71
72
}
72
73
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
+
73
88
function port ( url ) {
74
89
return url . match ( URLREGEX ) [ 3 ] ;
75
90
}
@@ -186,8 +201,6 @@ class Connection {
186
201
this . _unpacker . structMappers [ UNBOUND_RELATIONSHIP ] = _mappers . unboundRel ;
187
202
this . _unpacker . structMappers [ PATH ] = _mappers . path ;
188
203
189
-
190
-
191
204
let self = this ;
192
205
// TODO: Using `onmessage` and `onerror` came from the WebSocket API,
193
206
// it reads poorly and has several annoying drawbacks. Swap to having
@@ -266,16 +279,19 @@ class Connection {
266
279
_handleMessage ( msg ) {
267
280
switch ( msg . signature ) {
268
281
case RECORD :
282
+ log ( "S" , "RECORD" , msg . fields [ 0 ] ) ;
269
283
this . _currentObserver . onNext ( msg . fields [ 0 ] ) ;
270
284
break ;
271
285
case SUCCESS :
286
+ log ( "S" , "SUCCESS" , msg . fields [ 0 ] ) ;
272
287
try {
273
288
this . _currentObserver . onCompleted ( msg . fields [ 0 ] ) ;
274
289
} finally {
275
290
this . _currentObserver = this . _pendingObservers . shift ( ) ;
276
291
}
277
292
break ;
278
293
case FAILURE :
294
+ log ( "S" , "FAILURE" , msg ) ;
279
295
try {
280
296
this . _currentObserver . onError ( msg ) ;
281
297
this . _errorMsg = msg ;
@@ -303,6 +319,7 @@ class Connection {
303
319
}
304
320
break ;
305
321
case IGNORED :
322
+ log ( "S" , "IGNORED" ) ;
306
323
try {
307
324
if ( this . _errorMsg && this . _currentObserver . onError )
308
325
this . _currentObserver . onError ( this . _errorMsg ) ;
@@ -319,6 +336,7 @@ class Connection {
319
336
320
337
/** Queue an INIT-message to be sent to the database */
321
338
initialize ( clientName , token , observer ) {
339
+ log ( "C" , "INIT" , clientName , token ) ;
322
340
this . _queueObserver ( observer ) ;
323
341
this . _packer . packStruct ( INIT , [ this . _packable ( clientName ) , this . _packable ( token ) ] ,
324
342
( err ) => this . _handleFatalError ( err ) ) ;
@@ -328,6 +346,7 @@ class Connection {
328
346
329
347
/** Queue a RUN-message to be sent to the database */
330
348
run ( statement , params , observer ) {
349
+ log ( "C" , "RUN" , statement , params ) ;
331
350
this . _queueObserver ( observer ) ;
332
351
this . _packer . packStruct ( RUN , [ this . _packable ( statement ) , this . _packable ( params ) ] ,
333
352
( err ) => this . _handleFatalError ( err ) ) ;
@@ -336,20 +355,23 @@ class Connection {
336
355
337
356
/** Queue a PULL_ALL-message to be sent to the database */
338
357
pullAll ( observer ) {
358
+ log ( "C" , "PULL_ALL" ) ;
339
359
this . _queueObserver ( observer ) ;
340
360
this . _packer . packStruct ( PULL_ALL , [ ] , ( err ) => this . _handleFatalError ( err ) ) ;
341
361
this . _chunker . messageBoundary ( ) ;
342
362
}
343
363
344
364
/** Queue a DISCARD_ALL-message to be sent to the database */
345
365
discardAll ( observer ) {
366
+ log ( "C" , "DISCARD_ALL" ) ;
346
367
this . _queueObserver ( observer ) ;
347
368
this . _packer . packStruct ( DISCARD_ALL , [ ] , ( err ) => this . _handleFatalError ( err ) ) ;
348
369
this . _chunker . messageBoundary ( ) ;
349
370
}
350
371
351
372
/** Queue a RESET-message to be sent to the database */
352
373
reset ( observer ) {
374
+ log ( "C" , "RESET" ) ;
353
375
this . _isHandlingFailure = true ;
354
376
let self = this ;
355
377
let wrappedObs = {
@@ -369,6 +391,7 @@ class Connection {
369
391
370
392
/** Queue a ACK_FAILURE-message to be sent to the database */
371
393
_ackFailure ( observer ) {
394
+ log ( "C" , "ACK_FAILURE" ) ;
372
395
this . _queueObserver ( observer ) ;
373
396
this . _packer . packStruct ( ACK_FAILURE , [ ] , ( err ) => this . _handleFatalError ( err ) ) ;
374
397
this . _chunker . messageBoundary ( ) ;
0 commit comments