* Updated types generation script * Refactored api method definitions * Updated test - Removed old test code - Added tsd dev dependency - Rewritten test with tsd * Removed unused dependencies * Fixed definition * Updated test * Updated docs * Improved events type definitions * Updated test * Minor fixes in the type definitons * More type test * Improved Transport type definitions * Updated test * Addressed comments * Code generation * Use RequestBody, Response and Context everywhere, also default Context to unknown * Updated test * body -> hasBody * Fixed conflicts * Updated code generation * Improved request body type definition * Updated code generation * Use BodyType for both request and reponses generics - Use extends for defining the RequestBody generic to force the user following the same shape. - BodyType and NDBodyType now accepts a generics to allow injecting more specific types in the future * API generation * Updated test * Updated docs * Use BodyType also in ReponseError * Removed useless client generics * Renamed generics and types - prefixed all generics with a T - BodyType => RequestBody - NDBodyType => RequestNDBody - Added ResponseBody * Updated test * Updated docs * Test ResponseBody as well * Simplify overloads * API generation * Updated test * Updated error types
81 lines
2.0 KiB
TypeScript
81 lines
2.0 KiB
TypeScript
// Licensed to Elasticsearch B.V under one or more agreements.
|
|
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
|
|
// See the LICENSE file in the project root for more information
|
|
|
|
/// <reference types="node" />
|
|
|
|
import { URL } from 'url';
|
|
import { inspect, InspectOptions } from 'util'
|
|
import { Readable as ReadableStream } from 'stream';
|
|
import { ApiKeyAuth, BasicAuth } from './pool'
|
|
import * as http from 'http'
|
|
import { ConnectionOptions as TlsConnectionOptions } from 'tls'
|
|
|
|
export declare type agentFn = () => any;
|
|
|
|
interface ConnectionOptions {
|
|
url: URL;
|
|
ssl?: TlsConnectionOptions;
|
|
id?: string;
|
|
headers?: Record<string, any>;
|
|
agent?: AgentOptions | agentFn;
|
|
status?: string;
|
|
roles?: ConnectionRoles;
|
|
auth?: BasicAuth | ApiKeyAuth;
|
|
}
|
|
|
|
interface ConnectionRoles {
|
|
master?: boolean
|
|
data?: boolean
|
|
ingest?: boolean
|
|
ml?: boolean
|
|
}
|
|
|
|
interface RequestOptions extends http.ClientRequestArgs {
|
|
asStream?: boolean;
|
|
body?: string | Buffer | ReadableStream;
|
|
querystring?: string;
|
|
}
|
|
|
|
export interface AgentOptions {
|
|
keepAlive?: boolean;
|
|
keepAliveMsecs?: number;
|
|
maxSockets?: number;
|
|
maxFreeSockets?: number;
|
|
}
|
|
|
|
export default class Connection {
|
|
static statuses: {
|
|
ALIVE: string;
|
|
DEAD: string;
|
|
};
|
|
static roles: {
|
|
MASTER: string;
|
|
DATA: string;
|
|
INGEST: string;
|
|
ML: string;
|
|
};
|
|
url: URL
|
|
ssl: TlsConnectionOptions | null
|
|
id: string
|
|
headers: Record<string, any>
|
|
status: string
|
|
roles: ConnectionRoles
|
|
deadCount: number
|
|
resurrectTimeout: number
|
|
makeRequest: any
|
|
_openRequests: number
|
|
_status: string
|
|
_agent: http.Agent
|
|
constructor(opts?: ConnectionOptions)
|
|
request(params: RequestOptions, callback: (err: Error | null, response: http.IncomingMessage | null) => void): http.ClientRequest
|
|
close(): Connection
|
|
setRole(role: string, enabled: boolean): Connection
|
|
buildRequestObject(params: any): http.ClientRequestArgs
|
|
// @ts-ignore
|
|
[inspect.custom](object: any, options: InspectOptions): string
|
|
toJSON(): any
|
|
}
|
|
|
|
export {};
|