WIP: initial prototype

- Added options parameter in API methods
- Updated typings
This commit is contained in:
delvedor
2018-12-12 16:47:29 +01:00
parent 7c1b58d703
commit b91b1ad1de
4 changed files with 413 additions and 391 deletions

773
index.d.ts vendored
View File

@ -2,7 +2,7 @@
import { EventEmitter } from 'events';
import { SecureContextOptions } from 'tls';
import Transport, { ApiResponse, EventMeta, SniffMeta } from './lib/Transport';
import Transport, { ApiResponse, EventMeta, SniffMeta, RequestOptions } from './lib/Transport';
import Connection, { AgentOptions } from './lib/Connection';
import ConnectionPool, { nodeSelectorFn, nodeFilterFn, ResurrectMeta } from './lib/ConnectionPool';
import Serializer from './lib/Serializer';
@ -11,7 +11,12 @@ declare type anyObject = {
[key: string]: any;
};
declare type callbackFn = (err: Error | null, result: ApiResponse) => void;
declare type apiMethod = (params?: anyObject | callbackFn, callback?: callbackFn) => any;
interface ApiMethod {
(callback?: callbackFn): any;
(params: anyObject, callback?: callbackFn): any;
(params: anyObject, options: RequestOptions, callback?: callbackFn): any;
}
interface ClientOptions {
node?: string | string[];
@ -40,424 +45,424 @@ declare class Client extends EventEmitter {
connectionPool: ConnectionPool;
transport: Transport;
serializer: Serializer
bulk: apiMethod
bulk: ApiMethod
cat: {
aliases: apiMethod
allocation: apiMethod
count: apiMethod
fielddata: apiMethod
health: apiMethod
help: apiMethod
indices: apiMethod
master: apiMethod
nodeattrs: apiMethod
nodes: apiMethod
pending_tasks: apiMethod
pendingTasks: apiMethod
plugins: apiMethod
recovery: apiMethod
repositories: apiMethod
segments: apiMethod
shards: apiMethod
snapshots: apiMethod
tasks: apiMethod
templates: apiMethod
thread_pool: apiMethod
threadPool: apiMethod
aliases: ApiMethod
allocation: ApiMethod
count: ApiMethod
fielddata: ApiMethod
health: ApiMethod
help: ApiMethod
indices: ApiMethod
master: ApiMethod
nodeattrs: ApiMethod
nodes: ApiMethod
pending_tasks: ApiMethod
pendingTasks: ApiMethod
plugins: ApiMethod
recovery: ApiMethod
repositories: ApiMethod
segments: ApiMethod
shards: ApiMethod
snapshots: ApiMethod
tasks: ApiMethod
templates: ApiMethod
thread_pool: ApiMethod
threadPool: ApiMethod
}
ccr: {
delete_auto_follow_pattern: apiMethod
deleteAutoFollowPattern: apiMethod
follow: apiMethod
follow_stats: apiMethod
followStats: apiMethod
get_auto_follow_pattern: apiMethod
getAutoFollowPattern: apiMethod
pause_follow: apiMethod
pauseFollow: apiMethod
put_auto_follow_pattern: apiMethod
putAutoFollowPattern: apiMethod
resume_follow: apiMethod
resumeFollow: apiMethod
stats: apiMethod
unfollow: apiMethod
delete_auto_follow_pattern: ApiMethod
deleteAutoFollowPattern: ApiMethod
follow: ApiMethod
follow_stats: ApiMethod
followStats: ApiMethod
get_auto_follow_pattern: ApiMethod
getAutoFollowPattern: ApiMethod
pause_follow: ApiMethod
pauseFollow: ApiMethod
put_auto_follow_pattern: ApiMethod
putAutoFollowPattern: ApiMethod
resume_follow: ApiMethod
resumeFollow: ApiMethod
stats: ApiMethod
unfollow: ApiMethod
}
clear_scroll: apiMethod
clearScroll: apiMethod
clear_scroll: ApiMethod
clearScroll: ApiMethod
cluster: {
allocation_explain: apiMethod
allocationExplain: apiMethod
get_settings: apiMethod
getSettings: apiMethod
health: apiMethod
pending_tasks: apiMethod
pendingTasks: apiMethod
put_settings: apiMethod
putSettings: apiMethod
remote_info: apiMethod
remoteInfo: apiMethod
reroute: apiMethod
state: apiMethod
stats: apiMethod
allocation_explain: ApiMethod
allocationExplain: ApiMethod
get_settings: ApiMethod
getSettings: ApiMethod
health: ApiMethod
pending_tasks: ApiMethod
pendingTasks: ApiMethod
put_settings: ApiMethod
putSettings: ApiMethod
remote_info: ApiMethod
remoteInfo: ApiMethod
reroute: ApiMethod
state: ApiMethod
stats: ApiMethod
}
count: apiMethod
create: apiMethod
delete: apiMethod
delete_by_query: apiMethod
deleteByQuery: apiMethod
delete_by_query_rethrottle: apiMethod
deleteByQueryRethrottle: apiMethod
delete_script: apiMethod
deleteScript: apiMethod
exists: apiMethod
exists_source: apiMethod
existsSource: apiMethod
explain: apiMethod
field_caps: apiMethod
fieldCaps: apiMethod
get: apiMethod
get_script: apiMethod
getScript: apiMethod
get_source: apiMethod
getSource: apiMethod
index: apiMethod
count: ApiMethod
create: ApiMethod
delete: ApiMethod
delete_by_query: ApiMethod
deleteByQuery: ApiMethod
delete_by_query_rethrottle: ApiMethod
deleteByQueryRethrottle: ApiMethod
delete_script: ApiMethod
deleteScript: ApiMethod
exists: ApiMethod
exists_source: ApiMethod
existsSource: ApiMethod
explain: ApiMethod
field_caps: ApiMethod
fieldCaps: ApiMethod
get: ApiMethod
get_script: ApiMethod
getScript: ApiMethod
get_source: ApiMethod
getSource: ApiMethod
index: ApiMethod
indices: {
analyze: apiMethod
clear_cache: apiMethod
clearCache: apiMethod
close: apiMethod
create: apiMethod
delete: apiMethod
delete_alias: apiMethod
deleteAlias: apiMethod
delete_template: apiMethod
deleteTemplate: apiMethod
exists: apiMethod
exists_alias: apiMethod
existsAlias: apiMethod
exists_template: apiMethod
existsTemplate: apiMethod
exists_type: apiMethod
existsType: apiMethod
flush: apiMethod
flush_synced: apiMethod
flushSynced: apiMethod
forcemerge: apiMethod
get: apiMethod
get_alias: apiMethod
getAlias: apiMethod
get_field_mapping: apiMethod
getFieldMapping: apiMethod
get_mapping: apiMethod
getMapping: apiMethod
get_settings: apiMethod
getSettings: apiMethod
get_template: apiMethod
getTemplate: apiMethod
get_upgrade: apiMethod
getUpgrade: apiMethod
open: apiMethod
put_alias: apiMethod
putAlias: apiMethod
put_mapping: apiMethod
putMapping: apiMethod
put_settings: apiMethod
putSettings: apiMethod
put_template: apiMethod
putTemplate: apiMethod
recovery: apiMethod
refresh: apiMethod
rollover: apiMethod
segments: apiMethod
shard_stores: apiMethod
shardStores: apiMethod
shrink: apiMethod
split: apiMethod
stats: apiMethod
update_aliases: apiMethod
updateAliases: apiMethod
upgrade: apiMethod
validate_query: apiMethod
validateQuery: apiMethod
analyze: ApiMethod
clear_cache: ApiMethod
clearCache: ApiMethod
close: ApiMethod
create: ApiMethod
delete: ApiMethod
delete_alias: ApiMethod
deleteAlias: ApiMethod
delete_template: ApiMethod
deleteTemplate: ApiMethod
exists: ApiMethod
exists_alias: ApiMethod
existsAlias: ApiMethod
exists_template: ApiMethod
existsTemplate: ApiMethod
exists_type: ApiMethod
existsType: ApiMethod
flush: ApiMethod
flush_synced: ApiMethod
flushSynced: ApiMethod
forcemerge: ApiMethod
get: ApiMethod
get_alias: ApiMethod
getAlias: ApiMethod
get_field_mapping: ApiMethod
getFieldMapping: ApiMethod
get_mapping: ApiMethod
getMapping: ApiMethod
get_settings: ApiMethod
getSettings: ApiMethod
get_template: ApiMethod
getTemplate: ApiMethod
get_upgrade: ApiMethod
getUpgrade: ApiMethod
open: ApiMethod
put_alias: ApiMethod
putAlias: ApiMethod
put_mapping: ApiMethod
putMapping: ApiMethod
put_settings: ApiMethod
putSettings: ApiMethod
put_template: ApiMethod
putTemplate: ApiMethod
recovery: ApiMethod
refresh: ApiMethod
rollover: ApiMethod
segments: ApiMethod
shard_stores: ApiMethod
shardStores: ApiMethod
shrink: ApiMethod
split: ApiMethod
stats: ApiMethod
update_aliases: ApiMethod
updateAliases: ApiMethod
upgrade: ApiMethod
validate_query: ApiMethod
validateQuery: ApiMethod
}
info: apiMethod
info: ApiMethod
ingest: {
delete_pipeline: apiMethod
deletePipeline: apiMethod
get_pipeline: apiMethod
getPipeline: apiMethod
processor_grok: apiMethod
processorGrok: apiMethod
put_pipeline: apiMethod
putPipeline: apiMethod
simulate: apiMethod
delete_pipeline: ApiMethod
deletePipeline: ApiMethod
get_pipeline: ApiMethod
getPipeline: ApiMethod
processor_grok: ApiMethod
processorGrok: ApiMethod
put_pipeline: ApiMethod
putPipeline: ApiMethod
simulate: ApiMethod
}
mget: apiMethod
msearch: apiMethod
msearch_template: apiMethod
msearchTemplate: apiMethod
mtermvectors: apiMethod
mget: ApiMethod
msearch: ApiMethod
msearch_template: ApiMethod
msearchTemplate: ApiMethod
mtermvectors: ApiMethod
nodes: {
hot_threads: apiMethod
hotThreads: apiMethod
info: apiMethod
reload_secure_settings: apiMethod
reloadSecureSettings: apiMethod
stats: apiMethod
usage: apiMethod
hot_threads: ApiMethod
hotThreads: ApiMethod
info: ApiMethod
reload_secure_settings: ApiMethod
reloadSecureSettings: ApiMethod
stats: ApiMethod
usage: ApiMethod
}
ping: apiMethod
put_script: apiMethod
putScript: apiMethod
rank_eval: apiMethod
rankEval: apiMethod
reindex: apiMethod
reindex_rethrottle: apiMethod
reindexRethrottle: apiMethod
render_search_template: apiMethod
renderSearchTemplate: apiMethod
scripts_painless_execute: apiMethod
scriptsPainlessExecute: apiMethod
scroll: apiMethod
search: apiMethod
search_shards: apiMethod
searchShards: apiMethod
search_template: apiMethod
searchTemplate: apiMethod
ping: ApiMethod
put_script: ApiMethod
putScript: ApiMethod
rank_eval: ApiMethod
rankEval: ApiMethod
reindex: ApiMethod
reindex_rethrottle: ApiMethod
reindexRethrottle: ApiMethod
render_search_template: ApiMethod
renderSearchTemplate: ApiMethod
scripts_painless_execute: ApiMethod
scriptsPainlessExecute: ApiMethod
scroll: ApiMethod
search: ApiMethod
search_shards: ApiMethod
searchShards: ApiMethod
search_template: ApiMethod
searchTemplate: ApiMethod
snapshot: {
create: apiMethod
create_repository: apiMethod
createRepository: apiMethod
delete: apiMethod
delete_repository: apiMethod
deleteRepository: apiMethod
get: apiMethod
get_repository: apiMethod
getRepository: apiMethod
restore: apiMethod
status: apiMethod
verify_repository: apiMethod
verifyRepository: apiMethod
create: ApiMethod
create_repository: ApiMethod
createRepository: ApiMethod
delete: ApiMethod
delete_repository: ApiMethod
deleteRepository: ApiMethod
get: ApiMethod
get_repository: ApiMethod
getRepository: ApiMethod
restore: ApiMethod
status: ApiMethod
verify_repository: ApiMethod
verifyRepository: ApiMethod
}
tasks: {
cancel: apiMethod
get: apiMethod
list: apiMethod
cancel: ApiMethod
get: ApiMethod
list: ApiMethod
}
termvectors: apiMethod
update: apiMethod
update_by_query: apiMethod
updateByQuery: apiMethod
update_by_query_rethrottle: apiMethod
updateByQueryRethrottle: apiMethod
termvectors: ApiMethod
update: ApiMethod
update_by_query: ApiMethod
updateByQuery: ApiMethod
update_by_query_rethrottle: ApiMethod
updateByQueryRethrottle: ApiMethod
xpack: {
graph: {
explore: apiMethod
explore: ApiMethod
}
info: apiMethod
info: ApiMethod
license: {
delete: apiMethod
get: apiMethod
get_basic_status: apiMethod
getBasicStatus: apiMethod
get_trial_status: apiMethod
getTrialStatus: apiMethod
post: apiMethod
post_start_basic: apiMethod
postStartBasic: apiMethod
post_start_trial: apiMethod
postStartTrial: apiMethod
delete: ApiMethod
get: ApiMethod
get_basic_status: ApiMethod
getBasicStatus: ApiMethod
get_trial_status: ApiMethod
getTrialStatus: ApiMethod
post: ApiMethod
post_start_basic: ApiMethod
postStartBasic: ApiMethod
post_start_trial: ApiMethod
postStartTrial: ApiMethod
}
migration: {
deprecations: apiMethod
get_assistance: apiMethod
getAssistance: apiMethod
upgrade: apiMethod
deprecations: ApiMethod
get_assistance: ApiMethod
getAssistance: ApiMethod
upgrade: ApiMethod
}
ml: {
close_job: apiMethod
closeJob: apiMethod
delete_calendar: apiMethod
deleteCalendar: apiMethod
delete_calendar_event: apiMethod
deleteCalendarEvent: apiMethod
delete_calendar_job: apiMethod
deleteCalendarJob: apiMethod
delete_datafeed: apiMethod
deleteDatafeed: apiMethod
delete_expired_data: apiMethod
deleteExpiredData: apiMethod
delete_filter: apiMethod
deleteFilter: apiMethod
delete_forecast: apiMethod
deleteForecast: apiMethod
delete_job: apiMethod
deleteJob: apiMethod
delete_model_snapshot: apiMethod
deleteModelSnapshot: apiMethod
find_file_structure: apiMethod
findFileStructure: apiMethod
flush_job: apiMethod
flushJob: apiMethod
forecast: apiMethod
get_buckets: apiMethod
getBuckets: apiMethod
get_calendar_events: apiMethod
getCalendarEvents: apiMethod
get_calendars: apiMethod
getCalendars: apiMethod
get_categories: apiMethod
getCategories: apiMethod
get_datafeed_stats: apiMethod
getDatafeedStats: apiMethod
get_datafeeds: apiMethod
getDatafeeds: apiMethod
get_filters: apiMethod
getFilters: apiMethod
get_influencers: apiMethod
getInfluencers: apiMethod
get_job_stats: apiMethod
getJobStats: apiMethod
get_jobs: apiMethod
getJobs: apiMethod
get_model_snapshots: apiMethod
getModelSnapshots: apiMethod
get_overall_buckets: apiMethod
getOverallBuckets: apiMethod
get_records: apiMethod
getRecords: apiMethod
info: apiMethod
open_job: apiMethod
openJob: apiMethod
post_calendar_events: apiMethod
postCalendarEvents: apiMethod
post_data: apiMethod
postData: apiMethod
preview_datafeed: apiMethod
previewDatafeed: apiMethod
put_calendar: apiMethod
putCalendar: apiMethod
put_calendar_job: apiMethod
putCalendarJob: apiMethod
put_datafeed: apiMethod
putDatafeed: apiMethod
put_filter: apiMethod
putFilter: apiMethod
put_job: apiMethod
putJob: apiMethod
revert_model_snapshot: apiMethod
revertModelSnapshot: apiMethod
start_datafeed: apiMethod
startDatafeed: apiMethod
stop_datafeed: apiMethod
stopDatafeed: apiMethod
update_datafeed: apiMethod
updateDatafeed: apiMethod
update_filter: apiMethod
updateFilter: apiMethod
update_job: apiMethod
updateJob: apiMethod
update_model_snapshot: apiMethod
updateModelSnapshot: apiMethod
validate: apiMethod
validate_detector: apiMethod
validateDetector: apiMethod
close_job: ApiMethod
closeJob: ApiMethod
delete_calendar: ApiMethod
deleteCalendar: ApiMethod
delete_calendar_event: ApiMethod
deleteCalendarEvent: ApiMethod
delete_calendar_job: ApiMethod
deleteCalendarJob: ApiMethod
delete_datafeed: ApiMethod
deleteDatafeed: ApiMethod
delete_expired_data: ApiMethod
deleteExpiredData: ApiMethod
delete_filter: ApiMethod
deleteFilter: ApiMethod
delete_forecast: ApiMethod
deleteForecast: ApiMethod
delete_job: ApiMethod
deleteJob: ApiMethod
delete_model_snapshot: ApiMethod
deleteModelSnapshot: ApiMethod
find_file_structure: ApiMethod
findFileStructure: ApiMethod
flush_job: ApiMethod
flushJob: ApiMethod
forecast: ApiMethod
get_buckets: ApiMethod
getBuckets: ApiMethod
get_calendar_events: ApiMethod
getCalendarEvents: ApiMethod
get_calendars: ApiMethod
getCalendars: ApiMethod
get_categories: ApiMethod
getCategories: ApiMethod
get_datafeed_stats: ApiMethod
getDatafeedStats: ApiMethod
get_datafeeds: ApiMethod
getDatafeeds: ApiMethod
get_filters: ApiMethod
getFilters: ApiMethod
get_influencers: ApiMethod
getInfluencers: ApiMethod
get_job_stats: ApiMethod
getJobStats: ApiMethod
get_jobs: ApiMethod
getJobs: ApiMethod
get_model_snapshots: ApiMethod
getModelSnapshots: ApiMethod
get_overall_buckets: ApiMethod
getOverallBuckets: ApiMethod
get_records: ApiMethod
getRecords: ApiMethod
info: ApiMethod
open_job: ApiMethod
openJob: ApiMethod
post_calendar_events: ApiMethod
postCalendarEvents: ApiMethod
post_data: ApiMethod
postData: ApiMethod
preview_datafeed: ApiMethod
previewDatafeed: ApiMethod
put_calendar: ApiMethod
putCalendar: ApiMethod
put_calendar_job: ApiMethod
putCalendarJob: ApiMethod
put_datafeed: ApiMethod
putDatafeed: ApiMethod
put_filter: ApiMethod
putFilter: ApiMethod
put_job: ApiMethod
putJob: ApiMethod
revert_model_snapshot: ApiMethod
revertModelSnapshot: ApiMethod
start_datafeed: ApiMethod
startDatafeed: ApiMethod
stop_datafeed: ApiMethod
stopDatafeed: ApiMethod
update_datafeed: ApiMethod
updateDatafeed: ApiMethod
update_filter: ApiMethod
updateFilter: ApiMethod
update_job: ApiMethod
updateJob: ApiMethod
update_model_snapshot: ApiMethod
updateModelSnapshot: ApiMethod
validate: ApiMethod
validate_detector: ApiMethod
validateDetector: ApiMethod
}
monitoring: {
bulk: apiMethod
bulk: ApiMethod
}
rollup: {
delete_job: apiMethod
deleteJob: apiMethod
get_jobs: apiMethod
getJobs: apiMethod
get_rollup_caps: apiMethod
getRollupCaps: apiMethod
get_rollup_index_caps: apiMethod
getRollupIndexCaps: apiMethod
put_job: apiMethod
putJob: apiMethod
rollup_search: apiMethod
rollupSearch: apiMethod
start_job: apiMethod
startJob: apiMethod
stop_job: apiMethod
stopJob: apiMethod
delete_job: ApiMethod
deleteJob: ApiMethod
get_jobs: ApiMethod
getJobs: ApiMethod
get_rollup_caps: ApiMethod
getRollupCaps: ApiMethod
get_rollup_index_caps: ApiMethod
getRollupIndexCaps: ApiMethod
put_job: ApiMethod
putJob: ApiMethod
rollup_search: ApiMethod
rollupSearch: ApiMethod
start_job: ApiMethod
startJob: ApiMethod
stop_job: ApiMethod
stopJob: ApiMethod
}
security: {
authenticate: apiMethod
change_password: apiMethod
changePassword: apiMethod
clear_cached_realms: apiMethod
clearCachedRealms: apiMethod
clear_cached_roles: apiMethod
clearCachedRoles: apiMethod
delete_privileges: apiMethod
deletePrivileges: apiMethod
delete_role: apiMethod
deleteRole: apiMethod
delete_role_mapping: apiMethod
deleteRoleMapping: apiMethod
delete_user: apiMethod
deleteUser: apiMethod
disable_user: apiMethod
disableUser: apiMethod
enable_user: apiMethod
enableUser: apiMethod
get_privileges: apiMethod
getPrivileges: apiMethod
get_role: apiMethod
getRole: apiMethod
get_role_mapping: apiMethod
getRoleMapping: apiMethod
get_token: apiMethod
getToken: apiMethod
get_user: apiMethod
getUser: apiMethod
get_user_privileges: apiMethod
getUserPrivileges: apiMethod
has_privileges: apiMethod
hasPrivileges: apiMethod
invalidate_token: apiMethod
invalidateToken: apiMethod
put_privileges: apiMethod
putPrivileges: apiMethod
put_role: apiMethod
putRole: apiMethod
put_role_mapping: apiMethod
putRoleMapping: apiMethod
put_user: apiMethod
putUser: apiMethod
authenticate: ApiMethod
change_password: ApiMethod
changePassword: ApiMethod
clear_cached_realms: ApiMethod
clearCachedRealms: ApiMethod
clear_cached_roles: ApiMethod
clearCachedRoles: ApiMethod
delete_privileges: ApiMethod
deletePrivileges: ApiMethod
delete_role: ApiMethod
deleteRole: ApiMethod
delete_role_mapping: ApiMethod
deleteRoleMapping: ApiMethod
delete_user: ApiMethod
deleteUser: ApiMethod
disable_user: ApiMethod
disableUser: ApiMethod
enable_user: ApiMethod
enableUser: ApiMethod
get_privileges: ApiMethod
getPrivileges: ApiMethod
get_role: ApiMethod
getRole: ApiMethod
get_role_mapping: ApiMethod
getRoleMapping: ApiMethod
get_token: ApiMethod
getToken: ApiMethod
get_user: ApiMethod
getUser: ApiMethod
get_user_privileges: ApiMethod
getUserPrivileges: ApiMethod
has_privileges: ApiMethod
hasPrivileges: ApiMethod
invalidate_token: ApiMethod
invalidateToken: ApiMethod
put_privileges: ApiMethod
putPrivileges: ApiMethod
put_role: ApiMethod
putRole: ApiMethod
put_role_mapping: ApiMethod
putRoleMapping: ApiMethod
put_user: ApiMethod
putUser: ApiMethod
}
sql: {
clear_cursor: apiMethod
clearCursor: apiMethod
query: apiMethod
translate: apiMethod
clear_cursor: ApiMethod
clearCursor: ApiMethod
query: ApiMethod
translate: ApiMethod
}
ssl: {
certificates: apiMethod
certificates: ApiMethod
}
usage: apiMethod
usage: ApiMethod
watcher: {
ack_watch: apiMethod
ackWatch: apiMethod
activate_watch: apiMethod
activateWatch: apiMethod
deactivate_watch: apiMethod
deactivateWatch: apiMethod
delete_watch: apiMethod
deleteWatch: apiMethod
execute_watch: apiMethod
executeWatch: apiMethod
get_watch: apiMethod
getWatch: apiMethod
put_watch: apiMethod
putWatch: apiMethod
restart: apiMethod
start: apiMethod
stats: apiMethod
stop: apiMethod
ack_watch: ApiMethod
ackWatch: ApiMethod
activate_watch: ApiMethod
activateWatch: ApiMethod
deactivate_watch: ApiMethod
deactivateWatch: ApiMethod
delete_watch: ApiMethod
deleteWatch: ApiMethod
execute_watch: ApiMethod
executeWatch: ApiMethod
get_watch: ApiMethod
getWatch: ApiMethod
put_watch: ApiMethod
putWatch: ApiMethod
restart: ApiMethod
start: ApiMethod
stats: ApiMethod
stop: ApiMethod
}
}
constructor(opts?: ClientOptions);

6
lib/Connection.d.ts vendored
View File

@ -14,6 +14,10 @@ interface ConnectionOptions {
roles?: any;
}
interface RequestOptions extends http.ClientRequestArgs {
asStream?: boolean;
}
export interface AgentOptions {
keepAlive: boolean;
keepAliveMsecs: number;
@ -46,7 +50,7 @@ export default class Connection {
_status: string;
_agent: http.Agent;
constructor(opts?: ConnectionOptions);
request(params: http.ClientRequestArgs, callback: (err: Error | null, response: http.IncomingMessage | null) => void): http.ClientRequest;
request(params: RequestOptions, callback: (err: Error | null, response: http.IncomingMessage | null) => void): http.ClientRequest;
close(): Connection;
setRole(role: string, enabled: boolean): Connection;
status: string;

9
lib/Transport.d.ts vendored
View File

@ -38,6 +38,13 @@ export interface SniffMeta {
reason: string;
}
export interface RequestOptions {
ignore?: number | number[];
requestTimeout?: number | string;
maxRetries?: number;
asStream?: boolean;
}
export default class Transport {
static sniffReasons: {
SNIFF_ON_START: string;
@ -58,7 +65,7 @@ export default class Transport {
_nextSniff: number;
_isSniffing: boolean;
constructor(opts: TransportOptions);
request(params: any, callback: (err: Error | null, result: ApiResponse) => void): any;
request(params: any, options: RequestOptions, callback: (err: Error | null, result: ApiResponse) => void): any;
getConnection(): Connection | null;
sniff(callback?: (...args: any[]) => void): void;
}

View File

@ -33,8 +33,13 @@ class Transport {
}
}
request (params, callback) {
request (params, options, callback) {
if (typeof options === 'function') {
callback = options
options = {}
}
callback = once(callback)
// TODO: return in the result the metadata
const meta = {
connection: null,
request: null,
@ -48,7 +53,7 @@ class Transport {
headers: null,
warnings: null
}
const maxRetries = params.maxRetries || this.maxRetries
const maxRetries = options.maxRetries || this.maxRetries
var request = { abort: noop }
const makeRequest = () => {
@ -96,11 +101,12 @@ class Transport {
// serializes the querystring
params.querystring = this.serializer.qserialize(params.querystring)
// handles request timeout
params.timeout = toMs(params.requestTimeout || this.requestTimeout)
params.timeout = toMs(options.requestTimeout || this.requestTimeout)
meta.request = params
this.emit('request', null, meta)
if (options.asStream === true) params.asStream = true
// perform the actual http request
return meta.connection.request(params, onResponse)
}
@ -139,7 +145,7 @@ class Transport {
result.warnings = headers['warning'].split(/(?!\B"[^"]*),(?![^"]*"\B)/)
}
if (params.asStream === true) {
if (options.asStream === true) {
result.body = response
meta.response = result
this.emit('response', null, meta)
@ -180,7 +186,7 @@ class Transport {
// we should ignore the statusCode if the user has configured the `ignore` field with
// the statusCode we just got or if the request method is HEAD and the statusCode is 404
const ignoreStatusCode = (Array.isArray(params.ignore) && params.ignore.indexOf(statusCode) > -1) ||
const ignoreStatusCode = (Array.isArray(options.ignore) && options.ignore.indexOf(statusCode) > -1) ||
(isHead === true && statusCode === 404)
if (ignoreStatusCode === false &&