Skip to content

Remove Node.js v8 support #1402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .ci/test-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ NODE_JS_VERSION:
- 14
- 12
- 10
- 8

TEST_SUITE:
- free
Expand Down
25 changes: 0 additions & 25 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,6 @@ jobs:
run: |
npm run test:types

test-node-v8:
name: Test
runs-on: ${{ matrix.os }}

strategy:
matrix:
node-version: [8.x]
os: [ubuntu-latest, windows-latest, macOS-latest]

steps:
- uses: actions/checkout@v2

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Install
run: |
npm install

- name: Test
run: |
npm run test:node8

helpers-integration-test:
name: Helpers integration test
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ npm install @elastic/elasticsearch

### Node.js support

NOTE: The minimum supported version of Node.js is `v8`.
NOTE: The minimum supported version of Node.js is `v10`.

The client versioning follows the Elastc Stack versioning, this means that
major, minor, and patch releases are done following a precise schedule that
Expand Down
8 changes: 4 additions & 4 deletions api/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ function handleError (err, callback) {
}

function snakeCaseKeys (acceptedQuerystring, snakeCase, querystring) {
var target = {}
var keys = Object.keys(querystring)
for (var i = 0, len = keys.length; i < len; i++) {
var key = keys[i]
const target = {}
const keys = Object.keys(querystring)
for (let i = 0, len = keys.length; i < len; i++) {
const key = keys[i]
target[snakeCase[key] || key] = querystring[key]
}
return target
Expand Down
6 changes: 3 additions & 3 deletions docs/examples/asStream.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ async function run () {
})

// stream async iteration, available in Node.js ≥ 10
var payload = ''
let payload = ''
body.setEncoding('utf8')
for await (const chunk of body) {
payload += chunk
}
console.log(JSON.parse(payload))

// classic stream callback style
var payload = ''
let payload = ''
body.setEncoding('utf8')
body.on('data', chunk => { payload += chunk })
body.on('error', console.log)
Expand Down Expand Up @@ -101,4 +101,4 @@ fastify.post('/search/:index', async (req, reply) => {
})

fastify.listen(3000)
----
----
4 changes: 2 additions & 2 deletions docs/examples/scroll.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const client = new Client({ node: 'http://localhost:9200' })

// Scroll utility
async function * scrollSearch (params) {
var response = await client.search(params)
let response = await client.search(params)

while (true) {
const sourceHits = response.body.hits.hits
Expand Down Expand Up @@ -190,4 +190,4 @@ async function run () {
}

run().catch(console.log)
----
----
2 changes: 1 addition & 1 deletion docs/examples/sql.query.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async function run () {

const data = body.rows.map(row => {
const obj = {}
for (var i = 0; i < row.length; i++) {
for (let i = 0; i < row.length; i++) {
obj[body.columns[i].name] = row[i]
}
return obj
Expand Down
2 changes: 1 addition & 1 deletion docs/installation.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ To learn more about the supported major versions, please refer to the
[[nodejs-support]]
=== Node.js support

NOTE: The minimum supported version of Node.js is `v8`.
NOTE: The minimum supported version of Node.js is `v10`.

The client versioning follows the {stack} versioning, this means that
major, minor, and patch releases are done following a precise schedule that
Expand Down
31 changes: 9 additions & 22 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ const debug = require('debug')('elasticsearch')
const Transport = require('./lib/Transport')
const Connection = require('./lib/Connection')
const { ConnectionPool, CloudConnectionPool } = require('./lib/pool')
// Helpers works only in Node.js >= 10
const Helpers = nodeMajor < 10 ? /* istanbul ignore next */ null : require('./lib/Helpers')
const Helpers = require('./lib/Helpers')
const Serializer = require('./lib/Serializer')
const errors = require('./lib/errors')
const { ConfigurationError } = errors
Expand All @@ -48,15 +47,6 @@ const kEventEmitter = Symbol('elasticsearchjs-event-emitter')

const ESAPI = require('./api')

/* istanbul ignore next */
if (nodeMajor < 10) {
process.emitWarning('You are using a version of Node.js that is currently in EOL. ' +
'The support for this version will be dropped in 7.12. ' +
'Please refer to https://ela.st/nodejs-support for additional information.',
'DeprecationWarning'
)
}

/* istanbul ignore next */
if (nodeMajor >= 10 && nodeMajor < 12) {
process.emitWarning('You are using a version of Node.js that will reach EOL in April 2021. ' +
Expand Down Expand Up @@ -189,16 +179,13 @@ class Client extends ESAPI {
context: options.context
})

/* istanbul ignore else */
if (Helpers !== null) {
this.helpers = new Helpers({
client: this,
maxRetries: options.maxRetries,
metaHeader: options.enableMetaHeader
? `es=${clientVersion},js=${nodeVersion},t=${clientVersion},hc=${nodeVersion}`
: null
})
}
this.helpers = new Helpers({
client: this,
maxRetries: options.maxRetries,
metaHeader: options.enableMetaHeader
? `es=${clientVersion},js=${nodeVersion},t=${clientVersion},hc=${nodeVersion}`
: null
})
}

get emit () {
Expand All @@ -223,7 +210,7 @@ class Client extends ESAPI {
opts = {}
}

var [namespace, method] = name.split('.')
let [namespace, method] = name.split('.')
if (method == null) {
method = namespace
namespace = null
Expand Down
4 changes: 2 additions & 2 deletions lib/Connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ class Connection {
}

const paramsKeys = Object.keys(params)
for (var i = 0, len = paramsKeys.length; i < len; i++) {
var key = paramsKeys[i]
for (let i = 0, len = paramsKeys.length; i < len; i++) {
const key = paramsKeys[i]
if (key === 'path') {
request.pathname = resolve(request.pathname, params[key])
} else if (key === 'querystring' && !!params[key] === true) {
Expand Down
14 changes: 8 additions & 6 deletions lib/Serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ const { SerializationError, DeserializationError } = require('./errors')
class Serializer {
serialize (object) {
debug('Serializing', object)
let json
try {
var json = JSON.stringify(object)
json = JSON.stringify(object)
} catch (err) {
throw new SerializationError(err.message, object)
}
Expand All @@ -37,8 +38,9 @@ class Serializer {

deserialize (json) {
debug('Deserializing', json)
let object
try {
var object = sjson.parse(json)
object = sjson.parse(json)
} catch (err) {
throw new DeserializationError(err.message, json)
}
Expand All @@ -50,8 +52,8 @@ class Serializer {
if (Array.isArray(array) === false) {
throw new SerializationError('The argument provided is not an array')
}
var ndjson = ''
for (var i = 0, len = array.length; i < len; i++) {
let ndjson = ''
for (let i = 0, len = array.length; i < len; i++) {
if (typeof array[i] === 'string') {
ndjson += array[i] + '\n'
} else {
Expand All @@ -67,8 +69,8 @@ class Serializer {
if (typeof object === 'string') return object
// arrays should be serialized as comma separated list
const keys = Object.keys(object)
for (var i = 0, len = keys.length; i < len; i++) {
var key = keys[i]
for (let i = 0, len = keys.length; i < len; i++) {
const key = keys[i]
// elasticsearch will complain for keys without a value
if (object[key] === undefined) {
delete object[key]
Expand Down
13 changes: 7 additions & 6 deletions lib/Transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class Transport {
callback = options
options = {}
}
var p = null
let p = null

// promises support
if (callback === undefined) {
Expand Down Expand Up @@ -147,9 +147,10 @@ class Transport {
// the size of the stream, we risk to take too much memory.
// Furthermore, copying everytime the stream is very a expensive operation.
const maxRetries = isStream(params.body) || isStream(params.bulkBody)
? 0 : (typeof options.maxRetries === 'number' ? options.maxRetries : this.maxRetries)
? 0
: (typeof options.maxRetries === 'number' ? options.maxRetries : this.maxRetries)
const compression = options.compression !== undefined ? options.compression : this.compression
var request = { abort: noop }
let request = { abort: noop }
const transportReturn = {
then (onFulfilled, onRejected) {
return p.then(onFulfilled, onRejected)
Expand Down Expand Up @@ -525,7 +526,7 @@ function defaultNodeFilter (node) {
}

function roundRobinSelector () {
var current = -1
let current = -1
return function _roundRobinSelector (connections) {
if (++current >= connections.length) {
current = 0
Expand All @@ -540,8 +541,8 @@ function randomSelector (connections) {
}

function generateRequestId () {
var maxInt = 2147483647
var nextReqId = 0
const maxInt = 2147483647
let nextReqId = 0
return function genReqId (params, options) {
return (nextReqId = (nextReqId + 1) & maxInt)
}
Expand Down
6 changes: 3 additions & 3 deletions lib/pool/BaseConnectionPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class BaseConnectionPool {
*/
empty (callback) {
debug('Emptying the connection pool')
var openConnections = this.size
let openConnections = this.size
this.connections.forEach(connection => {
connection.close(() => {
if (--openConnections === 0) {
Expand Down Expand Up @@ -201,7 +201,7 @@ class BaseConnectionPool {
const ids = Object.keys(nodes)
const hosts = []

for (var i = 0, len = ids.length; i < len; i++) {
for (let i = 0, len = ids.length; i < len; i++) {
const node = nodes[ids[i]]
// If there is no protocol in
// the `publish_address` new URL will throw
Expand All @@ -210,7 +210,7 @@ class BaseConnectionPool {
// - hostname/ip:port
// if we encounter the second case, we should
// use the hostname instead of the ip
var address = node.http.publish_address
let address = node.http.publish_address
const parts = address.split('/')
// the url is in the form of hostname/ip:port
if (parts.length > 1) {
Expand Down
9 changes: 4 additions & 5 deletions lib/pool/ConnectionPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class ConnectionPool extends BaseConnectionPool {
// list a node that no longer exist. The following check verify
// that the connection is still part of the pool before
// marking it as dead.
for (var i = 0; i < this.size; i++) {
for (let i = 0; i < this.size; i++) {
if (this.connections[i].id === id) {
this.dead.push(id)
break
Expand Down Expand Up @@ -138,7 +138,7 @@ class ConnectionPool extends BaseConnectionPool {
path: '/',
timeout: this.pingTimeout
}, (err, response) => {
var isAlive = true
let isAlive = true
const statusCode = response !== null ? response.statusCode : 0
if (err != null ||
(statusCode === 502 || statusCode === 503 || statusCode === 504)) {
Expand Down Expand Up @@ -170,8 +170,7 @@ class ConnectionPool extends BaseConnectionPool {
isAlive: true,
connection
})
// eslint-disable-next-line standard/no-callback-literal
callback(true, connection)
callback(true, connection) // eslint-disable-line
}
}

Expand Down Expand Up @@ -199,7 +198,7 @@ class ConnectionPool extends BaseConnectionPool {

// TODO: can we cache this?
const connections = []
for (var i = 0; i < this.size; i++) {
for (let i = 0; i < this.size; i++) {
const connection = this.connections[i]
if (noAliveConnections || connection.status === Connection.statuses.ALIVE) {
if (filter(connection) === true) {
Expand Down
Loading