Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 96a103b

Browse files
committedMay 14, 2019
Added toJSON method to Connection class (#849)
* Added toJSON method to Connection class * Updated test * Updated typings
1 parent 3e9ae8b commit 96a103b

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed
 

‎lib/Connection.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export default class Connection {
7878
buildRequestObject(params: any): http.ClientRequestArgs;
7979
// @ts-ignore
8080
[inspect.custom](object: any, options: InspectOptions): string;
81+
toJSON(): any;
8182
}
8283

8384
export {};

‎lib/Connection.js

+13
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,19 @@ class Connection {
239239
roles: this.roles
240240
}
241241
}
242+
243+
toJSON () {
244+
return {
245+
url: this.url,
246+
id: this.id,
247+
headers: this.headers,
248+
deadCount: this.deadCount,
249+
resurrectTimeout: this.resurrectTimeout,
250+
_openRequests: this._openRequests,
251+
status: this.status,
252+
roles: this.roles
253+
}
254+
}
242255
}
243256

244257
Connection.statuses = {

‎test/unit/connection.test.js

+13
Original file line numberDiff line numberDiff line change
@@ -794,3 +794,16 @@ test('Port handling', t => {
794794

795795
t.end()
796796
})
797+
798+
test('Should not add agent and ssl to the serialized connection', t => {
799+
const connection = new Connection({
800+
url: new URL('http://localhost:9200')
801+
})
802+
803+
t.strictEqual(
804+
JSON.stringify(connection),
805+
'{"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}}'
806+
)
807+
808+
t.end()
809+
})

0 commit comments

Comments
 (0)
Please sign in to comment.