Updated type definitions (#882)

* Updated type definitions

* Updated test
This commit is contained in:
Tomas Della Vedova
2019-06-19 09:14:19 +02:00
committed by delvedor
parent 87fb0a2996
commit bef1604a8d
3 changed files with 39 additions and 7 deletions

22
index.d.ts vendored
View File

@ -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
View File

@ -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;

View File

@ -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