Skip to content

Commit 39bbd77

Browse files
committed
Updated type definitions (#882)
* Updated type definitions * Updated test
1 parent a4f893d commit 39bbd77

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

index.d.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
/// <reference types="node" />
2121

2222
import { EventEmitter } from 'events';
23-
import { SecureContextOptions } from 'tls';
23+
import { ConnectionOptions as TlsConnectionOptions } from 'tls';
2424
import Transport, {
2525
ApiResponse,
2626
RequestEvent,
@@ -31,6 +31,7 @@ import Transport, {
3131
generateRequestIdFn,
3232
TransportRequestCallback
3333
} from './lib/Transport';
34+
import { URL } from 'url';
3435
import Connection, { AgentOptions, agentFn } from './lib/Connection';
3536
import ConnectionPool, { ResurrectEvent } from './lib/ConnectionPool';
3637
import Serializer from './lib/Serializer';
@@ -72,8 +73,22 @@ interface ClientExtends {
7273
}
7374
// /Extend API
7475

76+
interface NodeOptions {
77+
url: URL;
78+
id?: string;
79+
agent?: AgentOptions;
80+
ssl?: TlsConnectionOptions;
81+
headers?: anyObject;
82+
roles?: {
83+
master: boolean;
84+
data: boolean;
85+
ingest: boolean;
86+
ml: boolean;
87+
}
88+
}
89+
7590
interface ClientOptions {
76-
node?: string | string[];
91+
node?: string | string[] | NodeOptions | NodeOptions[];
7792
nodes?: string | string[];
7893
Connection?: typeof Connection;
7994
ConnectionPool?: typeof ConnectionPool;
@@ -89,7 +104,7 @@ interface ClientOptions {
89104
resurrectStrategy?: 'ping' | 'optimistic' | 'none';
90105
suggestCompression?: boolean;
91106
compression?: 'gzip';
92-
ssl?: SecureContextOptions;
107+
ssl?: TlsConnectionOptions;
93108
agent?: AgentOptions | agentFn;
94109
nodeFilter?: nodeFilterFn;
95110
nodeSelector?: nodeSelectorFn | string;
@@ -327,5 +342,6 @@ export {
327342
ResurrectEvent,
328343
RequestParams,
329344
ClientOptions,
345+
NodeOptions,
330346
ClientExtendsCallbackOptions
331347
};

lib/Connection.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
import { URL } from 'url';
2323
import { inspect, InspectOptions } from 'util';
2424
import * as http from 'http';
25-
import { SecureContextOptions } from 'tls';
25+
import { ConnectionOptions as TlsConnectionOptions } from 'tls';
2626

2727
export declare type agentFn = () => any;
2828

2929
interface ConnectionOptions {
3030
url: URL;
31-
ssl?: SecureContextOptions;
31+
ssl?: TlsConnectionOptions;
3232
id?: string;
3333
headers?: any;
3434
agent?: AgentOptions | agentFn;
@@ -59,7 +59,7 @@ export default class Connection {
5959
ML: string;
6060
};
6161
url: URL;
62-
ssl: SecureContextOptions | null;
62+
ssl: TlsConnectionOptions | null;
6363
id: string;
6464
headers: any;
6565
deadCount: number;

test/types/index.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,29 @@ import {
2727
ResurrectEvent,
2828
events,
2929
errors,
30-
ClientExtendsCallbackOptions
30+
ClientExtendsCallbackOptions,
31+
NodeOptions
3132
} from '../../index'
3233

3334
import { TransportRequestParams, TransportRequestOptions } from '../../lib/Transport'
35+
import { URL } from 'url'
3436

3537
const client = new Client({ node: 'http://localhost:9200' })
3638

39+
const nodeOpts: NodeOptions = {
40+
url: new URL('http://localhost:9200'),
41+
id: 'winteriscoming',
42+
headers: { 'foo': 'bar' },
43+
roles: {
44+
master: false,
45+
data: true,
46+
ingest: false,
47+
ml: false
48+
}
49+
}
50+
51+
const client2 = new Client({ node: nodeOpts })
52+
3753
client.on(events.RESPONSE, (err: errors.ElasticsearchClientError | null, request: RequestEvent) => {
3854
if (err) console.log(err)
3955
const { body, statusCode } = request

0 commit comments

Comments
 (0)