Skip to content

Commit

Permalink
Disable client Helpers in Node.js < 10. (#1194)
Browse files Browse the repository at this point in the history
  • Loading branch information
delvedor authored May 14, 2020
1 parent b109f60 commit 22de806
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
- name: Test
run: |
npm run test:unit -- --node-arg=--harmony-async-iteration
npm run test:node8
helpers-integration-test:
name: Helpers integration test
Expand Down
3 changes: 1 addition & 2 deletions docs/helpers.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
The client comes with an handy collection of helpers to give you a more comfortable experience with some APIs.

CAUTION: The client helpers are experimental, and the API may change in the next minor releases.
If you are using the client with Node.js v8 you should run your code with the `--harmony-async-iteration` argument. +
eg: `node --harmony-async-iteration index.js`
The helpers will not work in any Node.js version lower than 10.

=== Bulk Helper
Running Bulk requests can be complex due to the shape of the API, this helper aims to provide a nicer developer experience around the Bulk API.
Expand Down
9 changes: 7 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

'use strict'

const nodeMajor = Number(process.versions.node.split('.')[0])

const { EventEmitter } = require('events')
const { URL } = require('url')
const debug = require('debug')('elasticsearch')
const Transport = require('./lib/Transport')
const Connection = require('./lib/Connection')
const { ConnectionPool, CloudConnectionPool } = require('./lib/pool')
const Helpers = require('./lib/Helpers')
// Helpers works only in Node.js >= 10
const Helpers = nodeMajor < 10 ? null : require('./lib/Helpers')
const Serializer = require('./lib/Serializer')
const errors = require('./lib/errors')
const { ConfigurationError } = errors
Expand Down Expand Up @@ -127,7 +130,9 @@ class Client extends EventEmitter {
opaqueIdPrefix: options.opaqueIdPrefix
})

this.helpers = new Helpers({ client: this, maxRetries: options.maxRetries })
if (Helpers !== null) {
this.helpers = new Helpers({ client: this, maxRetries: options.maxRetries })
}

const apis = buildApi({
makeRequest: this.transport.request.bind(this.transport),
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
],
"scripts": {
"test": "npm run lint && npm run test:unit && npm run test:behavior && npm run test:types",
"test:node8": "npm run lint && tap test/unit/*.test.js -t 300 --no-coverage && npm run test:behavior && npm run test:types",
"test:unit": "tap test/unit/*.test.js test/unit/**/*.test.js -t 300 --no-coverage",
"test:behavior": "tap test/behavior/*.test.js -t 300 --no-coverage",
"test:integration": "node test/integration/index.js",
Expand Down

0 comments on commit 22de806

Please sign in to comment.