@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.
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 +102 -106
  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 +275 -0
  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 +4779 -934
  69. package/index.js +153 -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 -63
  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 +383 -324
  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
@@ -28,33 +28,30 @@
28
28
  * under the License.
29
29
  */
30
30
 
31
- 'use strict'
31
+ 'use strict';
32
32
 
33
- const BaseConnectionPool = require('./BaseConnectionPool')
34
- const assert = require('assert')
35
- const debug = require('debug')('opensearch')
36
- const Connection = require('../Connection')
37
- const noop = () => { }
33
+ const BaseConnectionPool = require('./BaseConnectionPool');
34
+ const assert = require('assert');
35
+ const debug = require('debug')('opensearch');
36
+ const Connection = require('../Connection');
37
+ const noop = () => {};
38
38
 
39
39
  class ConnectionPool extends BaseConnectionPool {
40
- constructor (opts) {
41
- super(opts)
40
+ constructor(opts) {
41
+ super(opts);
42
42
 
43
- this.dead = []
43
+ this.dead = [];
44
44
  // the resurrect timeout is 60s
45
- this.resurrectTimeout = 1000 * 60
45
+ this.resurrectTimeout = 1000 * 60;
46
46
  // number of consecutive failures after which
47
47
  // the timeout doesn't increase
48
- this.resurrectTimeoutCutoff = 5
49
- this.pingTimeout = opts.pingTimeout
50
- this._sniffEnabled = opts.sniffEnabled || false
48
+ this.resurrectTimeoutCutoff = 5;
49
+ this.pingTimeout = opts.pingTimeout;
50
+ this._sniffEnabled = opts.sniffEnabled || false;
51
51
 
52
- const resurrectStrategy = opts.resurrectStrategy || 'ping'
53
- this.resurrectStrategy = ConnectionPool.resurrectStrategies[resurrectStrategy]
54
- assert(
55
- this.resurrectStrategy != null,
56
- `Invalid resurrection strategy: '${resurrectStrategy}'`
57
- )
52
+ const resurrectStrategy = opts.resurrectStrategy || 'ping';
53
+ this.resurrectStrategy = ConnectionPool.resurrectStrategies[resurrectStrategy];
54
+ assert(this.resurrectStrategy != null, `Invalid resurrection strategy: '${resurrectStrategy}'`);
58
55
  }
59
56
 
60
57
  /**
@@ -64,15 +61,15 @@ class ConnectionPool extends BaseConnectionPool {
64
61
  *
65
62
  * @param {object} connection
66
63
  */
67
- markAlive (connection) {
68
- const { id } = connection
69
- debug(`Marking as 'alive' connection '${id}'`)
70
- const index = this.dead.indexOf(id)
71
- if (index > -1) this.dead.splice(index, 1)
72
- connection.status = Connection.statuses.ALIVE
73
- connection.deadCount = 0
74
- connection.resurrectTimeout = 0
75
- return this
64
+ markAlive(connection) {
65
+ const { id } = connection;
66
+ debug(`Marking as 'alive' connection '${id}'`);
67
+ const index = this.dead.indexOf(id);
68
+ if (index > -1) this.dead.splice(index, 1);
69
+ connection.status = Connection.statuses.ALIVE;
70
+ connection.deadCount = 0;
71
+ connection.resurrectTimeout = 0;
72
+ return this;
76
73
  }
77
74
 
78
75
  /**
@@ -82,9 +79,9 @@ class ConnectionPool extends BaseConnectionPool {
82
79
  *
83
80
  * @param {object} connection
84
81
  */
85
- markDead (connection) {
86
- const { id } = connection
87
- debug(`Marking as 'dead' connection '${id}'`)
82
+ markDead(connection) {
83
+ const { id } = connection;
84
+ debug(`Marking as 'dead' connection '${id}'`);
88
85
  if (this.dead.indexOf(id) === -1) {
89
86
  // It might happen that `markDead` is called jsut after
90
87
  // a pool update, and in such case we will add to the dead
@@ -93,28 +90,29 @@ class ConnectionPool extends BaseConnectionPool {
93
90
  // marking it as dead.
94
91
  for (let i = 0; i < this.size; i++) {
95
92
  if (this.connections[i].id === id) {
96
- this.dead.push(id)
97
- break
93
+ this.dead.push(id);
94
+ break;
98
95
  }
99
96
  }
100
97
  }
101
- connection.status = Connection.statuses.DEAD
102
- connection.deadCount++
98
+ connection.status = Connection.statuses.DEAD;
99
+ connection.deadCount++;
103
100
  // resurrectTimeout formula:
104
101
  // `resurrectTimeout * 2 ** min(deadCount - 1, resurrectTimeoutCutoff)`
105
- connection.resurrectTimeout = Date.now() + this.resurrectTimeout * Math.pow(
106
- 2, Math.min(connection.deadCount - 1, this.resurrectTimeoutCutoff)
107
- )
102
+ connection.resurrectTimeout =
103
+ Date.now() +
104
+ this.resurrectTimeout *
105
+ Math.pow(2, Math.min(connection.deadCount - 1, this.resurrectTimeoutCutoff));
108
106
 
109
107
  // sort the dead list in ascending order
110
108
  // based on the resurrectTimeout
111
109
  this.dead.sort((a, b) => {
112
- const conn1 = this.connections.find(c => c.id === a)
113
- const conn2 = this.connections.find(c => c.id === b)
114
- return conn1.resurrectTimeout - conn2.resurrectTimeout
115
- })
110
+ const conn1 = this.connections.find((c) => c.id === a);
111
+ const conn2 = this.connections.find((c) => c.id === b);
112
+ return conn1.resurrectTimeout - conn2.resurrectTimeout;
113
+ });
116
114
 
117
- return this
115
+ return this;
118
116
  }
119
117
 
120
118
  /**
@@ -124,103 +122,105 @@ class ConnectionPool extends BaseConnectionPool {
124
122
  * @param {object} { now, requestId }
125
123
  * @param {function} callback (isAlive, connection)
126
124
  */
127
- resurrect (opts, callback = noop) {
125
+ resurrect(opts, callback = noop) {
128
126
  if (this.resurrectStrategy === 0 || this.dead.length === 0) {
129
- debug('Nothing to resurrect')
130
- callback(null, null)
131
- return
127
+ debug('Nothing to resurrect');
128
+ callback(null, null);
129
+ return;
132
130
  }
133
131
 
134
132
  // the dead list is sorted in ascending order based on the timeout
135
133
  // so the first element will always be the one with the smaller timeout
136
- const connection = this.connections.find(c => c.id === this.dead[0])
134
+ const connection = this.connections.find((c) => c.id === this.dead[0]);
137
135
  if ((opts.now || Date.now()) < connection.resurrectTimeout) {
138
- debug('Nothing to resurrect')
139
- callback(null, null)
140
- return
136
+ debug('Nothing to resurrect');
137
+ callback(null, null);
138
+ return;
141
139
  }
142
140
 
143
- const { id } = connection
141
+ const { id } = connection;
144
142
 
145
143
  // ping strategy
146
144
  if (this.resurrectStrategy === 1) {
147
- connection.request({
148
- method: 'HEAD',
149
- path: '/',
150
- timeout: this.pingTimeout
151
- }, (err, response) => {
152
- let isAlive = true
153
- const statusCode = response !== null ? response.statusCode : 0
154
- if (err != null ||
155
- (statusCode === 502 || statusCode === 503 || statusCode === 504)) {
156
- debug(`Resurrect: connection '${id}' is still dead`)
157
- this.markDead(connection)
158
- isAlive = false
159
- } else {
160
- debug(`Resurrect: connection '${id}' is now alive`)
161
- this.markAlive(connection)
145
+ connection.request(
146
+ {
147
+ method: 'HEAD',
148
+ path: '/',
149
+ timeout: this.pingTimeout,
150
+ },
151
+ (err, response) => {
152
+ let isAlive = true;
153
+ const statusCode = response !== null ? response.statusCode : 0;
154
+ if (err != null || statusCode === 502 || statusCode === 503 || statusCode === 504) {
155
+ debug(`Resurrect: connection '${id}' is still dead`);
156
+ this.markDead(connection);
157
+ isAlive = false;
158
+ } else {
159
+ debug(`Resurrect: connection '${id}' is now alive`);
160
+ this.markAlive(connection);
161
+ }
162
+ this.emit('resurrect', null, {
163
+ strategy: 'ping',
164
+ name: opts.name,
165
+ request: { id: opts.requestId },
166
+ isAlive,
167
+ connection,
168
+ });
169
+ callback(isAlive, connection);
162
170
  }
163
- this.emit('resurrect', null, {
164
- strategy: 'ping',
165
- name: opts.name,
166
- request: { id: opts.requestId },
167
- isAlive,
168
- connection
169
- })
170
- callback(isAlive, connection)
171
- })
171
+ );
172
172
  // optimistic strategy
173
173
  } else {
174
- debug(`Resurrect: optimistic resurrection for connection '${id}'`)
175
- this.dead.splice(this.dead.indexOf(id), 1)
176
- connection.status = Connection.statuses.ALIVE
174
+ debug(`Resurrect: optimistic resurrection for connection '${id}'`);
175
+ this.dead.splice(this.dead.indexOf(id), 1);
176
+ connection.status = Connection.statuses.ALIVE;
177
177
  this.emit('resurrect', null, {
178
178
  strategy: 'optimistic',
179
179
  name: opts.name,
180
180
  request: { id: opts.requestId },
181
181
  isAlive: true,
182
- connection
183
- })
184
- callback(true, connection) // eslint-disable-line
182
+ connection,
183
+ });
184
+ callback(true, connection); // eslint-disable-line
185
185
  }
186
186
  }
187
187
 
188
188
  /**
189
189
  * Returns an alive connection if present,
190
190
  * otherwise returns a dead connection.
191
- * By default it filters the `master` only nodes.
191
+ * By default it filters the `cluster_manager` or `master` only nodes.
192
192
  * It uses the selector to choose which
193
193
  * connection return.
194
194
  *
195
195
  * @param {object} options (filter and selector)
196
196
  * @returns {object|null} connection
197
197
  */
198
- getConnection (opts = {}) {
199
- const filter = opts.filter || (() => true)
200
- const selector = opts.selector || (c => c[0])
198
+ getConnection(opts = {}) {
199
+ const filter = opts.filter || (() => true);
200
+ const selector = opts.selector || ((c) => c[0]);
201
201
 
202
202
  this.resurrect({
203
203
  now: opts.now,
204
204
  requestId: opts.requestId,
205
- name: opts.name
206
- })
205
+ name: opts.name,
206
+ });
207
207
 
208
- const noAliveConnections = this.size === this.dead.length
208
+ const noAliveConnections = this.size === this.dead.length;
209
209
 
210
210
  // TODO: can we cache this?
211
- const connections = []
211
+ const connections = [];
212
212
  for (let i = 0; i < this.size; i++) {
213
- const connection = this.connections[i]
213
+ const connection = this.connections[i];
214
214
  if (noAliveConnections || connection.status === Connection.statuses.ALIVE) {
215
215
  if (filter(connection) === true) {
216
- connections.push(connection)
216
+ connections.push(connection);
217
217
  }
218
218
  }
219
219
  }
220
220
 
221
- if (connections.length === 0) return null
221
+ if (connections.length === 0) return null;
222
222
 
223
- return selector(connections)
223
+ return selector(connections);
224
224
  }
225
225
 
226
226
  /**
@@ -228,11 +228,11 @@ class ConnectionPool extends BaseConnectionPool {
228
228
  *
229
229
  * @returns {ConnectionPool}
230
230
  */
231
- empty (callback) {
231
+ empty(callback) {
232
232
  super.empty(() => {
233
- this.dead = []
234
- callback()
235
- })
233
+ this.dead = [];
234
+ callback();
235
+ });
236
236
  }
237
237
 
238
238
  /**
@@ -241,17 +241,17 @@ class ConnectionPool extends BaseConnectionPool {
241
241
  * @param {array} array of connections
242
242
  * @returns {ConnectionPool}
243
243
  */
244
- update (connections) {
245
- super.update(connections)
246
- this.dead = []
247
- return this
244
+ update(connections) {
245
+ super.update(connections);
246
+ this.dead = [];
247
+ return this;
248
248
  }
249
249
  }
250
250
 
251
251
  ConnectionPool.resurrectStrategies = {
252
252
  none: 0,
253
253
  ping: 1,
254
- optimistic: 2
255
- }
254
+ optimistic: 2,
255
+ };
256
256
 
