@elastic/elasticsearch 7.11.0 → 7.14.1
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/README.md +4 -2
- package/api/api/async_search.js +11 -11
- package/api/api/autoscaling.js +12 -12
- package/api/api/bulk.js +4 -4
- package/api/api/cat.js +127 -127
- package/api/api/ccr.js +40 -40
- package/api/api/clear_scroll.js +2 -2
- package/api/api/close_point_in_time.js +2 -2
- package/api/api/cluster.js +36 -36
- package/api/api/count.js +3 -3
- package/api/api/create.js +5 -5
- package/api/api/dangling_indices.js +8 -8
- package/api/api/delete.js +4 -4
- package/api/api/delete_by_query.js +5 -5
- package/api/api/delete_by_query_rethrottle.js +4 -4
- package/api/api/delete_script.js +3 -3
- package/api/api/enrich.js +14 -14
- package/api/api/eql.js +41 -10
- package/api/api/exists.js +4 -4
- package/api/api/exists_source.js +6 -6
- package/api/api/explain.js +4 -4
- package/api/api/features.js +81 -0
- package/api/api/field_caps.js +2 -2
- package/api/api/fleet.js +65 -0
- package/api/api/get.js +4 -4
- package/api/api/get_script.js +3 -3
- package/api/api/get_script_context.js +2 -2
- package/api/api/get_script_languages.js +2 -2
- package/api/api/get_source.js +4 -4
- package/api/api/graph.js +4 -4
- package/api/api/ilm.js +50 -28
- package/api/api/index.js +4 -4
- package/api/api/indices.js +381 -381
- package/api/api/info.js +2 -2
- package/api/api/ingest.js +37 -15
- package/api/api/license.js +14 -14
- package/api/api/logstash.js +125 -0
- package/api/api/mget.js +4 -4
- package/api/api/migration.js +2 -2
- package/api/api/ml.js +338 -208
- package/api/api/monitoring.js +3 -3
- package/api/api/msearch.js +4 -4
- package/api/api/msearch_template.js +4 -4
- package/api/api/mtermvectors.js +3 -3
- package/api/api/nodes.js +12 -12
- package/api/api/open_point_in_time.js +2 -2
- package/api/api/ping.js +2 -2
- package/api/api/put_script.js +5 -5
- package/api/api/rank_eval.js +3 -3
- package/api/api/reindex.js +3 -3
- package/api/api/reindex_rethrottle.js +4 -4
- package/api/api/render_search_template.js +2 -2
- package/api/api/rollup.js +31 -31
- package/api/api/scripts_painless_execute.js +2 -2
- package/api/api/scroll.js +2 -2
- package/api/api/search.js +5 -5
- package/api/api/search_shards.js +2 -2
- package/api/api/search_template.js +4 -4
- package/api/api/searchable_snapshots.js +42 -15
- package/api/api/security.js +464 -86
- package/api/api/shutdown.js +124 -0
- package/api/api/slm.js +21 -21
- package/api/api/snapshot.js +76 -48
- package/api/api/sql.js +96 -12
- package/api/api/ssl.js +2 -2
- package/api/api/tasks.js +7 -7
- package/api/api/terms_enum.js +56 -0
- package/api/api/termvectors.js +3 -3
- package/api/api/text_structure.js +65 -0
- package/api/api/transform.js +25 -25
- package/api/api/update.js +5 -5
- package/api/api/update_by_query.js +4 -4
- package/api/api/update_by_query_rethrottle.js +4 -4
- package/api/api/watcher.js +29 -29
- package/api/api/xpack.js +4 -4
- package/api/index.js +179 -120
- package/api/new.d.ts +1584 -0
- package/api/requestParams.d.ts +203 -7
- package/api/types.d.ts +15455 -0
- package/api/utils.js +4 -4
- package/free-report-junit.xml +3410 -0
- package/index.d.ts +326 -23
- package/index.js +28 -36
- package/lib/Connection.js +6 -4
- package/lib/Helpers.d.ts +4 -2
- package/lib/Helpers.js +31 -17
- package/lib/Serializer.d.ts +5 -0
- package/lib/Serializer.js +17 -6
- package/lib/Transport.d.ts +4 -2
- package/lib/Transport.js +194 -79
- package/lib/errors.d.ts +7 -0
- package/lib/errors.js +26 -2
- package/lib/pool/BaseConnectionPool.js +3 -3
- package/lib/pool/ConnectionPool.js +4 -5
- package/lib/pool/index.d.ts +5 -0
- package/package.json +26 -26
- package/api/kibana.d.ts +0 -485
package/index.js
CHANGED
|
@@ -19,21 +19,23 @@
|
|
|
19
19
|
|
|
20
20
|
'use strict'
|
|
21
21
|
|
|
22
|
-
const nodeMajor = Number(process.versions.node.split('.')[0])
|
|
23
|
-
|
|
24
22
|
const { EventEmitter } = require('events')
|
|
25
23
|
const { URL } = require('url')
|
|
26
24
|
const debug = require('debug')('elasticsearch')
|
|
27
25
|
const Transport = require('./lib/Transport')
|
|
28
26
|
const Connection = require('./lib/Connection')
|
|
29
27
|
const { ConnectionPool, CloudConnectionPool } = require('./lib/pool')
|
|
30
|
-
|
|
31
|
-
const Helpers = nodeMajor < 10 ? /* istanbul ignore next */ null : require('./lib/Helpers')
|
|
28
|
+
const Helpers = require('./lib/Helpers')
|
|
32
29
|
const Serializer = require('./lib/Serializer')
|
|
33
30
|
const errors = require('./lib/errors')
|
|
34
31
|
const { ConfigurationError } = errors
|
|
35
32
|
const { prepareHeaders } = Connection.internals
|
|
36
|
-
|
|
33
|
+
let clientVersion = require('./package.json').version
|
|
34
|
+
/* istanbul ignore next */
|
|
35
|
+
if (clientVersion.includes('-')) {
|
|
36
|
+
// clean prerelease
|
|
37
|
+
clientVersion = clientVersion.slice(0, clientVersion.indexOf('-')) + 'p'
|
|
38
|
+
}
|
|
37
39
|
const nodeVersion = process.versions.node
|
|
38
40
|
|
|
39
41
|
const kInitialOptions = Symbol('elasticsearchjs-initial-options')
|
|
@@ -43,24 +45,6 @@ const kEventEmitter = Symbol('elasticsearchjs-event-emitter')
|
|
|
43
45
|
|
|
44
46
|
const ESAPI = require('./api')
|
|
45
47
|
|
|
46
|
-
/* istanbul ignore next */
|
|
47
|
-
if (nodeMajor < 10) {
|
|
48
|
-
process.emitWarning('You are using a version of Node.js that is currently in EOL. ' +
|
|
49
|
-
'The support for this version will be dropped in 7.12. ' +
|
|
50
|
-
'Please refer to https://ela.st/nodejs-support for additional information.',
|
|
51
|
-
'DeprecationWarning'
|
|
52
|
-
)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/* istanbul ignore next */
|
|
56
|
-
if (nodeMajor >= 10 && nodeMajor < 12) {
|
|
57
|
-
process.emitWarning('You are using a version of Node.js that will reach EOL in April 2021. ' +
|
|
58
|
-
'The support for this version will be dropped in 7.13. ' +
|
|
59
|
-
'Please refer to https://ela.st/nodejs-support for additional information.',
|
|
60
|
-
'DeprecationWarning'
|
|
61
|
-
)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
48
|
class Client extends ESAPI {
|
|
65
49
|
constructor (opts = {}) {
|
|
66
50
|
super({ ConfigurationError })
|
|
@@ -128,9 +112,14 @@ class Client extends ESAPI {
|
|
|
128
112
|
opaqueIdPrefix: null,
|
|
129
113
|
context: null,
|
|
130
114
|
proxy: null,
|
|
131
|
-
enableMetaHeader: true
|
|
115
|
+
enableMetaHeader: true,
|
|
116
|
+
disablePrototypePoisoningProtection: false
|
|
132
117
|
}, opts)
|
|
133
118
|
|
|
119
|
+
if (process.env.ELASTIC_CLIENT_APIVERSIONING === 'true') {
|
|
120
|
+
options.headers = Object.assign({ accept: 'application/vnd.elasticsearch+json; compatible-with=7' }, options.headers)
|
|
121
|
+
}
|
|
122
|
+
|
|
134
123
|
this[kInitialOptions] = options
|
|
135
124
|
this[kExtensions] = []
|
|
136
125
|
this.name = options.name
|
|
@@ -145,7 +134,9 @@ class Client extends ESAPI {
|
|
|
145
134
|
this[kEventEmitter] = options[kChild].eventEmitter
|
|
146
135
|
} else {
|
|
147
136
|
this[kEventEmitter] = new EventEmitter()
|
|
148
|
-
this.serializer = new options.Serializer(
|
|
137
|
+
this.serializer = new options.Serializer({
|
|
138
|
+
disablePrototypePoisoningProtection: options.disablePrototypePoisoningProtection
|
|
139
|
+
})
|
|
149
140
|
this.connectionPool = new options.ConnectionPool({
|
|
150
141
|
pingTimeout: options.pingTimeout,
|
|
151
142
|
resurrectStrategy: options.resurrectStrategy,
|
|
@@ -184,16 +175,13 @@ class Client extends ESAPI {
|
|
|
184
175
|
context: options.context
|
|
185
176
|
})
|
|
186
177
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
: null
|
|
195
|
-
})
|
|
196
|
-
}
|
|
178
|
+
this.helpers = new Helpers({
|
|
179
|
+
client: this,
|
|
180
|
+
maxRetries: options.maxRetries,
|
|
181
|
+
metaHeader: options.enableMetaHeader
|
|
182
|
+
? `es=${clientVersion},js=${nodeVersion},t=${clientVersion},hc=${nodeVersion}`
|
|
183
|
+
: null
|
|
184
|
+
})
|
|
197
185
|
}
|
|
198
186
|
|
|
199
187
|
get emit () {
|
|
@@ -218,7 +206,7 @@ class Client extends ESAPI {
|
|
|
218
206
|
opts = {}
|
|
219
207
|
}
|
|
220
208
|
|
|
221
|
-
|
|
209
|
+
let [namespace, method] = name.split('.')
|
|
222
210
|
if (method == null) {
|
|
223
211
|
method = namespace
|
|
224
212
|
namespace = null
|
|
@@ -267,6 +255,10 @@ class Client extends ESAPI {
|
|
|
267
255
|
}
|
|
268
256
|
|
|
269
257
|
const client = new Client(options)
|
|
258
|
+
// sync product check
|
|
259
|
+
const tSymbol = Object.getOwnPropertySymbols(this.transport)
|
|
260
|
+
.filter(symbol => symbol.description === 'product check')[0]
|
|
261
|
+
client.transport[tSymbol] = this.transport[tSymbol]
|
|
270
262
|
// Add parent extensions
|
|
271
263
|
if (this[kExtensions].length > 0) {
|
|
272
264
|
this[kExtensions].forEach(({ name, opts, fn }) => {
|
package/lib/Connection.js
CHANGED
|
@@ -25,7 +25,7 @@ const hpagent = require('hpagent')
|
|
|
25
25
|
const http = require('http')
|
|
26
26
|
const https = require('https')
|
|
27
27
|
const debug = require('debug')('elasticsearch')
|
|
28
|
-
const
|
|
28
|
+
const { pipeline } = require('stream')
|
|
29
29
|
const INVALID_PATH_REGEX = /[^\u0021-\u00ff]/
|
|
30
30
|
const {
|
|
31
31
|
ConnectionError,
|
|
@@ -133,7 +133,7 @@ class Connection {
|
|
|
133
133
|
|
|
134
134
|
// starts the request
|
|
135
135
|
if (isStream(params.body) === true) {
|
|
136
|
-
|
|
136
|
+
pipeline(params.body, request, err => {
|
|
137
137
|
/* istanbul ignore if */
|
|
138
138
|
if (err != null && cleanedListeners === false) {
|
|
139
139
|
cleanListeners()
|
|
@@ -213,8 +213,8 @@ class Connection {
|
|
|
213
213
|
}
|
|
214
214
|
|
|
215
215
|
const paramsKeys = Object.keys(params)
|
|
216
|
-
for (
|
|
217
|
-
|
|
216
|
+
for (let i = 0, len = paramsKeys.length; i < len; i++) {
|
|
217
|
+
const key = paramsKeys[i]
|
|
218
218
|
if (key === 'path') {
|
|
219
219
|
request.pathname = resolve(request.pathname, params[key])
|
|
220
220
|
} else if (key === 'querystring' && !!params[key] === true) {
|
|
@@ -331,6 +331,8 @@ function prepareHeaders (headers = {}, auth) {
|
|
|
331
331
|
} else {
|
|
332
332
|
headers.authorization = `ApiKey ${auth.apiKey}`
|
|
333
333
|
}
|
|
334
|
+
} else if (auth.bearer) {
|
|
335
|
+
headers.authorization = `Bearer ${auth.bearer}`
|
|
334
336
|
} else if (auth.username && auth.password) {
|
|
335
337
|
headers.authorization = 'Basic ' + Buffer.from(`${auth.username}:${auth.password}`).toString('base64')
|
|
336
338
|
}
|
package/lib/Helpers.d.ts
CHANGED
|
@@ -25,8 +25,8 @@ export default class Helpers {
|
|
|
25
25
|
search<TDocument = unknown, TRequestBody extends RequestBody = Record<string, any>>(params: Search<TRequestBody>, options?: TransportRequestOptions): Promise<TDocument[]>
|
|
26
26
|
scrollSearch<TDocument = unknown, TResponse = Record<string, any>, TRequestBody extends RequestBody = Record<string, any>, TContext = Context>(params: Search<TRequestBody>, options?: TransportRequestOptions): AsyncIterable<ScrollSearchResponse<TDocument, TResponse, TContext>>
|
|
27
27
|
scrollDocuments<TDocument = unknown, TRequestBody extends RequestBody = Record<string, any>>(params: Search<TRequestBody>, options?: TransportRequestOptions): AsyncIterable<TDocument>
|
|
28
|
-
msearch(options?: MsearchHelperOptions): MsearchHelper
|
|
29
|
-
bulk<TDocument = unknown>(options: BulkHelperOptions<TDocument
|
|
28
|
+
msearch(options?: MsearchHelperOptions, reqOptions?: TransportRequestOptions): MsearchHelper
|
|
29
|
+
bulk<TDocument = unknown>(options: BulkHelperOptions<TDocument>, reqOptions?: TransportRequestOptions): BulkHelper<BulkStats>
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
export interface ScrollSearchResponse<TDocument = unknown, TResponse = Record<string, any>, TContext = Context> extends ApiResponse<TResponse, TContext> {
|
|
@@ -36,6 +36,7 @@ export interface ScrollSearchResponse<TDocument = unknown, TResponse = Record<st
|
|
|
36
36
|
|
|
37
37
|
export interface BulkHelper<T> extends Promise<T> {
|
|
38
38
|
abort: () => BulkHelper<T>
|
|
39
|
+
readonly stats: BulkStats
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
export interface BulkStats {
|
|
@@ -43,6 +44,7 @@ export interface BulkStats {
|
|
|
43
44
|
failed: number
|
|
44
45
|
retry: number
|
|
45
46
|
successful: number
|
|
47
|
+
noop: number
|
|
46
48
|
time: number
|
|
47
49
|
bytes: number
|
|
48
50
|
aborted: boolean
|
package/lib/Helpers.js
CHANGED
|
@@ -158,7 +158,7 @@ class Helpers {
|
|
|
158
158
|
*/
|
|
159
159
|
async * scrollDocuments (params, options) {
|
|
160
160
|
appendFilterPath('hits.hits._source', params, true)
|
|
161
|
-
for await (const { documents } of this.scrollSearch(params)) {
|
|
161
|
+
for await (const { documents } of this.scrollSearch(params, options)) {
|
|
162
162
|
for (const document of documents) {
|
|
163
163
|
yield document
|
|
164
164
|
}
|
|
@@ -169,9 +169,10 @@ class Helpers {
|
|
|
169
169
|
* Creates a msearch helper instance. Once you configure it, you can use the provided
|
|
170
170
|
* `search` method to add new searches in the queue.
|
|
171
171
|
* @param {object} options - The configuration of the msearch operations.
|
|
172
|
+
* @param {object} reqOptions - The client optional configuration for this request.
|
|
172
173
|
* @return {object} The possible operations to run.
|
|
173
174
|
*/
|
|
174
|
-
msearch (options = {}) {
|
|
175
|
+
msearch (options = {}, reqOptions = {}) {
|
|
175
176
|
const client = this[kClient]
|
|
176
177
|
const {
|
|
177
178
|
operations = 5,
|
|
@@ -378,7 +379,7 @@ class Helpers {
|
|
|
378
379
|
// This function never returns an error, if the msearch operation fails,
|
|
379
380
|
// the error is dispatched to all search executors.
|
|
380
381
|
function tryMsearch (msearchBody, callbacks, done) {
|
|
381
|
-
client.msearch(Object.assign({}, msearchOptions, { body: msearchBody }), (err, results) => {
|
|
382
|
+
client.msearch(Object.assign({}, msearchOptions, { body: msearchBody }), reqOptions, (err, results) => {
|
|
382
383
|
const retryBody = []
|
|
383
384
|
const retryCallbacks = []
|
|
384
385
|
if (err) {
|
|
@@ -415,12 +416,16 @@ class Helpers {
|
|
|
415
416
|
* Creates a bulk helper instance. Once you configure it, you can pick which operation
|
|
416
417
|
* to execute with the given dataset, index, create, update, and delete.
|
|
417
418
|
* @param {object} options - The configuration of the bulk operation.
|
|
419
|
+
* @param {object} reqOptions - The client optional configuration for this request.
|
|
418
420
|
* @return {object} The possible operations to run with the datasource.
|
|
419
421
|
*/
|
|
420
|
-
bulk (options) {
|
|
422
|
+
bulk (options, reqOptions = {}) {
|
|
421
423
|
const client = this[kClient]
|
|
422
|
-
const {
|
|
423
|
-
|
|
424
|
+
const { serializer } = client
|
|
425
|
+
if (this[kMetaHeader] !== null) {
|
|
426
|
+
reqOptions.headers = reqOptions.headers || {}
|
|
427
|
+
reqOptions.headers['x-elastic-client-meta'] = this[kMetaHeader] + ',h=bp'
|
|
428
|
+
}
|
|
424
429
|
const {
|
|
425
430
|
datasource,
|
|
426
431
|
onDocument,
|
|
@@ -451,6 +456,7 @@ class Helpers {
|
|
|
451
456
|
failed: 0,
|
|
452
457
|
retry: 0,
|
|
453
458
|
successful: 0,
|
|
459
|
+
noop: 0,
|
|
454
460
|
time: 0,
|
|
455
461
|
bytes: 0,
|
|
456
462
|
aborted: false
|
|
@@ -458,6 +464,9 @@ class Helpers {
|
|
|
458
464
|
|
|
459
465
|
const p = iterate()
|
|
460
466
|
const helper = {
|
|
467
|
+
get stats () {
|
|
468
|
+
return stats
|
|
469
|
+
},
|
|
461
470
|
then (onFulfilled, onRejected) {
|
|
462
471
|
return p.then(onFulfilled, onRejected)
|
|
463
472
|
},
|
|
@@ -500,19 +509,19 @@ class Helpers {
|
|
|
500
509
|
? Object.keys(action[0])[0]
|
|
501
510
|
: Object.keys(action)[0]
|
|
502
511
|
if (operation === 'index' || operation === 'create') {
|
|
503
|
-
actionBody = serialize(action)
|
|
504
|
-
payloadBody = typeof chunk === 'string' ? chunk : serialize(chunk)
|
|
512
|
+
actionBody = serializer.serialize(action)
|
|
513
|
+
payloadBody = typeof chunk === 'string' ? chunk : serializer.serialize(chunk)
|
|
505
514
|
chunkBytes += Buffer.byteLength(actionBody) + Buffer.byteLength(payloadBody)
|
|
506
515
|
bulkBody.push(actionBody, payloadBody)
|
|
507
516
|
} else if (operation === 'update') {
|
|
508
|
-
actionBody = serialize(action[0])
|
|
517
|
+
actionBody = serializer.serialize(action[0])
|
|
509
518
|
payloadBody = typeof chunk === 'string'
|
|
510
519
|
? `{"doc":${chunk}}`
|
|
511
|
-
: serialize({ doc: chunk, ...action[1] })
|
|
520
|
+
: serializer.serialize({ doc: chunk, ...action[1] })
|
|
512
521
|
chunkBytes += Buffer.byteLength(actionBody) + Buffer.byteLength(payloadBody)
|
|
513
522
|
bulkBody.push(actionBody, payloadBody)
|
|
514
523
|
} else if (operation === 'delete') {
|
|
515
|
-
actionBody = serialize(action)
|
|
524
|
+
actionBody = serializer.serialize(action)
|
|
516
525
|
chunkBytes += Buffer.byteLength(actionBody)
|
|
517
526
|
bulkBody.push(actionBody)
|
|
518
527
|
} else {
|
|
@@ -545,7 +554,7 @@ class Helpers {
|
|
|
545
554
|
index: typeof refreshOnCompletion === 'string'
|
|
546
555
|
? refreshOnCompletion
|
|
547
556
|
: '_all'
|
|
548
|
-
})
|
|
557
|
+
}, reqOptions)
|
|
549
558
|
}
|
|
550
559
|
|
|
551
560
|
stats.time = Date.now() - startTime
|
|
@@ -664,13 +673,13 @@ class Helpers {
|
|
|
664
673
|
return
|
|
665
674
|
}
|
|
666
675
|
for (let i = 0, len = bulkBody.length; i < len; i = i + 2) {
|
|
667
|
-
const operation = Object.keys(deserialize(bulkBody[i]))[0]
|
|
676
|
+
const operation = Object.keys(serializer.deserialize(bulkBody[i]))[0]
|
|
668
677
|
onDrop({
|
|
669
678
|
status: 429,
|
|
670
679
|
error: null,
|
|
671
|
-
operation: deserialize(bulkBody[i]),
|
|
680
|
+
operation: serializer.deserialize(bulkBody[i]),
|
|
672
681
|
document: operation !== 'delete'
|
|
673
|
-
? deserialize(bulkBody[i + 1])
|
|
682
|
+
? serializer.deserialize(bulkBody[i + 1])
|
|
674
683
|
/* istanbul ignore next */
|
|
675
684
|
: null,
|
|
676
685
|
retried: isRetrying
|
|
@@ -687,6 +696,11 @@ class Helpers {
|
|
|
687
696
|
if (err) return callback(err, null)
|
|
688
697
|
if (body.errors === false) {
|
|
689
698
|
stats.successful += body.items.length
|
|
699
|
+
for (const item of body.items) {
|
|
700
|
+
if (item.update && item.update.result === 'noop') {
|
|
701
|
+
stats.noop++
|
|
702
|
+
}
|
|
703
|
+
}
|
|
690
704
|
return callback(null, [])
|
|
691
705
|
}
|
|
692
706
|
const retry = []
|
|
@@ -711,9 +725,9 @@ class Helpers {
|
|
|
711
725
|
onDrop({
|
|
712
726
|
status: status,
|
|
713
727
|
error: action[operation].error,
|
|
714
|
-
operation: deserialize(bulkBody[indexSlice]),
|
|
728
|
+
operation: serializer.deserialize(bulkBody[indexSlice]),
|
|
715
729
|
document: operation !== 'delete'
|
|
716
|
-
? deserialize(bulkBody[indexSlice + 1])
|
|
730
|
+
? serializer.deserialize(bulkBody[indexSlice + 1])
|
|
717
731
|
: null,
|
|
718
732
|
retried: isRetrying
|
|
719
733
|
})
|
package/lib/Serializer.d.ts
CHANGED
|
@@ -17,7 +17,12 @@
|
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
+
export interface SerializerOptions {
|
|
21
|
+
disablePrototypePoisoningProtection: boolean | 'proto' | 'constructor'
|
|
22
|
+
}
|
|
23
|
+
|
|
20
24
|
export default class Serializer {
|
|
25
|
+
constructor (opts?: SerializerOptions)
|
|
21
26
|
serialize(object: any): string;
|
|
22
27
|
deserialize(json: string): any;
|
|
23
28
|
ndserialize(array: any[]): string;
|
package/lib/Serializer.js
CHANGED
|
@@ -23,12 +23,22 @@ const { stringify } = require('querystring')
|
|
|
23
23
|
const debug = require('debug')('elasticsearch')
|
|
24
24
|
const sjson = require('secure-json-parse')
|
|
25
25
|
const { SerializationError, DeserializationError } = require('./errors')
|
|
26
|
+
const kJsonOptions = Symbol('secure json parse options')
|
|
26
27
|
|
|
27
28
|
class Serializer {
|
|
29
|
+
constructor (opts = {}) {
|
|
30
|
+
const disable = opts.disablePrototypePoisoningProtection
|
|
31
|
+
this[kJsonOptions] = {
|
|
32
|
+
protoAction: disable === true || disable === 'proto' ? 'ignore' : 'error',
|
|
33
|
+
constructorAction: disable === true || disable === 'constructor' ? 'ignore' : 'error'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
28
37
|
serialize (object) {
|
|
29
38
|
debug('Serializing', object)
|
|
39
|
+
let json
|
|
30
40
|
try {
|
|
31
|
-
|
|
41
|
+
json = JSON.stringify(object)
|
|
32
42
|
} catch (err) {
|
|
33
43
|
throw new SerializationError(err.message, object)
|
|
34
44
|
}
|
|
@@ -37,8 +47,9 @@ class Serializer {
|
|
|
37
47
|
|
|
38
48
|
deserialize (json) {
|
|
39
49
|
debug('Deserializing', json)
|
|
50
|
+
let object
|
|
40
51
|
try {
|
|
41
|
-
|
|
52
|
+
object = sjson.parse(json, this[kJsonOptions])
|
|
42
53
|
} catch (err) {
|
|
43
54
|
throw new DeserializationError(err.message, json)
|
|
44
55
|
}
|
|
@@ -50,8 +61,8 @@ class Serializer {
|
|
|
50
61
|
if (Array.isArray(array) === false) {
|
|
51
62
|
throw new SerializationError('The argument provided is not an array')
|
|
52
63
|
}
|
|
53
|
-
|
|
54
|
-
for (
|
|
64
|
+
let ndjson = ''
|
|
65
|
+
for (let i = 0, len = array.length; i < len; i++) {
|
|
55
66
|
if (typeof array[i] === 'string') {
|
|
56
67
|
ndjson += array[i] + '\n'
|
|
57
68
|
} else {
|
|
@@ -67,8 +78,8 @@ class Serializer {
|
|
|
67
78
|
if (typeof object === 'string') return object
|
|
68
79
|
// arrays should be serialized as comma separated list
|
|
69
80
|
const keys = Object.keys(object)
|
|
70
|
-
for (
|
|
71
|
-
|
|
81
|
+
for (let i = 0, len = keys.length; i < len; i++) {
|
|
82
|
+
const key = keys[i]
|
|
72
83
|
// elasticsearch will complain for keys without a value
|
|
73
84
|
if (object[key] === undefined) {
|
|
74
85
|
delete object[key]
|
package/lib/Transport.d.ts
CHANGED
|
@@ -26,9 +26,10 @@ import * as errors from './errors';
|
|
|
26
26
|
export type ApiError = errors.ConfigurationError | errors.ConnectionError |
|
|
27
27
|
errors.DeserializationError | errors.SerializationError |
|
|
28
28
|
errors.NoLivingConnectionsError | errors.ResponseError |
|
|
29
|
-
errors.TimeoutError | errors.RequestAbortedError
|
|
29
|
+
errors.TimeoutError | errors.RequestAbortedError |
|
|
30
|
+
errors.ProductNotSupportedError
|
|
30
31
|
|
|
31
|
-
export type Context =
|
|
32
|
+
export type Context = unknown
|
|
32
33
|
|
|
33
34
|
export interface nodeSelectorFn {
|
|
34
35
|
(connections: Connection[]): Connection;
|
|
@@ -120,6 +121,7 @@ export interface TransportRequestCallback {
|
|
|
120
121
|
|
|
121
122
|
export interface TransportRequestPromise<T> extends Promise<T> {
|
|
122
123
|
abort: () => void;
|
|
124
|
+
finally(onFinally?: (() => void) | undefined | null): Promise<T>;
|
|
123
125
|
}
|
|
124
126
|
|
|
125
127
|
export interface TransportGetConnectionOptions {
|