@@ -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' ) {
@@ -455,7 +456,7 @@ class Transport {
455
456
prepareRequest ( )
456
457
} else {
457
458
// wait for product check to finish
458
- productCheckEmitter . once ( 'product-check' , ( error , status ) => {
459
+ this [ kEventEmitter ] . once ( 'product-check' , ( error , status ) => {
459
460
if ( status === false ) {
460
461
const err = error || new ProductNotSupportedError ( result )
461
462
if ( this [ kProductCheck ] === 4 ) {
@@ -556,48 +557,48 @@ class Transport {
556
557
if ( err . statusCode === 401 || err . statusCode === 403 ) {
557
558
this [ kProductCheck ] = 2
558
559
process . emitWarning ( '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.' )
559
- productCheckEmitter . emit ( 'product-check' , null , true )
560
+ this [ kEventEmitter ] . emit ( 'product-check' , null , true )
560
561
} else {
561
562
this [ kProductCheck ] = 0
562
- productCheckEmitter . emit ( 'product-check' , err , false )
563
+ this [ kEventEmitter ] . emit ( 'product-check' , err , false )
563
564
}
564
565
} else {
565
566
debug ( 'Checking elasticsearch version' , result . body , result . headers )
566
567
if ( result . body . version == null || typeof result . body . version . number !== 'string' ) {
567
568
debug ( 'Can\'t access Elasticsearch version' )
568
- return productCheckEmitter . emit ( 'product-check' , null , false )
569
+ return this [ kEventEmitter ] . emit ( 'product-check' , null , false )
569
570
}
570
571
const tagline = result . body . tagline
571
572
const version = result . body . version . number . split ( '.' )
572
573
const major = Number ( version [ 0 ] )
573
574
const minor = Number ( version [ 1 ] )
574
575
if ( major < 6 ) {
575
- return productCheckEmitter . emit ( 'product-check' , null , false )
576
+ return this [ kEventEmitter ] . emit ( 'product-check' , null , false )
576
577
} else if ( major >= 6 && major < 7 ) {
577
578
if ( tagline !== 'You Know, for Search' ) {
578
579
debug ( 'Bad tagline' )
579
- return productCheckEmitter . emit ( 'product-check' , null , false )
580
+ return this [ kEventEmitter ] . emit ( 'product-check' , null , false )
580
581
}
581
582
} else if ( major === 7 && minor < 14 ) {
582
583
if ( tagline !== 'You Know, for Search' ) {
583
584
debug ( 'Bad tagline' )
584
- return productCheckEmitter . emit ( 'product-check' , null , false )
585
+ return this [ kEventEmitter ] . emit ( 'product-check' , null , false )
585
586
}
586
587
587
588
if ( result . body . version . build_flavor !== 'default' ) {
588
589
debug ( 'Bad build_flavor' )
589
590
this [ kProductCheck ] = 4
590
- return productCheckEmitter . emit ( 'product-check' , null , false )
591
+ return this [ kEventEmitter ] . emit ( 'product-check' , null , false )
591
592
}
592
593
} else {
593
594
if ( result . headers [ 'x-elastic-product' ] !== 'Elasticsearch' ) {
594
595
debug ( 'x-elastic-product not recognized' )
595
- return productCheckEmitter . emit ( 'product-check' , null , false )
596
+ return this [ kEventEmitter ] . emit ( 'product-check' , null , false )
596
597
}
597
598
}
598
599
debug ( 'Valid Elasticsearch distribution' )
599
600
this [ kProductCheck ] = 2
600
- productCheckEmitter . emit ( 'product-check' , null , true )
601
+ this [ kEventEmitter ] . emit ( 'product-check' , null , true )
601
602
}
602
603
} )
603
604
}
0 commit comments