257
- module.exports = ConnectionPool
257
+ module.exports = ConnectionPool;
@@ -30,7 +30,7 @@
30
30
 
31
31
  /// <reference types="node" />
32
32
 
33
- import { URL } from 'url'
33
+ import { URL } from 'url';
34
34
  import { SecureContextOptions } from 'tls';
35
35
  import Connection, { AgentOptions } from '../Connection';
36
36
  import { nodeFilterFn, nodeSelectorFn } from '../Transport';
@@ -79,7 +79,6 @@ interface ResurrectEvent {
79
79
  };
80
80
  }
81
81
 
82
-
83
82
  declare class BaseConnectionPool {
84
83
  connections: Connection[];
85
84
  size: number;
@@ -109,7 +108,7 @@ declare class BaseConnectionPool {
109
108
  /**
110
109
  * Returns an alive connection if present,
111
110
  * otherwise returns a dead connection.
112
- * By default it filters the `master` only nodes.
111
+ * By default it filters the `cluster_manager` or `master` only nodes.
113
112
  * It uses the selector to choose which
114
113
  * connection return.
115
114
  *
@@ -181,11 +180,14 @@ declare class ConnectionPool extends BaseConnectionPool {
181
180
  * @param {object} { now, requestId, name }
182
181
  * @param {function} callback (isAlive, connection)
183
182
  */
184
- resurrect(opts: resurrectOptions, callback?: (isAlive: boolean | null, connection: Connection | null) => void): void;
183
+ resurrect(
184
+ opts: resurrectOptions,
185
+ callback?: (isAlive: boolean | null, connection: Connection | null) => void
186
+ ): void;
185
187
  }
186
188
 
187
189
  declare class CloudConnectionPool extends BaseConnectionPool {
188
- cloudConnection: Connection | null
190
+ cloudConnection: Connection | null;
189
191
  constructor(opts?: BaseConnectionPoolOptions);
190
192
  getConnection(): Connection | null;
191
193
  }
@@ -211,5 +213,5 @@ export {
211
213
  // Classes
212
214
  BaseConnectionPool,
213
215
  ConnectionPool,
214
- CloudConnectionPool
216
+ CloudConnectionPool,
215
217
  };
package/lib/pool/index.js CHANGED
@@ -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')
34
- const ConnectionPool = require('./ConnectionPool')
35
- const CloudConnectionPool = require('./CloudConnectionPool')
33
+ const BaseConnectionPool = require('./BaseConnectionPool');
34
+ const ConnectionPool = require('./ConnectionPool');
35
+ const CloudConnectionPool = require('./CloudConnectionPool');
36
36
 
37
37
  module.exports = {
38
38
  BaseConnectionPool,
39
39
  ConnectionPool,
40
- CloudConnectionPool
41
- }
40
+ CloudConnectionPool,
41
+ };
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "./": "./"
12
12
  },
