@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.
Files changed (86) hide show
  1. package/.eslintignore +2 -0
  2. package/.eslintrc.json +26 -0
  3. package/.prettierrc.json +5 -0
  4. package/.whitesource +15 -0
  5. package/ADMINS.md +18 -11
  6. package/COMPATIBILITY.md +24 -0
  7. package/DEVELOPER_GUIDE.md +22 -5
  8. package/MAINTAINERS.md +23 -18
  9. package/README.md +100 -101
  10. package/RELEASING.md +3 -3
  11. package/SECURITY.md +1 -1
  12. package/api/api/bulk.js +53 -26
  13. package/api/api/cat.js +354 -264
  14. package/api/api/clear_scroll.js +17 -17
  15. package/api/api/cluster.js +366 -219
  16. package/api/api/count.js +55 -24
  17. package/api/api/create.js +50 -24
  18. package/api/api/dangling_indices.js +95 -51
  19. package/api/api/delete.js +49 -22
  20. package/api/api/delete_by_query.js +88 -25
  21. package/api/api/delete_by_query_rethrottle.js +33 -19
  22. package/api/api/delete_script.js +31 -17
  23. package/api/api/exists.js +55 -22
  24. package/api/api/exists_source.js +60 -27
  25. package/api/api/explain.js +60 -22
  26. package/api/api/features.js +56 -35
  27. package/api/api/field_caps.js +36 -18
  28. package/api/api/get.js +55 -22
  29. package/api/api/get_script.js +30 -17
  30. package/api/api/get_script_context.js +15 -15
  31. package/api/api/get_script_languages.js +15 -15
  32. package/api/api/get_source.js +55 -22
  33. package/api/api/index.js +60 -28
  34. package/api/api/indices.js +1068 -857
  35. package/api/api/info.js +15 -15
  36. package/api/api/ingest.js +132 -96
  37. package/api/api/mget.js +50 -26
  38. package/api/api/msearch.js +49 -26
  39. package/api/api/msearch_template.js +53 -26
  40. package/api/api/mtermvectors.js +48 -24
  41. package/api/api/nodes.js +281 -154
  42. package/api/api/ping.js +15 -15
  43. package/api/api/put_script.js +40 -25
  44. package/api/api/rank_eval.js +37 -20
  45. package/api/api/reindex.js +38 -17
  46. package/api/api/reindex_rethrottle.js +32 -19
  47. package/api/api/render_search_template.js +18 -18
  48. package/api/api/scripts_painless_execute.js +15 -15
  49. package/api/api/scroll.js +31 -17
  50. package/api/api/search.js +108 -24
  51. package/api/api/search_shards.js +36 -18
  52. package/api/api/search_template.js +64 -26
  53. package/api/api/shutdown.js +66 -54
  54. package/api/api/snapshot.js +347 -224
  55. package/api/api/tasks.js +65 -46
  56. package/api/api/terms_enum.js +17 -17
  57. package/api/api/termvectors.js +57 -26
  58. package/api/api/update.js +64 -24
  59. package/api/api/update_by_query.js +89 -23
  60. package/api/api/update_by_query_rethrottle.js +33 -19
  61. package/api/index.js +267 -179
  62. package/api/new.d.ts +2042 -529
  63. package/api/opensearch_dashboards.d.ts +239 -236
  64. package/api/requestParams.d.ts +301 -69
  65. package/api/types.d.ts +6204 -5719
  66. package/api/utils.js +22 -22
  67. package/codecov.yml +2 -2
  68. package/index.d.ts +4776 -935
  69. package/index.js +152 -140
  70. package/index.mjs +9 -9
  71. package/lib/Connection.d.ts +37 -26
  72. package/lib/Connection.js +163 -168
  73. package/lib/Helpers.d.ts +103 -64
  74. package/lib/Helpers.js +398 -371
  75. package/lib/Serializer.d.ts +2 -2
  76. package/lib/Serializer.js +39 -39
  77. package/lib/Transport.d.ts +30 -12
  78. package/lib/Transport.js +375 -336
  79. package/lib/errors.d.ts +25 -7
  80. package/lib/errors.js +75 -71
  81. package/lib/pool/BaseConnectionPool.js +100 -97
  82. package/lib/pool/CloudConnectionPool.js +16 -16
  83. package/lib/pool/ConnectionPool.js +105 -105
  84. package/lib/pool/index.d.ts +8 -6
  85. package/lib/pool/index.js +6 -6
  86. package/package.json +13 -8
