Skip to content

Disable client Helpers in Node.js < 10. #1194

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 3 commits into from
May 14, 2020
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
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