Compare commits

...

6 Commits

Author SHA1 Message Date
f3ff692b76 Bumped v5.6.17 2019-05-14 17:50:44 -04:00
1e8e09f47a Added toJSON method to Connection class (#849)
* Added toJSON method to Connection class

* Updated test

* Updated typings
2019-05-14 12:01:41 -04:00
152e5c85b6 Fix #803 (#846) 2019-05-14 12:01:41 -04:00
e7443e0a33 Fix 843 (#845)
* Fix #843

* Updated test
2019-05-10 10:56:43 +02:00
4c988f318d Bumped v5.6.16 2019-05-09 15:35:23 +02:00
1a5d481482 Fix 841 (#842)
* Added errors to exported members

* Updated test
2019-05-09 14:58:01 +02:00
6 changed files with 73 additions and 11 deletions

1
index.d.ts vendored
View File

@ -321,6 +321,7 @@ export {
Connection,
Serializer,
events,
errors,
ApiResponse,
RequestEvent,
ResurrectEvent,

2
lib/Connection.d.ts vendored
View File

@ -76,7 +76,9 @@ export default class Connection {
setRole(role: string, enabled: boolean): Connection;
status: string;
buildRequestObject(params: any): http.ClientRequestArgs;
// @ts-ignore
[inspect.custom](object: any, options: InspectOptions): string;
toJSON(): any;
}
export {};

View File

@ -191,7 +191,8 @@ class Connection {
path: '',
href: url.href,
origin: url.origin,
port: url.port,
// https://github.com/elastic/elasticsearch-js/issues/843
port: url.port !== '' ? url.port : undefined,
headers: this.headers,
auth: !!url.username === true || !!url.password === true
? `${url.username}:${url.password}`
@ -238,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 = {

View File

@ -4,7 +4,7 @@
"main": "index.js",
"types": "index.d.ts",
"homepage": "http://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/index.html",
"version": "5.6.16-rc.3",
"version": "5.6.17",
"keywords": [
"elasticsearch",
"elastic",

View File

@ -26,6 +26,7 @@ import {
RequestEvent,
ResurrectEvent,
events,
errors,
ClientExtendsCallbackOptions
} from '../../index'
@ -33,23 +34,23 @@ import { TransportRequestParams, TransportRequestOptions } from '../../lib/Trans
const client = new Client({ node: 'http://localhost:9200' })
client.on(events.RESPONSE, (err: Error | null, request: RequestEvent) => {
client.on(events.RESPONSE, (err: errors.ElasticsearchClientError | null, request: RequestEvent) => {
if (err) console.log(err)
const { body, statusCode } = request
const { params } = request.meta.request
console.log(params, body, statusCode)
})
client.on(events.RESURRECT, (err: Error | null, meta: ResurrectEvent) => {})
client.on(events.RESURRECT, (err: errors.ElasticsearchClientError | null, meta: ResurrectEvent) => {})
// Callbacks
client.info((err: Error | null, result: ApiResponse) => {})
client.info((err: errors.ElasticsearchClientError | null, result: ApiResponse) => {})
client.index({
index: 'test',
type: 'test',
id: 'test',
body: { hello: 'world' }
}, (err: Error | null, result: ApiResponse) => {})
}, (err: errors.ElasticsearchClientError | null, result: ApiResponse) => {})
// request options
client.index({
@ -65,12 +66,12 @@ client.index({
querystring: { baz: 'faz' },
compression: 'gzip',
asStream: false
}, (err: Error | null, result: ApiResponse) => {})
}, (err: errors.ElasticsearchClientError | null, result: ApiResponse) => {})
// Promises
client.info()
.then((result: ApiResponse) => {})
.catch((err: Error) => {})
.catch((err: errors.ElasticsearchClientError) => {})
client.index({
index: 'test',
@ -79,7 +80,7 @@ client.index({
body: { hello: 'world' }
})
.then((result: ApiResponse) => {})
.catch((err: Error) => {})
.catch((err: errors.ElasticsearchClientError) => {})
// request options
client.index({
@ -93,7 +94,7 @@ client.index({
requestTimeout: 2000
})
.then((result: ApiResponse) => {})
.catch((err: Error) => {})
.catch((err: errors.ElasticsearchClientError) => {})
// --- Use generics ---
// Define the search parameters
@ -127,7 +128,7 @@ interface Source {
client.search(searchParams)
.then((response: ApiResponse<SearchResponse<Source>>) => console.log(response))
.catch((err: Error) => {})
.catch((err: errors.ElasticsearchClientError) => {})
// extend client
client.extend('namespace.method', (options: ClientExtendsCallbackOptions) => {

View File

@ -763,3 +763,47 @@ test('Util.inspect Connection class should hide agent and ssl', t => {
roles: { master: true, data: true, ingest: true, ml: false } }`)
)
})
// https://github.com/elastic/elasticsearch-js/issues/843
test('Port handling', t => {
t.test('http 80', t => {
const connection = new Connection({
url: new URL('http://localhost:80')
})
t.strictEqual(
connection.buildRequestObject({}).port,
undefined
)
t.end()
})
t.test('https 443', t => {
const connection = new Connection({
url: new URL('https://localhost:443')
})
t.strictEqual(
connection.buildRequestObject({}).port,
undefined
)
t.end()
})
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()
})