@opensearch-project/opensearch 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dockerignore +5 -0
- package/ADMINS.md +34 -0
- package/DEVELOPER_GUIDE.md +60 -0
- package/LICENSE.txt +201 -0
- package/MAINTAINERS.md +73 -0
- package/Makefile +27 -0
- package/NOTICE.txt +8 -0
- package/README.md +183 -0
- package/RELEASING.md +34 -0
- package/SECURITY.md +3 -0
- package/api/api/bulk.js +81 -0
- package/api/api/cat.js +525 -0
- package/api/api/clear_scroll.js +66 -0
- package/api/api/cluster.js +431 -0
- package/api/api/count.js +75 -0
- package/api/api/create.js +80 -0
- package/api/api/dangling_indices.js +126 -0
- package/api/api/delete.js +76 -0
- package/api/api/delete_by_query.js +82 -0
- package/api/api/delete_by_query_rethrottle.js +71 -0
- package/api/api/delete_script.js +67 -0
- package/api/api/exists.js +76 -0
- package/api/api/exists_source.js +85 -0
- package/api/api/explain.js +76 -0
- package/api/api/features.js +92 -0
- package/api/api/field_caps.js +66 -0
- package/api/api/get.js +76 -0
- package/api/api/get_script.js +67 -0
- package/api/api/get_script_context.js +61 -0
- package/api/api/get_script_languages.js +61 -0
- package/api/api/get_source.js +76 -0
- package/api/api/index.js +82 -0
- package/api/api/indices.js +1516 -0
- package/api/api/info.js +61 -0
- package/api/api/ingest.js +211 -0
- package/api/api/mget.js +81 -0
- package/api/api/msearch.js +81 -0
- package/api/api/msearch_template.js +81 -0
- package/api/api/mtermvectors.js +75 -0
- package/api/api/nodes.js +279 -0
- package/api/api/ping.js +61 -0
- package/api/api/put_script.js +82 -0
- package/api/api/rank_eval.js +72 -0
- package/api/api/reindex.js +67 -0
- package/api/api/reindex_rethrottle.js +71 -0
- package/api/api/render_search_template.js +66 -0
- package/api/api/scripts_painless_execute.js +61 -0
- package/api/api/scroll.js +66 -0
- package/api/api/search.js +75 -0
- package/api/api/search_shards.js +66 -0
- package/api/api/search_template.js +81 -0
- package/api/api/shutdown.js +135 -0
- package/api/api/snapshot.js +450 -0
- package/api/api/tasks.js +119 -0
- package/api/api/terms_enum.js +67 -0
- package/api/api/termvectors.js +78 -0
- package/api/api/update.js +80 -0
- package/api/api/update_by_query.js +78 -0
- package/api/api/update_by_query_rethrottle.js +71 -0
- package/api/index.js +254 -0
- package/api/new.d.ts +716 -0
- package/api/requestParams.d.ts +1583 -0
- package/api/types.d.ts +9481 -0
- package/api/utils.js +69 -0
- package/codecov.yml +14 -0
- package/index.d.ts +1210 -0
- package/index.js +338 -0
- package/index.mjs +40 -0
- package/lib/Connection.d.ts +107 -0
- package/lib/Connection.js +345 -0
- package/lib/Helpers.d.ts +135 -0
- package/lib/Helpers.js +779 -0
- package/lib/Serializer.d.ts +41 -0
- package/lib/Serializer.js +105 -0
- package/lib/Transport.d.ts +173 -0
- package/lib/Transport.js +646 -0
- package/lib/errors.d.ts +101 -0
- package/lib/errors.js +168 -0
- package/lib/pool/BaseConnectionPool.js +269 -0
- package/lib/pool/CloudConnectionPool.js +75 -0
- package/lib/pool/ConnectionPool.js +257 -0
- package/lib/pool/index.d.ts +215 -0
- package/lib/pool/index.js +41 -0
- package/package.json +102 -0
package/index.js
ADDED
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* The OpenSearch Contributors require contributions made to
|
|
5
|
+
* this file be licensed under the Apache-2.0 license or a
|
|
6
|
+
* compatible open source license.
|
|
7
|
+
*
|
|
8
|
+
* Modifications Copyright OpenSearch Contributors. See
|
|
9
|
+
* GitHub history for details.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
* Licensed to Elasticsearch B.V. under one or more contributor
|
|
14
|
+
* license agreements. See the NOTICE file distributed with
|
|
15
|
+
* this work for additional information regarding copyright
|
|
16
|
+
* ownership. Elasticsearch B.V. licenses this file to you under
|
|
17
|
+
* the Apache License, Version 2.0 (the "License"); you may
|
|
18
|
+
* not use this file except in compliance with the License.
|
|
19
|
+
* You may obtain a copy of the License at
|
|
20
|
+
*
|
|
21
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
22
|
+
*
|
|
23
|
+
* Unless required by applicable law or agreed to in writing,
|
|
24
|
+
* software distributed under the License is distributed on an
|
|
25
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
26
|
+
* KIND, either express or implied. See the License for the
|
|
27
|
+
* specific language governing permissions and limitations
|
|
28
|
+
* under the License.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
'use strict'
|
|
32
|
+
|
|
33
|
+
const { EventEmitter } = require('events')
|
|
34
|
+
const { URL } = require('url')
|
|
35
|
+
const debug = require('debug')('opensearch')
|
|
36
|
+
const Transport = require('./lib/Transport')
|
|
37
|
+
const Connection = require('./lib/Connection')
|
|
38
|
+
const { ConnectionPool, CloudConnectionPool } = require('./lib/pool')
|
|
39
|
+
const Helpers = require('./lib/Helpers')
|
|
40
|
+
const Serializer = require('./lib/Serializer')
|
|
41
|
+
const errors = require('./lib/errors')
|
|
42
|
+
const { ConfigurationError } = errors
|
|
43
|
+
const { prepareHeaders } = Connection.internals
|
|
44
|
+
let clientVersion = require('./package.json').version
|
|
45
|
+
/* istanbul ignore next */
|
|
46
|
+
if (clientVersion.includes('-')) {
|
|
47
|
+
// clean prerelease
|
|
48
|
+
clientVersion = clientVersion.slice(0, clientVersion.indexOf('-')) + 'p'
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const kInitialOptions = Symbol('opensearchjs-initial-options')
|
|
52
|
+
const kChild = Symbol('opensearchjs-child')
|
|
53
|
+
const kExtensions = Symbol('opensearchjs-extensions')
|
|
54
|
+
const kEventEmitter = Symbol('opensearchjs-event-emitter')
|
|
55
|
+
|
|
56
|
+
const OpenSearchAPI = require('./api')
|
|
57
|
+
|
|
58
|
+
class Client extends OpenSearchAPI {
|
|
59
|
+
constructor (opts = {}) {
|
|
60
|
+
super({ ConfigurationError })
|
|
61
|
+
if (opts.cloud && opts[kChild] === undefined) {
|
|
62
|
+
const { id, username, password } = opts.cloud
|
|
63
|
+
// the cloud id is `cluster-name:base64encodedurl`
|
|
64
|
+
// the url is a string divided by two '$', the first is the cloud url
|
|
65
|
+
// the second the opensearch instance, the third the opensearchDashboards instance
|
|
66
|
+
const cloudUrls = Buffer.from(id.split(':')[1], 'base64').toString().split('$')
|
|
67
|
+
|
|
68
|
+
// TODO: remove username and password here in 8
|
|
69
|
+
if (username && password) {
|
|
70
|
+
opts.auth = Object.assign({}, opts.auth, { username, password })
|
|
71
|
+
}
|
|
72
|
+
opts.node = `https://${cloudUrls[1]}.${cloudUrls[0]}`
|
|
73
|
+
|
|
74
|
+
// Cloud has better performances with compression enabled
|
|
75
|
+
// see https://github.com/elastic/elasticsearch-py/pull/704.
|
|
76
|
+
// So unless the user specifies otherwise, we enable compression.
|
|
77
|
+
if (opts.compression == null) opts.compression = 'gzip'
|
|
78
|
+
if (opts.suggestCompression == null) opts.suggestCompression = true
|
|
79
|
+
if (opts.ssl == null ||
|
|
80
|
+
(opts.ssl && opts.ssl.secureProtocol == null)) {
|
|
81
|
+
opts.ssl = opts.ssl || {}
|
|
82
|
+
opts.ssl.secureProtocol = 'TLSv1_2_method'
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (!opts.node && !opts.nodes) {
|
|
87
|
+
throw new ConfigurationError('Missing node(s) option')
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (opts[kChild] === undefined) {
|
|
91
|
+
const checkAuth = getAuth(opts.node || opts.nodes)
|
|
92
|
+
if (checkAuth && checkAuth.username && checkAuth.password) {
|
|
93
|
+
opts.auth = Object.assign({}, opts.auth, { username: checkAuth.username, password: checkAuth.password })
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const options = opts[kChild] !== undefined
|
|
98
|
+
? opts[kChild].initialOptions
|
|
99
|
+
: Object.assign({}, {
|
|
100
|
+
Connection,
|
|
101
|
+
Transport,
|
|
102
|
+
Serializer,
|
|
103
|
+
ConnectionPool: opts.cloud ? CloudConnectionPool : ConnectionPool,
|
|
104
|
+
maxRetries: 3,
|
|
105
|
+
requestTimeout: 30000,
|
|
106
|
+
pingTimeout: 3000,
|
|
107
|
+
sniffInterval: false,
|
|
108
|
+
sniffOnStart: false,
|
|
109
|
+
sniffEndpoint: '_nodes/_all/http',
|
|
110
|
+
sniffOnConnectionFault: false,
|
|
111
|
+
resurrectStrategy: 'ping',
|
|
112
|
+
suggestCompression: false,
|
|
113
|
+
compression: false,
|
|
114
|
+
ssl: null,
|
|
115
|
+
agent: null,
|
|
116
|
+
headers: {},
|
|
117
|
+
nodeFilter: null,
|
|
118
|
+
nodeSelector: 'round-robin',
|
|
119
|
+
generateRequestId: null,
|
|
120
|
+
name: 'opensearch-js',
|
|
121
|
+
auth: null,
|
|
122
|
+
opaqueIdPrefix: null,
|
|
123
|
+
context: null,
|
|
124
|
+
proxy: null,
|
|
125
|
+
enableMetaHeader: true,
|
|
126
|
+
disablePrototypePoisoningProtection: false
|
|
127
|
+
}, opts)
|
|
128
|
+
|
|
129
|
+
if (process.env.OPENSEARCH_CLIENT_APIVERSIONING === 'true') {
|
|
130
|
+
options.headers = Object.assign({ accept: 'application/vnd.opensearch+json; compatible-with=7' }, options.headers)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
this[kInitialOptions] = options
|
|
134
|
+
this[kExtensions] = []
|
|
135
|
+
this.name = options.name
|
|
136
|
+
|
|
137
|
+
if (opts[kChild] !== undefined) {
|
|
138
|
+
this.serializer = options[kChild].serializer
|
|
139
|
+
this.connectionPool = options[kChild].connectionPool
|
|
140
|
+
this[kEventEmitter] = options[kChild].eventEmitter
|
|
141
|
+
} else {
|
|
142
|
+
this[kEventEmitter] = new EventEmitter()
|
|
143
|
+
this.serializer = new options.Serializer({
|
|
144
|
+
disablePrototypePoisoningProtection: options.disablePrototypePoisoningProtection
|
|
145
|
+
})
|
|
146
|
+
this.connectionPool = new options.ConnectionPool({
|
|
147
|
+
pingTimeout: options.pingTimeout,
|
|
148
|
+
resurrectStrategy: options.resurrectStrategy,
|
|
149
|
+
ssl: options.ssl,
|
|
150
|
+
agent: options.agent,
|
|
151
|
+
proxy: options.proxy,
|
|
152
|
+
Connection: options.Connection,
|
|
153
|
+
auth: options.auth,
|
|
154
|
+
emit: this[kEventEmitter].emit.bind(this[kEventEmitter]),
|
|
155
|
+
sniffEnabled: options.sniffInterval !== false ||
|
|
156
|
+
options.sniffOnStart !== false ||
|
|
157
|
+
options.sniffOnConnectionFault !== false
|
|
158
|
+
})
|
|
159
|
+
// Add the connections before initialize the Transport
|
|
160
|
+
this.connectionPool.addConnection(options.node || options.nodes)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
this.transport = new options.Transport({
|
|
164
|
+
emit: this[kEventEmitter].emit.bind(this[kEventEmitter]),
|
|
165
|
+
connectionPool: this.connectionPool,
|
|
166
|
+
serializer: this.serializer,
|
|
167
|
+
maxRetries: options.maxRetries,
|
|
168
|
+
requestTimeout: options.requestTimeout,
|
|
169
|
+
sniffInterval: options.sniffInterval,
|
|
170
|
+
sniffOnStart: options.sniffOnStart,
|
|
171
|
+
sniffOnConnectionFault: options.sniffOnConnectionFault,
|
|
172
|
+
sniffEndpoint: options.sniffEndpoint,
|
|
173
|
+
suggestCompression: options.suggestCompression,
|
|
174
|
+
compression: options.compression,
|
|
175
|
+
headers: options.headers,
|
|
176
|
+
nodeFilter: options.nodeFilter,
|
|
177
|
+
nodeSelector: options.nodeSelector,
|
|
178
|
+
generateRequestId: options.generateRequestId,
|
|
179
|
+
name: options.name,
|
|
180
|
+
opaqueIdPrefix: options.opaqueIdPrefix,
|
|
181
|
+
context: options.context
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
this.helpers = new Helpers({
|
|
185
|
+
client: this,
|
|
186
|
+
maxRetries: options.maxRetries
|
|
187
|
+
})
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
get emit () {
|
|
191
|
+
return this[kEventEmitter].emit.bind(this[kEventEmitter])
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
get on () {
|
|
195
|
+
return this[kEventEmitter].on.bind(this[kEventEmitter])
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
get once () {
|
|
199
|
+
return this[kEventEmitter].once.bind(this[kEventEmitter])
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
get off () {
|
|
203
|
+
return this[kEventEmitter].off.bind(this[kEventEmitter])
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
extend (name, opts, fn) {
|
|
207
|
+
if (typeof opts === 'function') {
|
|
208
|
+
fn = opts
|
|
209
|
+
opts = {}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
let [namespace, method] = name.split('.')
|
|
213
|
+
if (method == null) {
|
|
214
|
+
method = namespace
|
|
215
|
+
namespace = null
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (namespace != null) {
|
|
219
|
+
if (this[namespace] != null && this[namespace][method] != null && opts.force !== true) {
|
|
220
|
+
throw new Error(`The method "${method}" already exists on namespace "${namespace}"`)
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (this[namespace] == null) this[namespace] = {}
|
|
224
|
+
this[namespace][method] = fn({
|
|
225
|
+
makeRequest: this.transport.request.bind(this.transport),
|
|
226
|
+
result: { body: null, statusCode: null, headers: null, warnings: null },
|
|
227
|
+
ConfigurationError
|
|
228
|
+
})
|
|
229
|
+
} else {
|
|
230
|
+
if (this[method] != null && opts.force !== true) {
|
|
231
|
+
throw new Error(`The method "${method}" already exists`)
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
this[method] = fn({
|
|
235
|
+
makeRequest: this.transport.request.bind(this.transport),
|
|
236
|
+
result: { body: null, statusCode: null, headers: null, warnings: null },
|
|
237
|
+
ConfigurationError
|
|
238
|
+
})
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
this[kExtensions].push({ name, opts, fn })
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
child (opts) {
|
|
245
|
+
// Merge the new options with the initial ones
|
|
246
|
+
const options = Object.assign({}, this[kInitialOptions], opts)
|
|
247
|
+
// Pass to the child client the parent instances that cannot be overriden
|
|
248
|
+
options[kChild] = {
|
|
249
|
+
connectionPool: this.connectionPool,
|
|
250
|
+
serializer: this.serializer,
|
|
251
|
+
eventEmitter: this[kEventEmitter],
|
|
252
|
+
initialOptions: options
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/* istanbul ignore else */
|
|
256
|
+
if (options.auth !== undefined) {
|
|
257
|
+
options.headers = prepareHeaders(options.headers, options.auth)
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const client = new Client(options)
|
|
261
|
+
// sync compatible check
|
|
262
|
+
const tSymbol = Object.getOwnPropertySymbols(this.transport)
|
|
263
|
+
.filter(symbol => symbol.description === 'compatible check')[0]
|
|
264
|
+
client.transport[tSymbol] = this.transport[tSymbol]
|
|
265
|
+
// Add parent extensions
|
|
266
|
+
if (this[kExtensions].length > 0) {
|
|
267
|
+
this[kExtensions].forEach(({ name, opts, fn }) => {
|
|
268
|
+
client.extend(name, opts, fn)
|
|
269
|
+
})
|
|
270
|
+
}
|
|
271
|
+
return client
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
close (callback) {
|
|
275
|
+
if (callback == null) {
|
|
276
|
+
return new Promise((resolve, reject) => {
|
|
277
|
+
this.close(resolve)
|
|
278
|
+
})
|
|
279
|
+
}
|
|
280
|
+
debug('Closing the client')
|
|
281
|
+
this.connectionPool.empty(callback)
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function getAuth (node) {
|
|
286
|
+
if (Array.isArray(node)) {
|
|
287
|
+
for (const url of node) {
|
|
288
|
+
const auth = getUsernameAndPassword(url)
|
|
289
|
+
if (auth.username !== '' && auth.password !== '') {
|
|
290
|
+
return auth
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
return null
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const auth = getUsernameAndPassword(node)
|
|
298
|
+
if (auth.username !== '' && auth.password !== '') {
|
|
299
|
+
return auth
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
return null
|
|
303
|
+
|
|
304
|
+
function getUsernameAndPassword (node) {
|
|
305
|
+
/* istanbul ignore else */
|
|
306
|
+
if (typeof node === 'string') {
|
|
307
|
+
const { username, password } = new URL(node)
|
|
308
|
+
return {
|
|
309
|
+
username: decodeURIComponent(username),
|
|
310
|
+
password: decodeURIComponent(password)
|
|
311
|
+
}
|
|
312
|
+
} else if (node.url instanceof URL) {
|
|
313
|
+
return {
|
|
314
|
+
username: decodeURIComponent(node.url.username),
|
|
315
|
+
password: decodeURIComponent(node.url.password)
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const events = {
|
|
322
|
+
RESPONSE: 'response',
|
|
323
|
+
REQUEST: 'request',
|
|
324
|
+
SNIFF: 'sniff',
|
|
325
|
+
RESURRECT: 'resurrect',
|
|
326
|
+
SERIALIZATION: 'serialization',
|
|
327
|
+
DESERIALIZATION: 'deserialization'
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
module.exports = {
|
|
331
|
+
Client,
|
|
332
|
+
Transport,
|
|
333
|
+
ConnectionPool,
|
|
334
|
+
Connection,
|
|
335
|
+
Serializer,
|
|
336
|
+
events,
|
|
337
|
+
errors
|
|
338
|
+
}
|
package/index.mjs
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* The OpenSearch Contributors require contributions made to
|
|
5
|
+
* this file be licensed under the Apache-2.0 license or a
|
|
6
|
+
* compatible open source license.
|
|
7
|
+
*
|
|
8
|
+
* Modifications Copyright OpenSearch Contributors. See
|
|
9
|
+
* GitHub history for details.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
* Licensed to Elasticsearch B.V. under one or more contributor
|
|
14
|
+
* license agreements. See the NOTICE file distributed with
|
|
15
|
+
* this work for additional information regarding copyright
|
|
16
|
+
* ownership. Elasticsearch B.V. licenses this file to you under
|
|
17
|
+
* the Apache License, Version 2.0 (the "License"); you may
|
|
18
|
+
* not use this file except in compliance with the License.
|
|
19
|
+
* You may obtain a copy of the License at
|
|
20
|
+
*
|
|
21
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
22
|
+
*
|
|
23
|
+
* Unless required by applicable law or agreed to in writing,
|
|
24
|
+
* software distributed under the License is distributed on an
|
|
25
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
26
|
+
* KIND, either express or implied. See the License for the
|
|
27
|
+
* specific language governing permissions and limitations
|
|
28
|
+
* under the License.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
import mod from './index.js'
|
|
32
|
+
|
|
33
|
+
export default mod
|
|
34
|
+
export const Client = mod.Client
|
|
35
|
+
export const Transport = mod.Transport
|
|
36
|
+
export const ConnectionPool = mod.ConnectionPool
|
|
37
|
+
export const Connection = mod.Connection
|
|
38
|
+
export const Serializer = mod.Serializer
|
|
39
|
+
export const events = mod.events
|
|
40
|
+
export const errors = mod.errors
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* The OpenSearch Contributors require contributions made to
|
|
5
|
+
* this file be licensed under the Apache-2.0 license or a
|
|
6
|
+
* compatible open source license.
|
|
7
|
+
*
|
|
8
|
+
* Modifications Copyright OpenSearch Contributors. See
|
|
9
|
+
* GitHub history for details.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
* Licensed to Elasticsearch B.V. under one or more contributor
|
|
14
|
+
* license agreements. See the NOTICE file distributed with
|
|
15
|
+
* this work for additional information regarding copyright
|
|
16
|
+
* ownership. Elasticsearch B.V. licenses this file to you under
|
|
17
|
+
* the Apache License, Version 2.0 (the "License"); you may
|
|
18
|
+
* not use this file except in compliance with the License.
|
|
19
|
+
* You may obtain a copy of the License at
|
|
20
|
+
*
|
|
21
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
22
|
+
*
|
|
23
|
+
* Unless required by applicable law or agreed to in writing,
|
|
24
|
+
* software distributed under the License is distributed on an
|
|
25
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
26
|
+
* KIND, either express or implied. See the License for the
|
|
27
|
+
* specific language governing permissions and limitations
|
|
28
|
+
* under the License.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/// <reference types="node" />
|
|
32
|
+
|
|
33
|
+
import { URL } from 'url';
|
|
34
|
+
import { inspect, InspectOptions } from 'util'
|
|
35
|
+
import { Readable as ReadableStream } from 'stream';
|
|
36
|
+
import { BasicAuth } from './pool'
|
|
37
|
+
import * as http from 'http'
|
|
38
|
+
import * as https from 'https'
|
|
39
|
+
import * as hpagent from 'hpagent'
|
|
40
|
+
import { ConnectionOptions as TlsConnectionOptions } from 'tls'
|
|
41
|
+
|
|
42
|
+
export declare type agentFn = (opts: ConnectionOptions) => any;
|
|
43
|
+
|
|
44
|
+
export interface ConnectionOptions {
|
|
45
|
+
url: URL;
|
|
46
|
+
ssl?: TlsConnectionOptions;
|
|
47
|
+
id?: string;
|
|
48
|
+
headers?: Record<string, any>;
|
|
49
|
+
agent?: AgentOptions | agentFn;
|
|
50
|
+
status?: string;
|
|
51
|
+
roles?: ConnectionRoles;
|
|
52
|
+
auth?: BasicAuth;
|
|
53
|
+
proxy?: string | URL;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface ConnectionRoles {
|
|
57
|
+
master?: boolean
|
|
58
|
+
data?: boolean
|
|
59
|
+
ingest?: boolean
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
interface RequestOptions extends http.ClientRequestArgs {
|
|
63
|
+
asStream?: boolean;
|
|
64
|
+
body?: string | Buffer | ReadableStream | null;
|
|
65
|
+
querystring?: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface AgentOptions {
|
|
69
|
+
keepAlive?: boolean;
|
|
70
|
+
keepAliveMsecs?: number;
|
|
71
|
+
maxSockets?: number;
|
|
72
|
+
maxFreeSockets?: number;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export default class Connection {
|
|
76
|
+
static statuses: {
|
|
77
|
+
ALIVE: string;
|
|
78
|
+
DEAD: string;
|
|
79
|
+
};
|
|
80
|
+
static roles: {
|
|
81
|
+
MASTER: string;
|
|
82
|
+
DATA: string;
|
|
83
|
+
INGEST: string;
|
|
84
|
+
};
|
|
85
|
+
url: URL
|
|
86
|
+
ssl: TlsConnectionOptions | null
|
|
87
|
+
id: string
|
|
88
|
+
headers: Record<string, any>
|
|
89
|
+
status: string
|
|
90
|
+
roles: ConnectionRoles
|
|
91
|
+
deadCount: number
|
|
92
|
+
resurrectTimeout: number
|
|
93
|
+
makeRequest: any
|
|
94
|
+
_openRequests: number
|
|
95
|
+
_status: string
|
|
96
|
+
_agent: http.Agent | https.Agent | hpagent.HttpProxyAgent | hpagent.HttpsProxyAgent
|
|
97
|
+
constructor(opts?: ConnectionOptions)
|
|
98
|
+
request(params: RequestOptions, callback: (err: Error | null, response: http.IncomingMessage | null) => void): http.ClientRequest
|
|
99
|
+
close(): Connection
|
|
100
|
+
setRole(role: string, enabled: boolean): Connection
|
|
101
|
+
buildRequestObject(params: any): http.ClientRequestArgs
|
|
102
|
+
// @ts-ignore
|
|
103
|
+
[inspect.custom](object: any, options: InspectOptions): string
|
|
104
|
+
toJSON(): any
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export { };
|