diff --git a/index.d.ts b/index.d.ts index c020b5c12..d645fd9f3 100644 --- a/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ /// 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; @@ -327,5 +342,6 @@ export { ResurrectEvent, RequestParams, ClientOptions, + NodeOptions, ClientExtendsCallbackOptions }; diff --git a/lib/Connection.d.ts b/lib/Connection.d.ts index 0c49207af..f2ab8532a 100644 --- a/lib/Connection.d.ts +++ b/lib/Connection.d.ts @@ -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; diff --git a/test/types/index.ts b/test/types/index.ts index 6f97182d4..2aa0526e9 100644 --- a/test/types/index.ts +++ b/test/types/index.ts @@ -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