From 436311b74d019785450b08f6e90426fb9cc44129 Mon Sep 17 00:00:00 2001 From: delvedor Date: Tue, 14 May 2019 11:16:36 -0400 Subject: [PATCH 1/3] Added toJSON method to Connection class --- lib/Connection.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/Connection.js b/lib/Connection.js index 9560b40cf..9e8f065ae 100644 --- a/lib/Connection.js +++ b/lib/Connection.js @@ -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 = { From ea1ed8af647a87f8818adbb3fc6cf1a925fed296 Mon Sep 17 00:00:00 2001 From: delvedor Date: Tue, 14 May 2019 11:16:42 -0400 Subject: [PATCH 2/3] Updated test --- test/unit/connection.test.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/unit/connection.test.js b/test/unit/connection.test.js index 4d1040280..cb7fa9a54 100644 --- a/test/unit/connection.test.js +++ b/test/unit/connection.test.js @@ -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() +}) From 74ccc3ab978616963444f294552eaf39cd1fdb81 Mon Sep 17 00:00:00 2001 From: delvedor Date: Tue, 14 May 2019 11:18:45 -0400 Subject: [PATCH 3/3] Updated typings --- lib/Connection.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Connection.d.ts b/lib/Connection.d.ts index a02b6f72a..e66f64660 100644 --- a/lib/Connection.d.ts +++ b/lib/Connection.d.ts @@ -77,6 +77,7 @@ export default class Connection { status: string; buildRequestObject(params: any): http.ClientRequestArgs; [inspect.custom](object: any, options: InspectOptions): string; + toJSON(): any; } export {};