@opensearch-project/opensearch 1.0.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 +102 -106
- 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 +275 -0
- 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 +4779 -934
- package/index.js +153 -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 -63
- 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 +383 -324
- 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({
|
|
@@ -178,142 +189,144 @@ class Client extends OpenSearchAPI {
|
|
|
178
189
|
generateRequestId: options.generateRequestId,
|
|
179
190
|
name: options.name,
|
|
180
191
|
opaqueIdPrefix: options.opaqueIdPrefix,
|
|
181
|
-
context: options.context
|
|
182
|
-
|
|
192
|
+
context: options.context,
|
|
193
|
+
memoryCircuitBreaker: options.memoryCircuitBreaker,
|
|
194
|
+
});
|
|
183
195
|
|
|
184
196
|
this.helpers = new Helpers({
|
|
185
197
|
client: this,
|
|
186
|
-
maxRetries: options.maxRetries
|
|
187
|
-
})
|
|
198
|
+
maxRetries: options.maxRetries,
|
|
199
|
+
});
|
|
188
200
|
}
|
|
189
201
|
|
|
190
|
-
get emit
|
|
191
|
-
return this[kEventEmitter].emit.bind(this[kEventEmitter])
|
|
202
|
+
get emit() {
|
|
203
|
+
return this[kEventEmitter].emit.bind(this[kEventEmitter]);
|
|
192
204
|
}
|
|
193
205
|
|
|
194
|
-
get on
|
|
195
|
-
return this[kEventEmitter].on.bind(this[kEventEmitter])
|
|
206
|
+
get on() {
|
|
207
|
+
return this[kEventEmitter].on.bind(this[kEventEmitter]);
|
|
196
208
|
}
|
|
197
209
|
|
|
198
|
-
get once
|
|
199
|
-
return this[kEventEmitter].once.bind(this[kEventEmitter])
|
|
210
|
+
get once() {
|
|
211
|
+
return this[kEventEmitter].once.bind(this[kEventEmitter]);
|
|
200
212
|
}
|
|
201
213
|
|
|
202
|
-
get off
|
|
203
|
-
return this[kEventEmitter].off.bind(this[kEventEmitter])
|
|
214
|
+
get off() {
|
|
215
|
+
return this[kEventEmitter].off.bind(this[kEventEmitter]);
|
|
204
216
|
}
|
|
205
217
|
|
|
206
|
-
extend
|
|
218
|
+
extend(name, opts, fn) {
|
|
207
219
|
if (typeof opts === 'function') {
|
|
208
|
-
fn = opts
|
|
209
|
-
opts = {}
|
|
220
|
+
fn = opts;
|
|
221
|
+
opts = {};
|
|
210
222
|
}
|
|
211
223
|
|
|
212
|
-
let [namespace, method] = name.split('.')
|
|
224
|
+
let [namespace, method] = name.split('.');
|
|
213
225
|
if (method == null) {
|
|
214
|
-
method = namespace
|
|
215
|
-
namespace = null
|
|
226
|
+
method = namespace;
|
|
227
|
+
namespace = null;
|
|
216
228
|
}
|
|
217
229
|
|
|
218
230
|
if (namespace != null) {
|
|
219
231
|
if (this[namespace] != null && this[namespace][method] != null && opts.force !== true) {
|
|
220
|
-
throw new Error(`The method "${method}" already exists on namespace "${namespace}"`)
|
|
232
|
+
throw new Error(`The method "${method}" already exists on namespace "${namespace}"`);
|
|
221
233
|
}
|
|
222
234
|
|
|
223
|
-
if (this[namespace] == null) this[namespace] = {}
|
|
235
|
+
if (this[namespace] == null) this[namespace] = {};
|
|
224
236
|
this[namespace][method] = fn({
|
|
225
237
|
makeRequest: this.transport.request.bind(this.transport),
|
|
226
238
|
result: { body: null, statusCode: null, headers: null, warnings: null },
|
|
227
|
-
ConfigurationError
|
|
228
|
-
})
|
|
239
|
+
ConfigurationError,
|
|
240
|
+
});
|
|
229
241
|
} else {
|
|
230
242
|
if (this[method] != null && opts.force !== true) {
|
|
231
|
-
throw new Error(`The method "${method}" already exists`)
|
|
243
|
+
throw new Error(`The method "${method}" already exists`);
|
|
232
244
|
}
|
|
233
245
|
|
|
234
246
|
this[method] = fn({
|
|
235
247
|
makeRequest: this.transport.request.bind(this.transport),
|
|
236
248
|
result: { body: null, statusCode: null, headers: null, warnings: null },
|
|
237
|
-
ConfigurationError
|
|
238
|
-
})
|
|
249
|
+
ConfigurationError,
|
|
250
|
+
});
|
|
239
251
|
}
|
|
240
252
|
|
|
241
|
-
this[kExtensions].push({ name, opts, fn })
|
|
253
|
+
this[kExtensions].push({ name, opts, fn });
|
|
242
254
|
}
|
|
243
255
|
|
|
244
|
-
child
|
|
256
|
+
child(opts) {
|
|
245
257
|
// Merge the new options with the initial ones
|
|
246
|
-
const options = Object.assign({}, this[kInitialOptions], opts)
|
|
258
|
+
const options = Object.assign({}, this[kInitialOptions], opts);
|
|
247
259
|
// Pass to the child client the parent instances that cannot be overriden
|
|
248
260
|
options[kChild] = {
|
|
249
261
|
connectionPool: this.connectionPool,
|
|
250
262
|
serializer: this.serializer,
|
|
251
263
|
eventEmitter: this[kEventEmitter],
|
|
252
|
-
initialOptions: options
|
|
253
|
-
}
|
|
264
|
+
initialOptions: options,
|
|
265
|
+
};
|
|
254
266
|
|
|
255
267
|
/* istanbul ignore else */
|
|
256
268
|
if (options.auth !== undefined) {
|
|
257
|
-
options.headers = prepareHeaders(options.headers, options.auth)
|
|
269
|
+
options.headers = prepareHeaders(options.headers, options.auth);
|
|
258
270
|
}
|
|
259
271
|
|
|
260
|
-
const client = new Client(options)
|
|
272
|
+
const client = new Client(options);
|
|
261
273
|
// sync compatible check
|
|
262
|
-
const tSymbol = Object.getOwnPropertySymbols(this.transport)
|
|
263
|
-
|
|
264
|
-
|
|
274
|
+
const tSymbol = Object.getOwnPropertySymbols(this.transport).filter(
|
|
275
|
+
(symbol) => symbol.description === 'compatible check'
|
|
276
|
+
)[0];
|
|
277
|
+
client.transport[tSymbol] = this.transport[tSymbol];
|
|
265
278
|
// Add parent extensions
|
|
266
279
|
if (this[kExtensions].length > 0) {
|
|
267
280
|
this[kExtensions].forEach(({ name, opts, fn }) => {
|
|
268
|
-
client.extend(name, opts, fn)
|
|
269
|
-
})
|
|
281
|
+
client.extend(name, opts, fn);
|
|
282
|
+
});
|
|
270
283
|
}
|
|
271
|
-
return client
|
|
284
|
+
return client;
|
|
272
285
|
}
|
|
273
286
|
|
|
274
|
-
close
|
|
287
|
+
close(callback) {
|
|
275
288
|
if (callback == null) {
|
|
276
289
|
return new Promise((resolve, reject) => {
|
|
277
|
-
this.close(resolve)
|
|
278
|
-
})
|
|
290
|
+
this.close(resolve);
|
|
291
|
+
});
|
|
279
292
|
}
|
|
280
|
-
debug('Closing the client')
|
|
281
|
-
this.connectionPool.empty(callback)
|
|
293
|
+
debug('Closing the client');
|
|
294
|
+
this.connectionPool.empty(callback);
|
|
282
295
|
}
|
|
283
296
|
}
|
|
284
297
|
|
|
285
|
-
function getAuth
|
|
298
|
+
function getAuth(node) {
|
|
286
299
|
if (Array.isArray(node)) {
|
|
287
300
|
for (const url of node) {
|
|
288
|
-
const auth = getUsernameAndPassword(url)
|
|
301
|
+
const auth = getUsernameAndPassword(url);
|
|
289
302
|
if (auth.username !== '' && auth.password !== '') {
|
|
290
|
-
return auth
|
|
303
|
+
return auth;
|
|
291
304
|
}
|
|
292
305
|
}
|
|
293
306
|
|
|
294
|
-
return null
|
|
307
|
+
return null;
|
|
295
308
|
}
|
|
296
309
|
|
|
297
|
-
const auth = getUsernameAndPassword(node)
|
|
310
|
+
const auth = getUsernameAndPassword(node);
|
|
298
311
|
if (auth.username !== '' && auth.password !== '') {
|
|
299
|
-
return auth
|
|
312
|
+
return auth;
|
|
300
313
|
}
|
|
301
314
|
|
|
302
|
-
return null
|
|
315
|
+
return null;
|
|
303
316
|
|
|
304
|
-
function getUsernameAndPassword
|
|
317
|
+
function getUsernameAndPassword(node) {
|
|
305
318
|
/* istanbul ignore else */
|
|
306
319
|
if (typeof node === 'string') {
|
|
307
|
-
const { username, password } = new URL(node)
|
|
320
|
+
const { username, password } = new URL(node);
|
|
308
321
|
return {
|
|
309
322
|
username: decodeURIComponent(username),
|
|
310
|
-
password: decodeURIComponent(password)
|
|
311
|
-
}
|
|
323
|
+
password: decodeURIComponent(password),
|
|
324
|
+
};
|
|
312
325
|
} else if (node.url instanceof URL) {
|
|
313
326
|
return {
|
|
314
327
|
username: decodeURIComponent(node.url.username),
|
|
315
|
-
password: decodeURIComponent(node.url.password)
|
|
316
|
-
}
|
|
328
|
+
password: decodeURIComponent(node.url.password),
|
|
329
|
+
};
|
|
317
330
|
}
|
|
318
331
|
}
|
|
319
332
|
}
|
|
@@ -324,8 +337,8 @@ const events = {
|
|
|
324
337
|
SNIFF: 'sniff',
|
|
325
338
|
RESURRECT: 'resurrect',
|
|
326
339
|
SERIALIZATION: 'serialization',
|
|
327
|
-
DESERIALIZATION: 'deserialization'
|
|
328
|
-
}
|
|
340
|
+
DESERIALIZATION: 'deserialization',
|
|
341
|
+
};
|
|
329
342
|
|
|
330
343
|
module.exports = {
|
|
331
344
|
Client,
|
|
@@ -334,5 +347,5 @@ module.exports = {
|
|
|
334
347
|
Connection,
|
|
335
348
|
Serializer,
|
|
336
349
|
events,
|
|
337
|
-
errors
|
|
338
|
-
}
|
|
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 { };
|