Skip to content

Commit

Permalink
Updated type definitions (#882)
Browse files Browse the repository at this point in the history
* Updated type definitions

* Updated test
  • Loading branch information
delvedor committed Jun 19, 2019
1 parent a4f893d commit 39bbd77
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
22 changes: 19 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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';
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -327,5 +342,6 @@ export {
ResurrectEvent,
RequestParams,
ClientOptions,
NodeOptions,
ClientExtendsCallbackOptions
};
6 changes: 3 additions & 3 deletions lib/Connection.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -59,7 +59,7 @@ export default class Connection {
ML: string;
};
url: URL;
ssl: SecureContextOptions | null;
ssl: TlsConnectionOptions | null;
id: string;
headers: any;
deadCount: number;
Expand Down
18 changes: 17 additions & 1 deletion test/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 39bbd77

Please sign in to comment.