13
13
  "homepage": "https://www.opensearch.org/",
14
- "version": "1.0.0",
14
+ "version": "2.0.0",
15
15
  "versionCanary": "7.10.0-canary.6",
16
16
  "keywords": [
17
17
  "opensearch",
@@ -33,10 +33,10 @@
33
33
  "test:coverage-90": "tap test/{unit,acceptance}/{*,**/*}.test.js --coverage --branches=90 --functions=90 --lines=90 --statements=90 --nyc-arg=\"--exclude=api\"",
34
34
  "test:coverage-report": "tap test/{unit,acceptance}/{*,**/*}.test.js --coverage --branches=90 --functions=90 --lines=90 --statements=90 --nyc-arg=\"--exclude=api\" && nyc report --reporter=text-lcov > coverage.lcov",
35
35
  "test:coverage-ui": "tap test/{unit,acceptance}/{*,**/*}.test.js --coverage --coverage-report=html --nyc-arg=\"--exclude=api\"",
36
- "lint": "standard",
37
- "lint:fix": "standard --fix",
36
+ "lint": "eslint .",
37
+ "lint:fix": "eslint . --fix",
38
38
  "license-checker": "license-checker --production --onlyAllow='MIT;Apache-2.0;Apache1.1;ISC;BSD-3-Clause;BSD-2-Clause'",
39
- "build-esm": "npx gen-esm-wrapper . index.mjs && standard --fix index.mjs"
39
+ "build-esm": "npx gen-esm-wrapper . index.mjs && eslint --fix index.mjs"
40
40
  },
