Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 05921b134d | |||
| aadf44bbf2 | |||
| bef1604a8d | |||
| 87fb0a2996 | |||
| 456fc19c94 | |||
| 4c118b9f9a | |||
| dc5c041b07 | |||
| 6774560444 |
@ -1,5 +1,6 @@
|
||||
---
|
||||
ELASTICSEARCH_VERSION:
|
||||
- 6.8.0
|
||||
- 6.7.1
|
||||
|
||||
NODE_JS_VERSION:
|
||||
|
||||
@ -150,6 +150,26 @@ function generateRequestId (params, options) {
|
||||
|`name`
|
||||
|`string` - The name to identify the client instance in the events. +
|
||||
_Default:_ `elasticsearch-js`
|
||||
|
||||
|`headers`
|
||||
|`object` - A set of custom headers to send in every request. +
|
||||
_Default:_ `{}`
|
||||
|
||||
|`cloud`
|
||||
a|`object` - Custom configuration for connecting to https://cloud.elastic.co[Elastic Cloud]. See https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/auth-reference.html[Authentication] for more details. +
|
||||
_Default:_ `null` +
|
||||
_Cloud configuration example:_
|
||||
[source,js]
|
||||
----
|
||||
const client = new Client({
|
||||
cloud: {
|
||||
id: 'name:bG9jYWxob3N0JGFiY2QkZWZnaA==',
|
||||
username: 'elastic',
|
||||
password: 'changeme'
|
||||
}
|
||||
})
|
||||
----
|
||||
|
||||
|===
|
||||
|
||||
=== Advanced configuration
|
||||
|
||||
@ -59,7 +59,7 @@ async function run (): void {
|
||||
client
|
||||
.search(params)
|
||||
.then((result: ApiResponse) => {
|
||||
console.og(result.body.hits.hits)
|
||||
console.log(result.body.hits.hits)
|
||||
})
|
||||
.catch((err: Error) => {
|
||||
console.log(err)
|
||||
|
||||
22
index.d.ts
vendored
22
index.d.ts
vendored
@ -20,7 +20,7 @@
|
||||
/// <reference types="node" />
|
||||
|
||||
import { EventEmitter } from 'events';
|
||||
import { SecureContextOptions } from 'tls';
|
||||
import { ConnectionOptions as TlsConnectionOptions } from 'tls';
|
||||
import Transport, {
|
||||
ApiResponse,
|
||||
RequestEvent,
|
||||
@ -31,6 +31,7 @@ import Transport, {
|
||||
generateRequestIdFn,
|
||||
TransportRequestCallback
|
||||
} from './lib/Transport';
|
||||
import { URL } from 'url';
|
||||
import Connection, { AgentOptions, agentFn } from './lib/Connection';
|
||||
import ConnectionPool, { ResurrectEvent } from './lib/ConnectionPool';
|
||||
import Serializer from './lib/Serializer';
|
||||
@ -72,8 +73,22 @@ interface ClientExtends {
|
||||
}
|
||||
// /Extend API
|
||||
|
||||
interface NodeOptions {
|
||||
url: URL;
|
||||
id?: string;
|
||||
agent?: AgentOptions;
|
||||
ssl?: TlsConnectionOptions;
|
||||
headers?: anyObject;
|
||||
roles?: {
|
||||
master: boolean;
|
||||
data: boolean;
|
||||
ingest: boolean;
|
||||
ml: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
interface ClientOptions {
|
||||
node?: string | string[];
|
||||
node?: string | string[] | NodeOptions | NodeOptions[];
|
||||
nodes?: string | string[];
|
||||
Connection?: typeof Connection;
|
||||
ConnectionPool?: typeof ConnectionPool;
|
||||
@ -89,7 +104,7 @@ interface ClientOptions {
|
||||
resurrectStrategy?: 'ping' | 'optimistic' | 'none';
|
||||
suggestCompression?: boolean;
|
||||
compression?: 'gzip';
|
||||
ssl?: SecureContextOptions;
|
||||
ssl?: TlsConnectionOptions;
|
||||
agent?: AgentOptions | agentFn;
|
||||
nodeFilter?: nodeFilterFn;
|
||||
nodeSelector?: nodeSelectorFn | string;
|
||||
@ -588,5 +603,6 @@ export {
|
||||
ResurrectEvent,
|
||||
RequestParams,
|
||||
ClientOptions,
|
||||
NodeOptions,
|
||||
ClientExtendsCallbackOptions
|
||||
};
|
||||
|
||||
6
lib/Connection.d.ts
vendored
6
lib/Connection.d.ts
vendored
@ -22,13 +22,13 @@
|
||||
import { URL } from 'url';
|
||||
import { inspect, InspectOptions } from 'util';
|
||||
import * as http from 'http';
|
||||
import { SecureContextOptions } from 'tls';
|
||||
import { ConnectionOptions as TlsConnectionOptions } from 'tls';
|
||||
|
||||
export declare type agentFn = () => any;
|
||||
|
||||
interface ConnectionOptions {
|
||||
url: URL;
|
||||
ssl?: SecureContextOptions;
|
||||
ssl?: TlsConnectionOptions;
|
||||
id?: string;
|
||||
headers?: any;
|
||||
agent?: AgentOptions | agentFn;
|
||||
@ -59,7 +59,7 @@ export default class Connection {
|
||||
ML: string;
|
||||
};
|
||||
url: URL;
|
||||
ssl: SecureContextOptions | null;
|
||||
ssl: TlsConnectionOptions | null;
|
||||
id: string;
|
||||
headers: any;
|
||||
deadCount: number;
|
||||
|
||||
@ -231,7 +231,7 @@ class Connection {
|
||||
// access them with `instance.agent` and `instance.ssl`.
|
||||
[inspect.custom] (depth, options) {
|
||||
return {
|
||||
url: this.url,
|
||||
url: stripAuth(this.url.toString()),
|
||||
id: this.id,
|
||||
headers: this.headers,
|
||||
deadCount: this.deadCount,
|
||||
@ -244,7 +244,7 @@ class Connection {
|
||||
|
||||
toJSON () {
|
||||
return {
|
||||
url: this.url,
|
||||
url: stripAuth(this.url.toString()),
|
||||
id: this.id,
|
||||
headers: this.headers,
|
||||
deadCount: this.deadCount,
|
||||
|
||||
@ -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": "6.8.0",
|
||||
"version": "6.8.1",
|
||||
"keywords": [
|
||||
"elasticsearch",
|
||||
"elastic",
|
||||
|
||||
@ -35,12 +35,12 @@ const {
|
||||
} = require('./utils')
|
||||
|
||||
start(minimist(process.argv.slice(2), {
|
||||
string: ['tag']
|
||||
string: ['tag', 'branch']
|
||||
}))
|
||||
|
||||
function start (opts) {
|
||||
const log = ora('Loading Elasticsearch Repository').start()
|
||||
if (semver.valid(opts.tag) === null) {
|
||||
if (opts.branch == null && semver.valid(opts.tag) === null) {
|
||||
log.fail(`Missing or invalid tag: ${opts.tag}`)
|
||||
return
|
||||
}
|
||||
@ -55,7 +55,7 @@ function start (opts) {
|
||||
log.text = 'Cleaning API folder...'
|
||||
rimraf.sync(join(apiOutputFolder, '*.js'))
|
||||
|
||||
cloneAndCheckout({ log, tag: opts.tag }, (err, { apiFolder, xPackFolder }) => {
|
||||
cloneAndCheckout({ log, tag: opts.tag, branch: opts.branch }, (err, { apiFolder, xPackFolder }) => {
|
||||
if (err) {
|
||||
log.fail(err.message)
|
||||
return
|
||||
|
||||
@ -29,7 +29,7 @@ const apiFolder = join(esFolder, 'rest-api-spec', 'src', 'main', 'resources', 'r
|
||||
const xPackFolder = join(esFolder, 'x-pack', 'plugin', 'src', 'test', 'resources', 'rest-api-spec', 'api')
|
||||
|
||||
function cloneAndCheckout (opts, callback) {
|
||||
const { log, tag } = opts
|
||||
const { log, tag, branch } = opts
|
||||
withTag(tag, callback)
|
||||
|
||||
/**
|
||||
@ -57,13 +57,19 @@ function cloneAndCheckout (opts, callback) {
|
||||
|
||||
if (fresh) {
|
||||
clone(checkout)
|
||||
} else if (opts.branch) {
|
||||
checkout(true)
|
||||
} else {
|
||||
checkout()
|
||||
}
|
||||
|
||||
function checkout () {
|
||||
log.text = `Checking out tag '${tag}'`
|
||||
git.checkout(tag, err => {
|
||||
function checkout (alsoPull = false) {
|
||||
if (branch) {
|
||||
log.text = `Checking out branch '${branch}'`
|
||||
} else {
|
||||
log.text = `Checking out tag '${tag}'`
|
||||
}
|
||||
git.checkout(branch || tag, err => {
|
||||
if (err) {
|
||||
if (retry++ > 0) {
|
||||
callback(new Error(`Cannot checkout tag '${tag}'`), { apiFolder, xPackFolder })
|
||||
@ -71,6 +77,9 @@ function cloneAndCheckout (opts, callback) {
|
||||
}
|
||||
return pull(checkout)
|
||||
}
|
||||
if (alsoPull) {
|
||||
return pull(checkout)
|
||||
}
|
||||
callback(null, { apiFolder, xPackFolder })
|
||||
})
|
||||
}
|
||||
|
||||
@ -27,13 +27,29 @@ import {
|
||||
ResurrectEvent,
|
||||
events,
|
||||
errors,
|
||||
ClientExtendsCallbackOptions
|
||||
ClientExtendsCallbackOptions,
|
||||
NodeOptions
|
||||
} from '../../index'
|
||||
|
||||
import { TransportRequestParams, TransportRequestOptions } from '../../lib/Transport'
|
||||
import { URL } from 'url'
|
||||
|
||||
const client = new Client({ node: 'http://localhost:9200' })
|
||||
|
||||
const nodeOpts: NodeOptions = {
|
||||
url: new URL('http://localhost:9200'),
|
||||
id: 'winteriscoming',
|
||||
headers: { 'foo': 'bar' },
|
||||
roles: {
|
||||
master: false,
|
||||
data: true,
|
||||
ingest: false,
|
||||
ml: false
|
||||
}
|
||||
}
|
||||
|
||||
const client2 = new Client({ node: nodeOpts })
|
||||
|
||||
client.on(events.RESPONSE, (err: errors.ElasticsearchClientError | null, request: RequestEvent) => {
|
||||
if (err) console.log(err)
|
||||
const { body, statusCode } = request
|
||||
|
||||
@ -723,11 +723,11 @@ test('setRole', t => {
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('Util.inspect Connection class should hide agent and ssl', t => {
|
||||
test('Util.inspect Connection class should hide agent, ssl and auth', t => {
|
||||
t.plan(1)
|
||||
|
||||
const connection = new Connection({
|
||||
url: new URL('http://localhost:9200'),
|
||||
url: new URL('http://user:password@localhost:9200'),
|
||||
id: 'node-id',
|
||||
headers: { foo: 'bar' }
|
||||
})
|
||||
@ -741,20 +741,7 @@ test('Util.inspect Connection class should hide agent and ssl', t => {
|
||||
.replace(/(\r\n|\n|\r)/gm, '')
|
||||
}
|
||||
|
||||
t.strictEqual(cleanStr(inspect(connection)), cleanStr(`{ url:
|
||||
URL {
|
||||
href: 'http://localhost:9200/',
|
||||
origin: 'http://localhost:9200',
|
||||
protocol: 'http:',
|
||||
username: '',
|
||||
password: '',
|
||||
host: 'localhost:9200',
|
||||
hostname: 'localhost',
|
||||
port: '9200',
|
||||
pathname: '/',
|
||||
search: '',
|
||||
searchParams: URLSearchParams {},
|
||||
hash: '' },
|
||||
t.strictEqual(cleanStr(inspect(connection)), cleanStr(`{ url: 'http://localhost:9200/',
|
||||
id: 'node-id',
|
||||
headers: { foo: 'bar' },
|
||||
deadCount: 0,
|
||||
@ -765,6 +752,34 @@ test('Util.inspect Connection class should hide agent and ssl', t => {
|
||||
)
|
||||
})
|
||||
|
||||
test('connection.toJSON should hide agent, ssl and auth', t => {
|
||||
t.plan(1)
|
||||
|
||||
const connection = new Connection({
|
||||
url: new URL('http://user:password@localhost:9200'),
|
||||
id: 'node-id',
|
||||
headers: { foo: 'bar' }
|
||||
})
|
||||
|
||||
t.deepEqual(connection.toJSON(), {
|
||||
url: 'http://localhost:9200/',
|
||||
id: 'node-id',
|
||||
headers: {
|
||||
foo: 'bar'
|
||||
},
|
||||
deadCount: 0,
|
||||
resurrectTimeout: 0,
|
||||
_openRequests: 0,
|
||||
status: 'alive',
|
||||
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 => {
|
||||
|
||||
Reference in New Issue
Block a user