@@ -36,13 +36,13 @@ const {
36
36
37
37
const noop = ( ) => { }
38
38
39
- const productCheckEmitter = new EventEmitter ( )
40
39
const clientVersion = require ( '../package.json' ) . version
41
40
const userAgent = `elasticsearch-js/${ clientVersion } (${ os . platform ( ) } ${ os . release ( ) } -${ os . arch ( ) } ; Node.js ${ process . version } )`
42
41
const MAX_BUFFER_LENGTH = buffer . constants . MAX_LENGTH
43
42
const MAX_STRING_LENGTH = buffer . constants . MAX_STRING_LENGTH
44
43
const kProductCheck = Symbol ( 'product check' )
45
44
const kApiVersioning = Symbol ( 'api versioning' )
45
+ const kEventEmitter = Symbol ( 'event emitter' )
46
46
47
47
class Transport {
48
48
constructor ( opts ) {
@@ -71,6 +71,7 @@ class Transport {
71
71
this . opaqueIdPrefix = opts . opaqueIdPrefix
72
72
this [ kProductCheck ] = 0 // 0 = to be checked, 1 = checking, 2 = checked-ok, 3 checked-notok, 4 checked-nodefault
73
73
this [ kApiVersioning ] = process . env . ELASTIC_CLIENT_APIVERSIONING === 'true'
74
+ this [ kEventEmitter ] = new EventEmitter ( )
74
75
75
76
this . nodeFilter = opts . nodeFilter || defaultNodeFilter
76
77
if ( typeof opts . nodeSelector === 'function' ) {
@@ -460,7 +461,7 @@ class Transport {
460
461
prepareRequest ( )
461
462
} else {
462
463
// wait for product check to finish
463
- productCheckEmitter . once ( 'product-check' , ( error , status ) => {
464
+ this [ kEventEmitter ] . once ( 'product-check' , ( error , status ) => {
464
465
if ( status === false ) {
465
466
const err = error || new ProductNotSupportedError ( result )
466
467
if ( this [ kProductCheck ] === 4 ) {
@@ -564,48 +565,48 @@ class Transport {
564
565
'The client is unable to verify that the server is Elasticsearch due to security privileges on the server side. Some functionality may not be compatible if the server is running an unsupported product.' ,
565
566
'ProductNotSupportedSecurityError'
566
567
)
567
- productCheckEmitter . emit ( 'product-check' , null , true )
568
+ this [ kEventEmitter ] . emit ( 'product-check' , null , true )
568
569
} else {
569
570
this [ kProductCheck ] = 0
570
- productCheckEmitter . emit ( 'product-check' , err , false )
571
+ this [ kEventEmitter ] . emit ( 'product-check' , err , false )
571
572
}
572
573
} else {
573
574
debug ( 'Checking elasticsearch version' , result . body , result . headers )
574
575
if ( result . body . version == null || typeof result . body . version . number !== 'string' ) {
575
576
debug ( 'Can\'t access Elasticsearch version' )
576
- return productCheckEmitter . emit ( 'product-check' , null , false )
577
+ return this [ kEventEmitter ] . emit ( 'product-check' , null , false )
577
578
}
578
579
const tagline = result . body . tagline
579
580
const version = result . body . version . number . split ( '.' )
580
581
const major = Number ( version [ 0 ] )
581
582
const minor = Number ( version [ 1 ] )
582
583
if ( major < 6 ) {
583
- return productCheckEmitter . emit ( 'product-check' , null , false )
584
+ return this [ kEventEmitter ] . emit ( 'product-check' , null , false )
584
585
} else if ( major >= 6 && major < 7 ) {
585
586
if ( tagline !== 'You Know, for Search' ) {
586
587
debug ( 'Bad tagline' )
587
- return productCheckEmitter . emit ( 'product-check' , null , false )
588
+ return this [ kEventEmitter ] . emit ( 'product-check' , null , false )
588
589
}
589
590
} else if ( major === 7 && minor < 14 ) {
590
591
if ( tagline !== 'You Know, for Search' ) {
591
592
debug ( 'Bad tagline' )
592
- return productCheckEmitter . emit ( 'product-check' , null , false )
593
+ return this [ kEventEmitter ] . emit ( 'product-check' , null , false )
593
594
}
594
595
595
596
if ( result . body . version . build_flavor !== 'default' ) {
596
597
debug ( 'Bad build_flavor' )
597
598
this [ kProductCheck ] = 4
598
- return productCheckEmitter . emit ( 'product-check' , null , false )
599
+ return this [ kEventEmitter ] . emit ( 'product-check' , null , false )
599
600
}
600
601
} else {
601
602
if ( result . headers [ 'x-elastic-product' ] !== 'Elasticsearch' ) {
602
603
debug ( 'x-elastic-product not recognized' )
603
- return productCheckEmitter . emit ( 'product-check' , null , false )
604
+ return this [ kEventEmitter ] . emit ( 'product-check' , null , false )
604
605
}
605
606
}
606
607
debug ( 'Valid Elasticsearch distribution' )
607
608
this [ kProductCheck ] = 2
608
- productCheckEmitter . emit ( 'product-check' , null , true )
609
+ this [ kEventEmitter ] . emit ( 'product-check' , null , true )
609
610
}
610
611
} )
611
612
}
0 commit comments