Skip to content

Commit

Permalink
Support elastic client 8 (#177)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniele Fedeli <danielefedeli@MacBook-Air.station>
  • Loading branch information
DanieleFedeli and Daniele Fedeli committed Oct 17, 2023
1 parent a4d2f55 commit 52bb803
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion lib.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export type Options = Pick<ClientOptions, 'node' | 'auth' | 'cloud' | 'caFingerp
/** @deprecated use `tls.rejectUnauthorized` instead */
rejectUnauthorized?: boolean

tls?: ClientOptions['ssl'];
tls?: ClientOptions['tls'];
}

export type Index = string | `${string | ''}%{DATE}${string | ''}` | ((logTime: string) => string)
Expand Down
4 changes: 2 additions & 2 deletions lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function pinoElasticSearch (opts = {}) {
if (typeof value === 'object' && value.hasOwnProperty('time')) {
if (
(typeof value.time === 'string' && value.time.length) ||
(typeof value.time === 'number' && value.time >= 0)
(typeof value.time === 'number' && value.time >= 0)
) {
return new Date(value.time).toISOString()
}
Expand Down Expand Up @@ -140,7 +140,7 @@ function pinoElasticSearch (opts = {}) {

const client = new Client(clientOpts)

client.on('resurrect', () => {
client.diagnostic.on('resurrect', () => {
initializeBulkHandler(opts, client, splitter)
})

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"tsd": "^0.29.0"
},
"dependencies": {
"@elastic/elasticsearch": "^7.17.12",
"@elastic/elasticsearch": "^8.0.0",
"minimist": "^1.2.5",
"pump": "^3.0.0",
"split2": "^4.0.0"
Expand Down
2 changes: 1 addition & 1 deletion test/acceptance.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ beforeEach(async () => {
await esWaitCluster()
}

const { body: { version } } = await client.info()
const { version } = await client.info()
esVersion = Number(version.number.split('.')[0])
esMinor = Number(version.number.split('.')[1])
await client.indices.delete({ index }, { ignore: [404] })
Expand Down
40 changes: 20 additions & 20 deletions test/unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test('make sure log is a valid json', (t) => {
const Client = function (config) {
t.equal(config.node, options.node)
}
Client.prototype.on = () => {}
Client.prototype.diagnostic = { on: () => {} }
Client.prototype.helpers = {
async bulk (opts) {
for await (const chunk of opts.datasource) {
Expand All @@ -52,7 +52,7 @@ test('make sure log is a valid json', (t) => {
test('date can be a number', (t) => {
t.plan(1)
const Client = function (config) {}
Client.prototype.on = () => {}
Client.prototype.diagnostic = { on: () => {} }

const threeDaysInMillis = 3 * 24 * 60 * 60 * 1000
const time = new Date(Date.now() - threeDaysInMillis)
Expand Down Expand Up @@ -81,7 +81,7 @@ test('Uses the type parameter only with ES < 7 / 1', (t) => {
const Client = function (config) {
t.equal(config.node, options.node)
}
Client.prototype.on = () => {}
Client.prototype.diagnostic = { on: () => {} }

Client.prototype.helpers = {
async bulk (opts) {
Expand All @@ -108,7 +108,7 @@ test('Uses the type parameter only with ES < 7 / 1, even with the deprecated `es
const Client = function (config) {
t.equal(config.node, options.node)
}
Client.prototype.on = () => {}
Client.prototype.diagnostic = { on: () => {} }

Client.prototype.helpers = {
async bulk (opts) {
Expand All @@ -135,7 +135,7 @@ test('Uses the type parameter only with ES < 7 / 2', (t) => {
const Client = function (config) {
t.equal(config.node, options.node)
}
Client.prototype.on = () => {}
Client.prototype.diagnostic = { on: () => {} }
Client.prototype.helpers = {
async bulk (opts) {
for await (const chunk of opts.datasource) {
Expand All @@ -160,7 +160,7 @@ test('Uses the type parameter only with ES < 7 / 2, even with the deprecate `es-
const Client = function (config) {
t.equal(config.node, options.node)
}
Client.prototype.on = () => {}
Client.prototype.diagnostic = { on: () => {} }
Client.prototype.helpers = {
async bulk (opts) {
for await (const chunk of opts.datasource) {
Expand All @@ -185,7 +185,7 @@ test('ecs format', (t) => {
const Client = function (config) {
t.equal(config.node, options.node)
}
Client.prototype.on = () => {}
Client.prototype.diagnostic = { on: () => {} }
Client.prototype.helpers = {
async bulk (opts) {
for await (const chunk of opts.datasource) {
Expand Down Expand Up @@ -226,7 +226,7 @@ test('auth and cloud parameters are properly passed to client', (t) => {
t.equal(config.auth, opts.auth)
t.equal(config.cloud, opts.cloud)
}
Client.prototype.on = () => {}
Client.prototype.diagnostic = { on: () => {} }
Client.prototype.helpers = {
async bulk (opts) {}
}
Expand All @@ -249,7 +249,7 @@ test('apiKey is passed through auth param properly to client', (t) => {
t.equal(config.node, opts.node)
t.equal(config.auth, opts.auth)
}
Client.prototype.on = () => {}
Client.prototype.diagnostic = { on: () => {} }
Client.prototype.helpers = {
async bulk (opts) {}
}
Expand All @@ -263,7 +263,7 @@ test('make sure `flushInterval` is passed to bulk request', (t) => {
t.plan(1)

const Client = function (config) {}
Client.prototype.on = () => {}
Client.prototype.diagnostic = { on: () => {} }

Client.prototype.helpers = {
async bulk (opts) {
Expand All @@ -286,7 +286,7 @@ test('make sure deprecated `flush-interval` is passed to bulk request', (t) => {
const flushInterval = 12345

const Client = function (config) {}
Client.prototype.on = () => {}
Client.prototype.diagnostic = { on: () => {} }

Client.prototype.helpers = {
async bulk (opts) {
Expand All @@ -308,7 +308,7 @@ test('make sure `flushBytes` is passed to bulk request', (t) => {
const flushBytes = true

const Client = function (config) {}
Client.prototype.on = () => {}
Client.prototype.diagnostic = { on: () => {} }

Client.prototype.helpers = {
async bulk (opts) {
Expand All @@ -330,7 +330,7 @@ test('make sure deprecated `flush-bytes` is passed to bulk request', (t) => {
const flushBytes = true

const Client = function (config) {}
Client.prototype.on = () => {}
Client.prototype.diagnostic = { on: () => {} }

Client.prototype.helpers = {
async bulk (opts) {
Expand All @@ -350,7 +350,7 @@ test('make sure `opType` is passed to bulk onDocument request', (t) => {
t.plan(2)

const Client = function (config) {}
Client.prototype.on = () => {}
Client.prototype.diagnostic = { on: () => {} }

Client.prototype.helpers = {
async bulk (opts) {
Expand All @@ -373,7 +373,7 @@ test('make sure deprecated `op_type` is passed to bulk onDocument request', (t)
t.plan(2)

const Client = function (config) {}
Client.prototype.on = () => {}
Client.prototype.diagnostic = { on: () => {} }

Client.prototype.helpers = {
async bulk (opts) {
Expand Down Expand Up @@ -401,7 +401,7 @@ test('make sure `@timestamp` is correctly set when `opType` is `create`', (t) =>
time: '2021-09-01T01:01:01.038Z'
}
const Client = function (config) {}
Client.prototype.on = () => {}
Client.prototype.diagnostic = { on: () => {} }

Client.prototype.helpers = {
async bulk (opts) {
Expand All @@ -422,7 +422,7 @@ test('make sure `@timestamp` is correctly set when `opType` is `create`', (t) =>
test('resurrect client connection pool when datasource split is destroyed', (t) => {
let isResurrected = false
const Client = function (config) {}
Client.prototype.on = () => {}
Client.prototype.diagnostic = { on: () => {} }

Client.prototype.helpers = {
bulk: async function (opts) {
Expand Down Expand Up @@ -459,7 +459,7 @@ test('make sure deprecated `rejectUnauthorized` is passed to client constructor'
t.equal(config.ssl.rejectUnauthorized, rejectUnauthorized)
}

Client.prototype.on = () => {}
Client.prototype.diagnostic = { on: () => {} }
Client.prototype.helpers = { async bulk () {} }

const elastic = proxyquire('../', {
Expand All @@ -480,7 +480,7 @@ test('make sure `tls.rejectUnauthorized` is passed to client constructor', (t) =
t.equal(config.ssl.rejectUnauthorized, tls.rejectUnauthorized)
}

Client.prototype.on = () => {}
Client.prototype.diagnostic = { on: () => {} }
Client.prototype.helpers = { async bulk () {} }

const elastic = proxyquire('../', {
Expand All @@ -502,7 +502,7 @@ test('make sure `tls.rejectUnauthorized` overrides deprecated `rejectUnauthorize
t.equal(config.ssl.rejectUnauthorized, tls.rejectUnauthorized)
}

Client.prototype.on = () => {}
Client.prototype.diagnostic = { on: () => {} }
Client.prototype.helpers = { async bulk () {} }

const elastic = proxyquire('../', {
Expand Down

0 comments on commit 52bb803

Please sign in to comment.