41
41
  "author": "opensearch-project",
42
42
  "original-author": {
@@ -46,11 +46,15 @@
46
46
  "devDependencies": {
47
47
  "@sinonjs/fake-timers": "github:sinonjs/fake-timers#0bfffc1",
48
48
  "@types/node": "^15.3.1",
49
+ "babel-eslint": "^10.1.0",
49
50
  "convert-hrtime": "^5.0.0",
50
51
  "cross-zip": "^4.0.0",
51
52
  "dedent": "^0.7.0",
52
53
  "deepmerge": "^4.2.2",
53
54
  "dezalgo": "^1.0.3",
55
+ "eslint": "^7.32.0",
56
+ "eslint-config-prettier": "^8.5.0",
57
+ "eslint-plugin-prettier": "^4.0.0",
54
58
  "fast-deep-equal": "^3.1.3",
55
59
  "into-stream": "^6.0.0",
56
60
  "js-yaml": "^4.1.0",
@@ -58,14 +62,14 @@
58
62
  "minimist": "^1.2.5",
59
63
  "node-fetch": "^2.6.1",
60
64
  "ora": "^5.4.0",
65
+ "prettier": "^2.6.2",
61
66
  "pretty-hrtime": "^1.0.3",
62
67
  "proxy": "^1.0.2",
63
68
  "rimraf": "^3.0.2",
64
69
  "semver": "^7.3.5",
65
- "simple-git": "^2.39.0",
70
+ "simple-git": "^3.5.0",
66
71
  "simple-statistics": "^7.7.0",
67
72
  "split2": "^3.2.2",
68
- "standard": "^16.0.3",
69
73
  "stoppable": "^1.1.0",
70
74
  "tap": "^15.0.9",
71
75
  "tsd": "^0.15.1",
@@ -87,7 +91,8 @@
87
91
  "url": "https://github.com/opensearch-project/opensearch-js/issues"
88
92
  },
89
93
  "engines": {
90
- "node": ">=10"
94
+ "node": ">=10",
95
+ "yarn": "^1.22.10"
91
96
  },
92
97
  "tsd": {
93
98
  "directory": "test/types"
@@ -99,4 +104,4 @@
99
104
  "coverage": false,
100
105
  "jobs-auto": true
101
106
  }
102
- }
107
+ }