Added toJSON method to Connection class (#849)
* Added toJSON method to Connection class * Updated test * Updated typings
This commit is contained in:
committed by
delvedor
parent
3e9ae8b29c
commit
96a103b305
1
lib/Connection.d.ts
vendored
1
lib/Connection.d.ts
vendored
@ -78,6 +78,7 @@ export default class Connection {
|
||||
buildRequestObject(params: any): http.ClientRequestArgs;
|
||||
// @ts-ignore
|
||||
[inspect.custom](object: any, options: InspectOptions): string;
|
||||
toJSON(): any;
|
||||
}
|
||||
|
||||
export {};
|
||||
|
||||
@ -239,6 +239,19 @@ class Connection {
|
||||
roles: this.roles
|
||||
}
|
||||
}
|
||||
|
||||
toJSON () {
|
||||
return {
|
||||
url: this.url,
|
||||
id: this.id,
|
||||
headers: this.headers,
|
||||
deadCount: this.deadCount,
|
||||
resurrectTimeout: this.resurrectTimeout,
|
||||
_openRequests: this._openRequests,
|
||||
status: this.status,
|
||||
roles: this.roles
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Connection.statuses = {
|
||||
|
||||
@ -794,3 +794,16 @@ test('Port handling', t => {
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('Should not add agent and ssl to the serialized connection', t => {
|
||||
const connection = new Connection({
|
||||
url: new URL('http://localhost:9200')
|
||||
})
|
||||
|
||||
t.strictEqual(
|
||||
JSON.stringify(connection),
|
||||
'{"url":"http://localhost:9200/","id":"http://localhost:9200/","headers":null,"deadCount":0,"resurrectTimeout":0,"_openRequests":0,"status":"alive","roles":{"master":true,"data":true,"ingest":true,"ml":false}}'
|
||||
)
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user