package/lib/errors.d.ts CHANGED
@@ -28,28 +28,37 @@
28
28
  * under the License.
29
29
  */
30
30
 
31
- import { ApiResponse, Context } from './Transport'
31
+ import { ApiResponse, Context } from './Transport';
32
32
 
33
33
  export declare class OpenSearchClientError extends Error {
34
34
  name: string;
35
35
  message: string;
36
36
  }
37
37
 
38
- export declare class TimeoutError<TResponse = Record<string, any>, TContext = Context> extends OpenSearchClientError {
38
+ export declare class TimeoutError<
39
+ TResponse = Record<string, any>,
40
+ TContext = Context
41
+ > extends OpenSearchClientError {
39
42
  name: string;
40
43
  message: string;
41
44
  meta: ApiResponse<TResponse, TContext>;
42
45
  constructor(message: string, meta: ApiResponse);
43
46
  }
44
47
 
45
- export declare class ConnectionError<TResponse = Record<string, any>, TContext = Context> extends OpenSearchClientError {
48
+ export declare class ConnectionError<
49
+ TResponse = Record<string, any>,
50
+ TContext = Context
51
+ > extends OpenSearchClientError {
46
52
  name: string;
47
53
  message: string;
48
54
  meta: ApiResponse<TResponse, TContext>;
49
55
  constructor(message: string, meta: ApiResponse);
50
56
  }
51
57
 
52
- export declare class NoLivingConnectionsError<TResponse = Record<string, any>, TContext = Context> extends OpenSearchClientError {
58
+ export declare class NoLivingConnectionsError<
59
+ TResponse = Record<string, any>,
60
+ TContext = Context
61
+ > extends OpenSearchClientError {
53
62
  name: string;
54
63
  message: string;
55
64
  meta: ApiResponse<TResponse, TContext>;
@@ -76,7 +85,10 @@ export declare class ConfigurationError extends OpenSearchClientError {
76
85
  constructor(message: string);
77
86
  }
78
87
 
79
- export declare class ResponseError<TResponse = Record<string, any>, TContext = Context> extends OpenSearchClientError {
88
+ export declare class ResponseError<
89
+ TResponse = Record<string, any>,
90
+ TContext = Context
91
+ > extends OpenSearchClientError {
80
92
  name: string;
81
93
  message: string;
82
94
  meta: ApiResponse<TResponse, TContext>;
@@ -86,14 +98,20 @@ export declare class ResponseError<TResponse = Record<string, any>, TContext = C
86
98
  constructor(meta: ApiResponse);
87
99
  }
88
100
 
89
- export declare class RequestAbortedError<TResponse = Record<string, any>, TContext = Context> extends OpenSearchClientError {
101
+ export declare class RequestAbortedError<
102
+ TResponse = Record<string, any>,
103
+ TContext = Context
104
+ > extends OpenSearchClientError {
90
105
  name: string;
91
106
  message: string;
92
107
  meta: ApiResponse<TResponse, TContext>;
93
108
  constructor(message: string, meta: ApiResponse);
94
109
  }
95
110
 
96
- export declare class NotCompatibleError<TResponse = Record<string, any>, TContext = Context> extends OpenSearchClientError {
111
+ export declare class NotCompatibleError<
112
+ TResponse = Record<string, any>,
113
+ TContext = Context
114
+ > extends OpenSearchClientError {
97
115
  name: string;
98
116
  message: string;
99
117
  meta: ApiResponse<TResponse, TContext>;
package/lib/errors.js CHANGED
@@ -28,129 +28,133 @@
28
28
  * under the License.
29
29
  */
30
30
 
31
- 'use strict'
31
+ 'use strict';
32
32
 
33
33
  class OpenSearchClientError extends Error {
34
- constructor (message) {
35
- super(message)
36
- this.name = 'OpenSearchClientError'
34
+ constructor(message) {
35
+ super(message);
36
+ this.name = 'OpenSearchClientError';
37
37
  }
38
38
  }
39
39
 
40
40
  class TimeoutError extends OpenSearchClientError {
41
- constructor (message, meta) {
42
- super(message)
43
- Error.captureStackTrace(this, TimeoutError)
44
- this.name = 'TimeoutError'
45
- this.message = message || 'Timeout Error'
46
- this.meta = meta
41
+ constructor(message, meta) {
42
+ super(message);
43
+ Error.captureStackTrace(this, TimeoutError);
44
+ this.name = 'TimeoutError';
45
+ this.message = message || 'Timeout Error';
46
+ this.meta = meta;
47
47
  }
48
48
  }
49
49
 
50
50
  class ConnectionError extends OpenSearchClientError {
51
- constructor (message, meta) {
52
- super(message)
53
- Error.captureStackTrace(this, ConnectionError)
54
- this.name = 'ConnectionError'
55
- this.message = message || 'Connection Error'
56
- this.meta = meta
51
+ constructor(message, meta) {
52
+ super(message);
53
+ Error.captureStackTrace(this, ConnectionError);
54
+ this.name = 'ConnectionError';
55
+ this.message = message || 'Connection Error';
56
+ this.meta = meta;
57
57
  }
58
58
  }
59
59
 
60
60
  class NoLivingConnectionsError extends OpenSearchClientError {
61
- constructor (message, meta) {
62
- super(message)
63
- Error.captureStackTrace(this, NoLivingConnectionsError)
64
- this.name = 'NoLivingConnectionsError'
65
- this.message = message || 'Given the configuration, the ConnectionPool was not able to find a usable Connection for this request.'
66
- this.meta = meta
61
+ constructor(message, meta) {
62
+ super(message);
63
+ Error.captureStackTrace(this, NoLivingConnectionsError);
64
+ this.name = 'NoLivingConnectionsError';
65
+ this.message =
66
+ message ||
67
+ 'Given the configuration, the ConnectionPool was not able to find a usable Connection for this request.';
68
+ this.meta = meta;
67
69
  }
68
70
  }
69
71
 
70
72
  class SerializationError extends OpenSearchClientError {
71
- constructor (message, data) {
72
- super(message, data)
73
- Error.captureStackTrace(this, SerializationError)
74
- this.name = 'SerializationError'
75
- this.message = message || 'Serialization Error'
76
- this.data = data
73
+ constructor(message, data) {
74
+ super(message, data);
75
+ Error.captureStackTrace(this, SerializationError);
76
+ this.name = 'SerializationError';
77
+ this.message = message || 'Serialization Error';
78
+ this.data = data;
77
79
  }
78
80
  }
79
81
 
80
82
  class DeserializationError extends OpenSearchClientError {
81
- constructor (message, data) {
82
- super(message, data)
83
- Error.captureStackTrace(this, DeserializationError)
84
- this.name = 'DeserializationError'
85
- this.message = message || 'Deserialization Error'
86
- this.data = data
83
+ constructor(message, data) {
84
+ super(message, data);
85
+ Error.captureStackTrace(this, DeserializationError);
86
+ this.name = 'DeserializationError';
87
+ this.message = message || 'Deserialization Error';
88
+ this.data = data;
87
89
  }
88
90
  }
89
91
 
90
92
  class ConfigurationError extends OpenSearchClientError {
91
- constructor (message) {
92
- super(message)
93
- Error.captureStackTrace(this, ConfigurationError)
94
- this.name = 'ConfigurationError'
95
- this.message = message || 'Configuration Error'
93
+ constructor(message) {
94
+ super(message);
95
+ Error.captureStackTrace(this, ConfigurationError);
96
+ this.name = 'ConfigurationError';
97
+ this.message = message || 'Configuration Error';
96
98
  }
97
99
  }
98
100
 
99
101
  class ResponseError extends OpenSearchClientError {
100
- constructor (meta) {
101
- super('Response Error')
102
- Error.captureStackTrace(this, ResponseError)
103
- this.name = 'ResponseError'
102
+ constructor(meta) {
103
+ super('Response Error');
104
+ Error.captureStackTrace(this, ResponseError);
105
+ this.name = 'ResponseError';
104
106
  if (meta.body && meta.body.error && meta.body.error.type) {
105
107
  if (Array.isArray(meta.body.error.root_cause)) {
106
- this.message = meta.body.error.type + ': '
107
- this.message += meta.body.error.root_cause.map(entry => `[${entry.type}] Reason: ${entry.reason}`).join('; ')
108
+ this.message = meta.body.error.type + ': ';
109
+ this.message += meta.body.error.root_cause
110
+ .map((entry) => `[${entry.type}] Reason: ${entry.reason}`)
111
+ .join('; ');
108
112
  } else {
109
- this.message = meta.body.error.type
113
+ this.message = meta.body.error.type;
110
114
  }
111
115
  } else {
112
- this.message = 'Response Error'
116
+ this.message = 'Response Error';
113
117
  }
114
- this.meta = meta
118
+ this.meta = meta;
115
119
  }
116
120
 
117
- get body () {
118
- return this.meta.body
121
+ get body() {
122
+ return this.meta.body;
119
123
  }
120
124
 
121
- get statusCode () {
125
+ get statusCode() {
122
126
  if (this.meta.body && typeof this.meta.body.status === 'number') {
123
- return this.meta.body.status
127
+ return this.meta.body.status;
124
128
  }
125
- return this.meta.statusCode
129
+ return this.meta.statusCode;
126
130
  }
127
131
 
128
- get headers () {
129
- return this.meta.headers
132
+ get headers() {
133
+ return this.meta.headers;
130
134
  }
131
135
 
132
- toString () {
133
- return JSON.stringify(this.meta.body)
136
+ toString() {
137
+ return JSON.stringify(this.meta.body);
134
138
  }
135
139
  }
136
140
 
137
141
  class RequestAbortedError extends OpenSearchClientError {
138
- constructor (message, meta) {
139
- super(message)
140
- Error.captureStackTrace(this, RequestAbortedError)
141
- this.name = 'RequestAbortedError'
142
- this.message = message || 'Request aborted'
143
- this.meta = meta
142
+ constructor(message, meta) {
143
+ super(message);
144
+ Error.captureStackTrace(this, RequestAbortedError);
145
+ this.name = 'RequestAbortedError';
146
+ this.message = message || 'Request aborted';
147
+ this.meta = meta;
144
148
  }
145
149
  }
146
150
 
147
151
  class NotCompatibleError extends OpenSearchClientError {
148
- constructor (meta) {
149
- super('Not Compatible Error')
150
- Error.captureStackTrace(this, NotCompatibleError)
151
- this.name = 'NotCompatibleError'
152
- this.message = 'The client noticed that the server is not a supported distribution'
153
- this.meta = meta
152
+ constructor(meta) {
153
+ super('Not Compatible Error');
154
+ Error.captureStackTrace(this, NotCompatibleError);
155
+ this.name = 'NotCompatibleError';
156
+ this.message = 'The client noticed that the server is not a supported distribution';
157
+ this.meta = meta;
154
158
  }
155
159
  }
156
160
 
@@ -164,5 +168,5 @@ module.exports = {
164
168
  ConfigurationError,
165
169
  ResponseError,
166
170
  RequestAbortedError,
167
- NotCompatibleError
168
- }
171
+ NotCompatibleError,
172
+ };
@@ -28,71 +28,71 @@
28
28
  * under the License.
29
29
  */
30
30
 
31
- 'use strict'
31
+ 'use strict';
32
32
 
33
- const { URL } = require('url')
34
- const debug = require('debug')('opensearch')
35
- const Connection = require('../Connection')
36
- const noop = () => { }
33
+ const { URL } = require('url');
34
+ const debug = require('debug')('opensearch');
35
+ const Connection = require('../Connection');
36
+ const noop = () => {};
37
37
 
38
38
  class BaseConnectionPool {
39
- constructor (opts) {
39
+ constructor(opts) {
40
40
  // list of nodes and weights
41
- this.connections = []
41
+ this.connections = [];
42
42
  // how many nodes we have in our scheduler
43
- this.size = this.connections.length
44
- this.Connection = opts.Connection
45
- this.emit = opts.emit || noop
46
- this.auth = opts.auth || null
47
- this._ssl = opts.ssl
48
- this._agent = opts.agent
49
- this._proxy = opts.proxy || null
43
+ this.size = this.connections.length;
44
+ this.Connection = opts.Connection;
45
+ this.emit = opts.emit || noop;
46
+ this.auth = opts.auth || null;
47
+ this._ssl = opts.ssl;
48
+ this._agent = opts.agent;
49
+ this._proxy = opts.proxy || null;
50
50
  }
51
51
 
52
- getConnection () {
53
- throw new Error('getConnection must be implemented')
52
+ getConnection() {
53
+ throw new Error('getConnection must be implemented');
54
54
  }
55
55
 
56
- markAlive () {
57
- return this
56
+ markAlive() {
57
+ return this;
58
58
  }
59
59
 
60
- markDead () {
61
- return this
60
+ markDead() {
61
+ return this;
62
62
  }
63
63
 
64
64
  /**
65
65
  * Creates a new connection instance.
66
66
  */
67
- createConnection (opts) {
67
+ createConnection(opts) {
68
68
  if (typeof opts === 'string') {
69
- opts = this.urlToHost(opts)
69
+ opts = this.urlToHost(opts);
70
70
  }
71
71
 
72
72
  if (this.auth !== null) {
73
- opts.auth = this.auth
73
+ opts.auth = this.auth;
74
74
  } else if (opts.url.username !== '' && opts.url.password !== '') {
75
75
  opts.auth = {
76
76
  username: decodeURIComponent(opts.url.username),
77
- password: decodeURIComponent(opts.url.password)
78
- }
77
+ password: decodeURIComponent(opts.url.password),
78
+ };
79
79
  }
80
80
 
81
- if (opts.ssl == null) opts.ssl = this._ssl
81
+ if (opts.ssl == null) opts.ssl = this._ssl;
82
82
  /* istanbul ignore else */
83
- if (opts.agent == null) opts.agent = this._agent
83
+ if (opts.agent == null) opts.agent = this._agent;
84
84
  /* istanbul ignore else */
85
- if (opts.proxy == null) opts.proxy = this._proxy
85
+ if (opts.proxy == null) opts.proxy = this._proxy;
86
86
 
87
- const connection = new this.Connection(opts)
87
+ const connection = new this.Connection(opts);
88
88
 
89
89
  for (const conn of this.connections) {
90
90
  if (conn.id === connection.id) {
91
- throw new Error(`Connection with id '${connection.id}' is already present`)
91
+ throw new Error(`Connection with id '${connection.id}' is already present`);
92
92
  }
93
93
  }
94
94
 
95
- return connection
95
+ return connection;
96
96
  }
97
97
 
98
98
  /**
@@ -101,24 +101,24 @@ class BaseConnectionPool {
101
101
  * @param {object|string} host
102
102
  * @returns {ConnectionPool}
103
103
  */
104
- addConnection (opts) {
104
+ addConnection(opts) {
105
105
  if (Array.isArray(opts)) {
106
- return opts.forEach(o => this.addConnection(o))
106
+ return opts.forEach((o) => this.addConnection(o));
107
107
  }
108
108
 
109
109
  if (typeof opts === 'string') {
110
- opts = this.urlToHost(opts)
110
+ opts = this.urlToHost(opts);
111
111
  }
112
112
 
113
- const connectionById = this.connections.find(c => c.id === opts.id)
114
- const connectionByUrl = this.connections.find(c => c.id === opts.url.href)
113
+ const connectionById = this.connections.find((c) => c.id === opts.id);
114
+ const connectionByUrl = this.connections.find((c) => c.id === opts.url.href);
115
115
 
116
116
  if (connectionById || connectionByUrl) {
117
- throw new Error(`Connection with id '${opts.id || opts.url.href}' is already present`)
117
+ throw new Error(`Connection with id '${opts.id || opts.url.href}' is already present`);
118
118
  }
119
119
 
120
- this.update([...this.connections, opts])
121
- return this.connections[this.size - 1]
120
+ this.update([...this.connections, opts]);
121
+ return this.connections[this.size - 1];
122
122
  }
123
123
 
124
124
  /**
@@ -127,9 +127,9 @@ class BaseConnectionPool {
127
127
  * @param {object} connection
128
128
  * @returns {ConnectionPool}
129
129
  */
130
- removeConnection (connection) {
131
- debug('Removing connection', connection)
132
- return this.update(this.connections.filter(c => c.id !== connection.id))
130
+ removeConnection(connection) {
131
+ debug('Removing connection', connection);
132
+ return this.update(this.connections.filter((c) => c.id !== connection.id));
133
133
  }
134
134
 
135
135
  /**
@@ -137,18 +137,18 @@ class BaseConnectionPool {
137
137
  *
138
138
  * @returns {ConnectionPool}
139
139
  */
140
- empty (callback) {
141
- debug('Emptying the connection pool')
142
- let openConnections = this.size
143
- this.connections.forEach(connection => {
140
+ empty(callback) {
141
+ debug('Emptying the connection pool');
142
+ let openConnections = this.size;
143
+ this.connections.forEach((connection) => {
144
144
  connection.close(() => {
145
145
  if (--openConnections === 0) {
146
- this.connections = []
147
- this.size = this.connections.length
148
- callback()
146
+ this.connections = [];
147
+ this.size = this.connections.length;
148
+ callback();
149
149
  }
150
- })
151
- })
150
+ });
151
+ });
152
152
  }
153
153
 
154
154
  /**
@@ -157,49 +157,49 @@ class BaseConnectionPool {
157
157
  * @param {array} array of connections
158
158
  * @returns {ConnectionPool}
159
159
  */
160
- update (nodes) {
161
- debug('Updating the connection pool')
162
- const newConnections = []
163
- const oldConnections = []
160
+ update(nodes) {
161
+ debug('Updating the connection pool');
162
+ const newConnections = [];
163
+ const oldConnections = [];
164
164
 
165
165
  for (const node of nodes) {
166
166
  // if we already have a given connection in the pool
167
167
  // we mark it as alive and we do not close the connection
168
168
  // to avoid socket issues
169
- const connectionById = this.connections.find(c => c.id === node.id)
170
- const connectionByUrl = this.connections.find(c => c.id === node.url.href)
169
+ const connectionById = this.connections.find((c) => c.id === node.id);
170
+ const connectionByUrl = this.connections.find((c) => c.id === node.url.href);
171
171
  if (connectionById) {
172
- debug(`The connection with id '${node.id}' is already present`)
173
- this.markAlive(connectionById)
174
- newConnections.push(connectionById)
172
+ debug(`The connection with id '${node.id}' is already present`);
173
+ this.markAlive(connectionById);
174
+ newConnections.push(connectionById);
175
175
  // in case the user has passed a single url (or an array of urls),
176
176
  // the connection id will be the full href; to avoid closing valid connections
177
177
  // because are not present in the pool, we check also the node url,
178
178
  // and if is already present we update its id with the opensearch provided one.
179
179
  } else if (connectionByUrl) {
180
- connectionByUrl.id = node.id
181
- this.markAlive(connectionByUrl)
182
- newConnections.push(connectionByUrl)
180
+ connectionByUrl.id = node.id;
181
+ this.markAlive(connectionByUrl);
182
+ newConnections.push(connectionByUrl);
183
183
  } else {
184
- newConnections.push(this.createConnection(node))
184
+ newConnections.push(this.createConnection(node));
185
185
  }
186
186
  }
187
187
 
188
- const ids = nodes.map(c => c.id)
188
+ const ids = nodes.map((c) => c.id);
189
189
  // remove all the dead connections and old connections
190
190
  for (const connection of this.connections) {
191
191
  if (ids.indexOf(connection.id) === -1) {
192
- oldConnections.push(connection)
192
+ oldConnections.push(connection);
193
193
  }
194
194
  }
195
195
 
196
196
  // close old connections
197
- oldConnections.forEach(connection => connection.close())
197
+ oldConnections.forEach((connection) => connection.close());
198
198
 
199
- this.connections = newConnections
200
- this.size = this.connections.length
199
+ this.connections = newConnections;
200
+ this.size = this.connections.length;
201
201
 
202
- return this
202
+ return this;
203
203
  }
204
204
 
205
205
  /**
@@ -208,12 +208,12 @@ class BaseConnectionPool {
208
208
  * @param {object} nodes
209
209
  * @returns {array} hosts
210
210
  */
211
- nodesToHost (nodes, protocol) {
212
- const ids = Object.keys(nodes)
213
- const hosts = []
211
+ nodesToHost(nodes, protocol) {
212
+ const ids = Object.keys(nodes);
213
+ const hosts = [];
214
214
 
215
215
  for (let i = 0, len = ids.length; i < len; i++) {
216
- const node = nodes[ids[i]]
216
+ const node = nodes[ids[i]];
217
217
  // If there is no protocol in
218
218
  // the `publish_address` new URL will throw
219
219
  // the publish_address can have two forms:
@@ -221,36 +221,39 @@ class BaseConnectionPool {
221
221
  // - hostname/ip:port
222
222
  // if we encounter the second case, we should
223
223
  // use the hostname instead of the ip
224
- let address = node.http.publish_address
225
- const parts = address.split('/')
224
+ let address = node.http.publish_address;
225
+ const parts = address.split('/');
226
226
  // the url is in the form of hostname/ip:port
227
227
  if (parts.length > 1) {
228
- const hostname = parts[0]
229
- const port = parts[1].match(/((?::))(?:[0-9]+)$/g)[0].slice(1)
230
- address = `${hostname}:${port}`
228
+ const hostname = parts[0];
229
+ const port = parts[1].match(/((?::))(?:[0-9]+)$/g)[0].slice(1);
230
+ address = `${hostname}:${port}`;
231
231
  }
232
232
 
233
- address = address.slice(0, 4) === 'http'
234
- /* istanbul ignore next */
235
- ? address
236
- : `${protocol}//${address}`
233
+ address =
234
+ address.slice(0, 4) === 'http'
235
+ ? /* istanbul ignore next */
236
+ address
237
+ : `${protocol}//${address}`;
237
238
  const roles = node.roles.reduce((acc, role) => {
238
- acc[role] = true
239
- return acc
240
- }, {})
239
+ acc[role] = true;
240
+ return acc;
241
+ }, {});
241
242
 
242
243
  hosts.push({
243
244
  url: new URL(address),
244
245
  id: ids[i],
245
- roles: Object.assign({
246
- [Connection.roles.MASTER]: false,
247
- [Connection.roles.DATA]: false,
248
- [Connection.roles.INGEST]: false
249
- }, roles)
250
- })
246
+ roles: Object.assign(
247
+ {
248
+ [Connection.roles.DATA]: false,
249
+ [Connection.roles.INGEST]: false,
250
+ },
251
+ roles
252
+ ),
253
+ });
251
254
  }
252
255
 
253
- return hosts
256
+ return hosts;
254
257
  }
255
258
 
256
259
  /**
@@ -259,11 +262,11 @@ class BaseConnectionPool {
259
262
  * @param {string} url
260
263
  * @returns {object} host
261
264
  */
262
- urlToHost (url) {
265
+ urlToHost(url) {
263
266
  return {
264
- url: new URL(url)
265
- }
267
+ url: new URL(url),
268
+ };
266
269
  }
267
270
  }
268
271
 
269
- module.exports = BaseConnectionPool
272
+ module.exports = BaseConnectionPool;
@@ -28,14 +28,14 @@
28
28
  * under the License.
29
29
  */
30
30
 
31
- 'use strict'
31
+ 'use strict';
32
32
 
33
- const BaseConnectionPool = require('./BaseConnectionPool')
33
+ const BaseConnectionPool = require('./BaseConnectionPool');
34
34
 
35
35
  class CloudConnectionPool extends BaseConnectionPool {
36
- constructor (opts) {
37
- super(opts)
38
- this.cloudConnection = null
36
+ constructor(opts) {
37
+ super(opts);
38
+ this.cloudConnection = null;
39
39
  }
40
40
 
41
41
  /**
@@ -43,8 +43,8 @@ class CloudConnectionPool extends BaseConnectionPool {
43
43
  *
44
44
  * @returns {object} connection
45
45
  */
46
- getConnection () {
47
- return this.cloudConnection
46
+ getConnection() {
47
+ return this.cloudConnection;
48
48
  }
49
49
 
50
50
  /**
@@ -52,11 +52,11 @@ class CloudConnectionPool extends BaseConnectionPool {
52
52
  *
53
53
  * @returns {ConnectionPool}
54
54
  */
55
- empty (callback) {
55
+ empty(callback) {
56
56
  super.empty(() => {
57
- this.cloudConnection = null
58
- callback()
59
- })
57
+ this.cloudConnection = null;
58
+ callback();
59
+ });
60
60
  }
61
61
 
62
62
  /**
@@ -65,11 +65,11 @@ class CloudConnectionPool extends BaseConnectionPool {
65
65
  * @param {array} array of connections
66
66
  * @returns {ConnectionPool}
67
67
  */
68
- update (connections) {
69
- super.update(connections)
70
- this.cloudConnection = this.connections[0]
71
- return this
68
+ update(connections) {
69
+ super.update(connections);
70
+ this.cloudConnection = this.connections[0];
71
+ return this;
72
72
  }
73
73
  }
74
74
 
75
- module.exports = CloudConnectionPool
75
+ module.exports = CloudConnectionPool;