@opensearch-project/opensearch 1.1.0 → 2.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/.eslintignore +2 -0
- package/.eslintrc.json +26 -0
- package/.prettierrc.json +5 -0
- package/.whitesource +15 -0
- package/ADMINS.md +18 -11
- package/COMPATIBILITY.md +24 -0
- package/DEVELOPER_GUIDE.md +22 -5
- package/MAINTAINERS.md +23 -18
- package/README.md +100 -101
- package/RELEASING.md +3 -3
- package/SECURITY.md +1 -1
- package/api/api/bulk.js +53 -26
- package/api/api/cat.js +354 -264
- package/api/api/clear_scroll.js +17 -17
- package/api/api/cluster.js +366 -219
- package/api/api/count.js +55 -24
- package/api/api/create.js +50 -24
- package/api/api/dangling_indices.js +95 -51
- package/api/api/delete.js +49 -22
- package/api/api/delete_by_query.js +88 -25
- package/api/api/delete_by_query_rethrottle.js +33 -19
- package/api/api/delete_script.js +31 -17
- package/api/api/exists.js +55 -22
- package/api/api/exists_source.js +60 -27
- package/api/api/explain.js +60 -22
- package/api/api/features.js +56 -35
- package/api/api/field_caps.js +36 -18
- package/api/api/get.js +55 -22
- package/api/api/get_script.js +30 -17
- package/api/api/get_script_context.js +15 -15
- package/api/api/get_script_languages.js +15 -15
- package/api/api/get_source.js +55 -22
- package/api/api/index.js +60 -28
- package/api/api/indices.js +1068 -857
- package/api/api/info.js +15 -15
- package/api/api/ingest.js +132 -96
- package/api/api/mget.js +50 -26
- package/api/api/msearch.js +49 -26
- package/api/api/msearch_template.js +53 -26
- package/api/api/mtermvectors.js +48 -24
- package/api/api/nodes.js +281 -154
- package/api/api/ping.js +15 -15
- package/api/api/put_script.js +40 -25
- package/api/api/rank_eval.js +37 -20
- package/api/api/reindex.js +38 -17
- package/api/api/reindex_rethrottle.js +32 -19
- package/api/api/render_search_template.js +18 -18
- package/api/api/scripts_painless_execute.js +15 -15
- package/api/api/scroll.js +31 -17
- package/api/api/search.js +108 -24
- package/api/api/search_shards.js +36 -18
- package/api/api/search_template.js +64 -26
- package/api/api/shutdown.js +66 -54
- package/api/api/snapshot.js +347 -224
- package/api/api/tasks.js +65 -46
- package/api/api/terms_enum.js +17 -17
- package/api/api/termvectors.js +57 -26
- package/api/api/update.js +64 -24
- package/api/api/update_by_query.js +89 -23
- package/api/api/update_by_query_rethrottle.js +33 -19
- package/api/index.js +267 -179
- package/api/new.d.ts +2042 -529
- package/api/opensearch_dashboards.d.ts +239 -236
- package/api/requestParams.d.ts +301 -69
- package/api/types.d.ts +6204 -5719
- package/api/utils.js +22 -22
- package/codecov.yml +2 -2
- package/index.d.ts +4776 -935
- package/index.js +152 -140
- package/index.mjs +9 -9
- package/lib/Connection.d.ts +37 -26
- package/lib/Connection.js +163 -168
- package/lib/Helpers.d.ts +103 -64
- package/lib/Helpers.js +398 -371
- package/lib/Serializer.d.ts +2 -2
- package/lib/Serializer.js +39 -39
- package/lib/Transport.d.ts +30 -12
- package/lib/Transport.js +375 -336
- package/lib/errors.d.ts +25 -7
- package/lib/errors.js +75 -71
- package/lib/pool/BaseConnectionPool.js +100 -97
- package/lib/pool/CloudConnectionPool.js +16 -16
- package/lib/pool/ConnectionPool.js +105 -105
- package/lib/pool/index.d.ts +8 -6
- package/lib/pool/index.js +6 -6
- package/package.json +13 -8
package/index.js
CHANGED
|
@@ -28,121 +28,131 @@
|
|
|
28
28
|
* under the License.
|
|
29
29
|
*/
|
|
30
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
|
|
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
45
|
/* istanbul ignore next */
|
|
46
46
|
if (clientVersion.includes('-')) {
|
|
47
47
|
// clean prerelease
|
|
48
|
-
clientVersion = clientVersion.slice(0, clientVersion.indexOf('-')) + 'p'
|
|
48
|
+
clientVersion = clientVersion.slice(0, clientVersion.indexOf('-')) + 'p';
|
|
49
49
|
}
|
|
50
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')
|
|
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
55
|
|
|
56
|
-
const OpenSearchAPI = require('./api')
|
|
56
|
+
const OpenSearchAPI = require('./api');
|
|
57
57
|
|
|
58
58
|
class Client extends OpenSearchAPI {
|
|
59
|
-
constructor
|
|
60
|
-
super({ ConfigurationError })
|
|
59
|
+
constructor(opts = {}) {
|
|
60
|
+
super({ ConfigurationError });
|
|
61
61
|
if (opts.cloud && opts[kChild] === undefined) {
|
|
62
|
-
const { id, username, password } = opts.cloud
|
|
62
|
+
const { id, username, password } = opts.cloud;
|
|
63
63
|
// the cloud id is `cluster-name:base64encodedurl`
|
|
64
64
|
// the url is a string divided by two '$', the first is the cloud url
|
|
65
65
|
// the second the opensearch instance, the third the opensearchDashboards instance
|
|
66
|
-
const cloudUrls = Buffer.from(id.split(':')[1], 'base64').toString().split('$')
|
|
66
|
+
const cloudUrls = Buffer.from(id.split(':')[1], 'base64').toString().split('$');
|
|
67
67
|
|
|
68
68
|
// TODO: remove username and password here in 8
|
|
69
69
|
if (username && password) {
|
|
70
|
-
opts.auth = Object.assign({}, opts.auth, { username, password })
|
|
70
|
+
opts.auth = Object.assign({}, opts.auth, { username, password });
|
|
71
71
|
}
|
|
72
|
-
opts.node = `https://${cloudUrls[1]}.${cloudUrls[0]}
|
|
72
|
+
opts.node = `https://${cloudUrls[1]}.${cloudUrls[0]}`;
|
|
73
73
|
|
|
74
74
|
// Cloud has better performances with compression enabled
|
|
75
75
|
// see https://github.com/elastic/elasticsearch-py/pull/704.
|
|
76
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
|
-
|
|
81
|
-
opts.ssl =
|
|
82
|
-
opts.ssl.secureProtocol = 'TLSv1_2_method'
|
|
77
|
+
if (opts.compression == null) opts.compression = 'gzip';
|
|
78
|
+
if (opts.suggestCompression == null) opts.suggestCompression = true;
|
|
79
|
+
if (opts.ssl == null || (opts.ssl && opts.ssl.secureProtocol == null)) {
|
|
80
|
+
opts.ssl = opts.ssl || {};
|
|
81
|
+
opts.ssl.secureProtocol = 'TLSv1_2_method';
|
|
83
82
|
}
|
|
84
83
|
}
|
|
85
84
|
|
|
86
85
|
if (!opts.node && !opts.nodes) {
|
|
87
|
-
throw new ConfigurationError('Missing node(s) option')
|
|
86
|
+
throw new ConfigurationError('Missing node(s) option');
|
|
88
87
|
}
|
|
89
88
|
|
|
90
89
|
if (opts[kChild] === undefined) {
|
|
91
|
-
const checkAuth = getAuth(opts.node || opts.nodes)
|
|
90
|
+
const checkAuth = getAuth(opts.node || opts.nodes);
|
|
92
91
|
if (checkAuth && checkAuth.username && checkAuth.password) {
|
|
93
|
-
opts.auth = Object.assign({}, opts.auth, {
|
|
92
|
+
opts.auth = Object.assign({}, opts.auth, {
|
|
93
|
+
username: checkAuth.username,
|
|
94
|
+
password: checkAuth.password,
|
|
95
|
+
});
|
|
94
96
|
}
|
|
95
97
|
}
|
|
96
98
|
|
|
97
|
-
const options =
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
99
|
+
const options =
|
|
100
|
+
opts[kChild] !== undefined
|
|
101
|
+
? opts[kChild].initialOptions
|
|
102
|
+
: Object.assign(
|
|
103
|
+
{},
|
|
104
|
+
{
|
|
105
|
+
Connection,
|
|
106
|
+
Transport,
|
|
107
|
+
Serializer,
|
|
108
|
+
ConnectionPool: opts.cloud ? CloudConnectionPool : ConnectionPool,
|
|
109
|
+
maxRetries: 3,
|
|
110
|
+
requestTimeout: 30000,
|
|
111
|
+
pingTimeout: 3000,
|
|
112
|
+
sniffInterval: false,
|
|
113
|
+
sniffOnStart: false,
|
|
114
|
+
sniffEndpoint: '_nodes/_all/http',
|
|
115
|
+
sniffOnConnectionFault: false,
|
|
116
|
+
resurrectStrategy: 'ping',
|
|
117
|
+
suggestCompression: false,
|
|
118
|
+
compression: false,
|
|
119
|
+
ssl: null,
|
|
120
|
+
agent: null,
|
|
121
|
+
headers: {},
|
|
122
|
+
nodeFilter: null,
|
|
123
|
+
nodeSelector: 'round-robin',
|
|
124
|
+
generateRequestId: null,
|
|
125
|
+
name: 'opensearch-js',
|
|
126
|
+
auth: null,
|
|
127
|
+
opaqueIdPrefix: null,
|
|
128
|
+
context: null,
|
|
129
|
+
proxy: null,
|
|
130
|
+
enableMetaHeader: true,
|
|
131
|
+
disablePrototypePoisoningProtection: false,
|
|
132
|
+
},
|
|
133
|
+
opts
|
|
134
|
+
);
|
|
128
135
|
|
|
129
136
|
if (process.env.OPENSEARCH_CLIENT_APIVERSIONING === 'true') {
|
|
130
|
-
options.headers = Object.assign(
|
|
137
|
+
options.headers = Object.assign(
|
|
138
|
+
{ accept: 'application/vnd.opensearch+json; compatible-with=7' },
|
|
139
|
+
options.headers
|
|
140
|
+
);
|
|
131
141
|
}
|
|
132
142
|
|
|
133
|
-
this[kInitialOptions] = options
|
|
134
|
-
this[kExtensions] = []
|
|
135
|
-
this.name = options.name
|
|
143
|
+
this[kInitialOptions] = options;
|
|
144
|
+
this[kExtensions] = [];
|
|
145
|
+
this.name = options.name;
|
|
136
146
|
|
|
137
147
|
if (opts[kChild] !== undefined) {
|
|
138
|
-
this.serializer = options[kChild].serializer
|
|
139
|
-
this.connectionPool = options[kChild].connectionPool
|
|
140
|
-
this[kEventEmitter] = options[kChild].eventEmitter
|
|
148
|
+
this.serializer = options[kChild].serializer;
|
|
149
|
+
this.connectionPool = options[kChild].connectionPool;
|
|
150
|
+
this[kEventEmitter] = options[kChild].eventEmitter;
|
|
141
151
|
} else {
|
|
142
|
-
this[kEventEmitter] = new EventEmitter()
|
|
152
|
+
this[kEventEmitter] = new EventEmitter();
|
|
143
153
|
this.serializer = new options.Serializer({
|
|
144
|
-
disablePrototypePoisoningProtection: options.disablePrototypePoisoningProtection
|
|
145
|
-
})
|
|
154
|
+
disablePrototypePoisoningProtection: options.disablePrototypePoisoningProtection,
|
|
155
|
+
});
|
|
146
156
|
this.connectionPool = new options.ConnectionPool({
|
|
147
157
|
pingTimeout: options.pingTimeout,
|
|
148
158
|
resurrectStrategy: options.resurrectStrategy,
|
|
@@ -152,12 +162,13 @@ class Client extends OpenSearchAPI {
|
|
|
152
162
|
Connection: options.Connection,
|
|
153
163
|
auth: options.auth,
|
|
154
164
|
emit: this[kEventEmitter].emit.bind(this[kEventEmitter]),
|
|
155
|
-
sniffEnabled:
|
|
165
|
+
sniffEnabled:
|
|
166
|
+
options.sniffInterval !== false ||
|
|
156
167
|
options.sniffOnStart !== false ||
|
|
157
|
-
options.sniffOnConnectionFault !== false
|
|
158
|
-
})
|
|
168
|
+
options.sniffOnConnectionFault !== false,
|
|
169
|
+
});
|
|
159
170
|
// Add the connections before initialize the Transport
|
|
160
|
-
this.connectionPool.addConnection(options.node || options.nodes)
|
|
171
|
+
this.connectionPool.addConnection(options.node || options.nodes);
|
|
161
172
|
}
|
|
162
173
|
|
|
163
174
|
this.transport = new options.Transport({
|
|
@@ -179,142 +190,143 @@ class Client extends OpenSearchAPI {
|
|
|
179
190
|
name: options.name,
|
|
180
191
|
opaqueIdPrefix: options.opaqueIdPrefix,
|
|
181
192
|
context: options.context,
|
|
182
|
-
memoryCircuitBreaker: options.memoryCircuitBreaker
|
|
183
|
-
})
|
|
193
|
+
memoryCircuitBreaker: options.memoryCircuitBreaker,
|
|
194
|
+
});
|
|
184
195
|
|
|
185
196
|
this.helpers = new Helpers({
|
|
186
197
|
client: this,
|
|
187
|
-
maxRetries: options.maxRetries
|
|
188
|
-
})
|
|
198
|
+
maxRetries: options.maxRetries,
|
|
199
|
+
});
|
|
189
200
|
}
|
|
190
201
|
|
|
191
|
-
get emit
|
|
192
|
-
return this[kEventEmitter].emit.bind(this[kEventEmitter])
|
|
202
|
+
get emit() {
|
|
203
|
+
return this[kEventEmitter].emit.bind(this[kEventEmitter]);
|
|
193
204
|
}
|
|
194
205
|
|
|
195
|
-
get on
|
|
196
|
-
return this[kEventEmitter].on.bind(this[kEventEmitter])
|
|
206
|
+
get on() {
|
|
207
|
+
return this[kEventEmitter].on.bind(this[kEventEmitter]);
|
|
197
208
|
}
|
|
198
209
|
|
|
199
|
-
get once
|
|
200
|
-
return this[kEventEmitter].once.bind(this[kEventEmitter])
|
|
210
|
+
get once() {
|
|
211
|
+
return this[kEventEmitter].once.bind(this[kEventEmitter]);
|
|
201
212
|
}
|
|
202
213
|
|
|
203
|
-
get off
|
|
204
|
-
return this[kEventEmitter].off.bind(this[kEventEmitter])
|
|
214
|
+
get off() {
|
|
215
|
+
return this[kEventEmitter].off.bind(this[kEventEmitter]);
|
|
205
216
|
}
|
|
206
217
|
|
|
207
|
-
extend
|
|
218
|
+
extend(name, opts, fn) {
|
|
208
219
|
if (typeof opts === 'function') {
|
|
209
|
-
fn = opts
|
|
210
|
-
opts = {}
|
|
220
|
+
fn = opts;
|
|
221
|
+
opts = {};
|
|
211
222
|
}
|
|
212
223
|
|
|
213
|
-
let [namespace, method] = name.split('.')
|
|
224
|
+
let [namespace, method] = name.split('.');
|
|
214
225
|
if (method == null) {
|
|
215
|
-
method = namespace
|
|
216
|
-
namespace = null
|
|
226
|
+
method = namespace;
|
|
227
|
+
namespace = null;
|
|
217
228
|
}
|
|
218
229
|
|
|
219
230
|
if (namespace != null) {
|
|
220
231
|
if (this[namespace] != null && this[namespace][method] != null && opts.force !== true) {
|
|
221
|
-
throw new Error(`The method "${method}" already exists on namespace "${namespace}"`)
|
|
232
|
+
throw new Error(`The method "${method}" already exists on namespace "${namespace}"`);
|
|
222
233
|
}
|
|
223
234
|
|
|
224
|
-
if (this[namespace] == null) this[namespace] = {}
|
|
235
|
+
if (this[namespace] == null) this[namespace] = {};
|
|
225
236
|
this[namespace][method] = fn({
|
|
226
237
|
makeRequest: this.transport.request.bind(this.transport),
|
|
227
238
|
result: { body: null, statusCode: null, headers: null, warnings: null },
|
|
228
|
-
ConfigurationError
|
|
229
|
-
})
|
|
239
|
+
ConfigurationError,
|
|
240
|
+
});
|
|
230
241
|
} else {
|
|
231
242
|
if (this[method] != null && opts.force !== true) {
|
|
232
|
-
throw new Error(`The method "${method}" already exists`)
|
|
243
|
+
throw new Error(`The method "${method}" already exists`);
|
|
233
244
|
}
|
|
234
245
|
|
|
235
246
|
this[method] = fn({
|
|
236
247
|
makeRequest: this.transport.request.bind(this.transport),
|
|
237
248
|
result: { body: null, statusCode: null, headers: null, warnings: null },
|
|
238
|
-
ConfigurationError
|
|
239
|
-
})
|
|
249
|
+
ConfigurationError,
|
|
250
|
+
});
|
|
240
251
|
}
|
|
241
252
|
|
|
242
|
-
this[kExtensions].push({ name, opts, fn })
|
|
253
|
+
this[kExtensions].push({ name, opts, fn });
|
|
243
254
|
}
|
|
244
255
|
|
|
245
|
-
child
|
|
256
|
+
child(opts) {
|
|
246
257
|
// Merge the new options with the initial ones
|
|
247
|
-
const options = Object.assign({}, this[kInitialOptions], opts)
|
|
258
|
+
const options = Object.assign({}, this[kInitialOptions], opts);
|
|
248
259
|
// Pass to the child client the parent instances that cannot be overriden
|
|
249
260
|
options[kChild] = {
|
|
250
261
|
connectionPool: this.connectionPool,
|
|
251
262
|
serializer: this.serializer,
|
|
252
263
|
eventEmitter: this[kEventEmitter],
|
|
253
|
-
initialOptions: options
|
|
254
|
-
}
|
|
264
|
+
initialOptions: options,
|
|
265
|
+
};
|
|
255
266
|
|
|
256
267
|
/* istanbul ignore else */
|
|
257
268
|
if (options.auth !== undefined) {
|
|
258
|
-
options.headers = prepareHeaders(options.headers, options.auth)
|
|
269
|
+
options.headers = prepareHeaders(options.headers, options.auth);
|
|
259
270
|
}
|
|
260
271
|
|
|
261
|
-
const client = new Client(options)
|
|
272
|
+
const client = new Client(options);
|
|
262
273
|
// sync compatible check
|
|
263
|
-
const tSymbol = Object.getOwnPropertySymbols(this.transport)
|
|
264
|
-
|
|
265
|
-
|
|
274
|
+
const tSymbol = Object.getOwnPropertySymbols(this.transport).filter(
|
|
275
|
+
(symbol) => symbol.description === 'compatible check'
|
|
276
|
+
)[0];
|
|
277
|
+
client.transport[tSymbol] = this.transport[tSymbol];
|
|
266
278
|
// Add parent extensions
|
|
267
279
|
if (this[kExtensions].length > 0) {
|
|
268
280
|
this[kExtensions].forEach(({ name, opts, fn }) => {
|
|
269
|
-
client.extend(name, opts, fn)
|
|
270
|
-
})
|
|
281
|
+
client.extend(name, opts, fn);
|
|
282
|
+
});
|
|
271
283
|
}
|
|
272
|
-
return client
|
|
284
|
+
return client;
|
|
273
285
|
}
|
|
274
286
|
|
|
275
|
-
close
|
|
287
|
+
close(callback) {
|
|
276
288
|
if (callback == null) {
|
|
277
289
|
return new Promise((resolve, reject) => {
|
|
278
|
-
this.close(resolve)
|
|
279
|
-
})
|
|
290
|
+
this.close(resolve);
|
|
291
|
+
});
|
|
280
292
|
}
|
|
281
|
-
debug('Closing the client')
|
|
282
|
-
this.connectionPool.empty(callback)
|
|
293
|
+
debug('Closing the client');
|
|
294
|
+
this.connectionPool.empty(callback);
|
|
283
295
|
}
|
|
284
296
|
}
|
|
285
297
|
|
|
286
|
-
function getAuth
|
|
298
|
+
function getAuth(node) {
|
|
287
299
|
if (Array.isArray(node)) {
|
|
288
300
|
for (const url of node) {
|
|
289
|
-
const auth = getUsernameAndPassword(url)
|
|
301
|
+
const auth = getUsernameAndPassword(url);
|
|
290
302
|
if (auth.username !== '' && auth.password !== '') {
|
|
291
|
-
return auth
|
|
303
|
+
return auth;
|
|
292
304
|
}
|
|
293
305
|
}
|
|
294
306
|
|
|
295
|
-
return null
|
|
307
|
+
return null;
|
|
296
308
|
}
|
|
297
309
|
|
|
298
|
-
const auth = getUsernameAndPassword(node)
|
|
310
|
+
const auth = getUsernameAndPassword(node);
|
|
299
311
|
if (auth.username !== '' && auth.password !== '') {
|
|
300
|
-
return auth
|
|
312
|
+
return auth;
|
|
301
313
|
}
|
|
302
314
|
|
|
303
|
-
return null
|
|
315
|
+
return null;
|
|
304
316
|
|
|
305
|
-
function getUsernameAndPassword
|
|
317
|
+
function getUsernameAndPassword(node) {
|
|
306
318
|
/* istanbul ignore else */
|
|
307
319
|
if (typeof node === 'string') {
|
|
308
|
-
const { username, password } = new URL(node)
|
|
320
|
+
const { username, password } = new URL(node);
|
|
309
321
|
return {
|
|
310
322
|
username: decodeURIComponent(username),
|
|
311
|
-
password: decodeURIComponent(password)
|
|
312
|
-
}
|
|
323
|
+
password: decodeURIComponent(password),
|
|
324
|
+
};
|
|
313
325
|
} else if (node.url instanceof URL) {
|
|
314
326
|
return {
|
|
315
327
|
username: decodeURIComponent(node.url.username),
|
|
316
|
-
password: decodeURIComponent(node.url.password)
|
|
317
|
-
}
|
|
328
|
+
password: decodeURIComponent(node.url.password),
|
|
329
|
+
};
|
|
318
330
|
}
|
|
319
331
|
}
|
|
320
332
|
}
|
|
@@ -325,8 +337,8 @@ const events = {
|
|
|
325
337
|
SNIFF: 'sniff',
|
|
326
338
|
RESURRECT: 'resurrect',
|
|
327
339
|
SERIALIZATION: 'serialization',
|
|
328
|
-
DESERIALIZATION: 'deserialization'
|
|
329
|
-
}
|
|
340
|
+
DESERIALIZATION: 'deserialization',
|
|
341
|
+
};
|
|
330
342
|
|
|
331
343
|
module.exports = {
|
|
332
344
|
Client,
|
|
@@ -335,5 +347,5 @@ module.exports = {
|
|
|
335
347
|
Connection,
|
|
336
348
|
Serializer,
|
|
337
349
|
events,
|
|
338
|
-
errors
|
|
339
|
-
}
|
|
350
|
+
errors,
|
|
351
|
+
};
|
package/index.mjs
CHANGED
|
@@ -28,13 +28,13 @@
|
|
|
28
28
|
* under the License.
|
|
29
29
|
*/
|
|
30
30
|
|
|
31
|
-
import mod from './index.js'
|
|
31
|
+
import mod from './index.js';
|
|
32
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
|
|
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;
|
package/lib/Connection.d.ts
CHANGED
|
@@ -31,13 +31,13 @@
|
|
|
31
31
|
/// <reference types="node" />
|
|
32
32
|
|
|
33
33
|
import { URL } from 'url';
|
|
34
|
-
import { inspect, InspectOptions } from 'util'
|
|
34
|
+
import { inspect, InspectOptions } from 'util';
|
|
35
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'
|
|
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
41
|
|
|
42
42
|
export declare type agentFn = (opts: ConnectionOptions) => any;
|
|
43
43
|
|
|
@@ -54,6 +54,10 @@ export interface ConnectionOptions {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
interface ConnectionRoles {
|
|
57
|
+
cluster_manager?: boolean
|
|
58
|
+
/**
|
|
59
|
+
* @deprecated use cluster_manager instead
|
|
60
|
+
*/
|
|
57
61
|
master?: boolean
|
|
58
62
|
data?: boolean
|
|
59
63
|
ingest?: boolean
|
|
@@ -78,30 +82,37 @@ export default class Connection {
|
|
|
78
82
|
DEAD: string;
|
|
79
83
|
};
|
|
80
84
|
static roles: {
|
|
81
|
-
|
|
85
|
+
CLUSTER_MANAGER?: string;
|
|
86
|
+
/**
|
|
87
|
+
* @deprecated use CLUSTER_MANAGER instead
|
|
88
|
+
*/
|
|
89
|
+
MASTER?: string;
|
|
82
90
|
DATA: string;
|
|
83
91
|
INGEST: string;
|
|
84
92
|
};
|
|
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(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
93
|
+
url: URL;
|
|
94
|
+
ssl: TlsConnectionOptions | null;
|
|
95
|
+
id: string;
|
|
96
|
+
headers: Record<string, any>;
|
|
97
|
+
status: string;
|
|
98
|
+
roles: ConnectionRoles;
|
|
99
|
+
deadCount: number;
|
|
100
|
+
resurrectTimeout: number;
|
|
101
|
+
makeRequest: any;
|
|
102
|
+
_openRequests: number;
|
|
103
|
+
_status: string;
|
|
104
|
+
_agent: http.Agent | https.Agent | hpagent.HttpProxyAgent | hpagent.HttpsProxyAgent;
|
|
105
|
+
constructor(opts?: ConnectionOptions);
|
|
106
|
+
request(
|
|
107
|
+
params: RequestOptions,
|
|
108
|
+
callback: (err: Error | null, response: http.IncomingMessage | null) => void
|
|
109
|
+
): http.ClientRequest;
|
|
110
|
+
close(): Connection;
|
|
111
|
+
setRole(role: string, enabled: boolean): Connection;
|
|
112
|
+
buildRequestObject(params: any): http.ClientRequestArgs;
|
|
102
113
|
// @ts-ignore
|
|
103
|
-
[inspect.custom](object: any, options: InspectOptions): string
|
|
104
|
-
toJSON(): any
|
|
114
|
+
[inspect.custom](object: any, options: InspectOptions): string;
|
|
115
|
+
toJSON(): any;
|
|
105
116
|
}
|
|
106
117
|
|
|
107
118
|
export { };
|