@fastify/elasticsearch 2.1.0 → 3.0.0

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.
@@ -1,49 +1,80 @@
1
1
  name: CI
2
- 'on':
2
+
3
+ on:
3
4
  push:
4
5
  paths-ignore:
5
- - docs/**
6
+ - 'docs/**'
6
7
  - '*.md'
7
8
  pull_request:
8
9
  paths-ignore:
9
- - docs/**
10
+ - 'docs/**'
10
11
  - '*.md'
12
+
11
13
  jobs:
14
+ dependency-review:
15
+ name: Dependency Review
16
+ if: github.event_name == 'pull_request'
17
+ runs-on: ubuntu-latest
18
+ permissions:
19
+ contents: read
20
+ steps:
21
+ - name: Check out repo
22
+ uses: actions/checkout@v3
23
+ with:
24
+ persist-credentials: false
25
+
26
+ - name: Dependency review
27
+ uses: actions/dependency-review-action@v2
28
+
12
29
  test:
13
30
  runs-on: ubuntu-latest
31
+ permissions:
32
+ contents: read
14
33
  strategy:
15
34
  matrix:
16
- node-version:
17
- - 10
18
- - 12
19
- - 14
20
- - 16
21
- services:
22
- elasticsearch:
23
- image: docker.elastic.co/elasticsearch/elasticsearch:7.10.0
24
- ports:
25
- - '9200:9200'
26
- env:
27
- discovery.type: single-node
35
+ node-version: [14, 16, 18]
28
36
  steps:
29
- - uses: actions/checkout@v3
30
- - name: Use Node.js
37
+ - name: Check out repo
38
+ uses: actions/checkout@v3
39
+ with:
40
+ persist-credentials: false
41
+
42
+ - name: Setup Node ${{ matrix.node-version }}
31
43
  uses: actions/setup-node@v3
32
44
  with:
33
45
  node-version: ${{ matrix.node-version }}
34
- - name: Install Dependencies
35
- run: |
36
- npm install --ignore-scripts
37
- - name: Run Tests
46
+
47
+ - name: Configure sysctl limits
38
48
  run: |
39
- npm test
49
+ sudo swapoff -a
50
+ sudo sysctl -w vm.swappiness=1
51
+ sudo sysctl -w fs.file-max=262144
52
+ sudo sysctl -w vm.max_map_count=262144
53
+
54
+ - name: Runs Elasticsearch
55
+ uses: elastic/elastic-github-actions/elasticsearch@562b8b6ae4677da97273ff6bc4d630ce96ecbaa5
56
+ with:
57
+ stack-version: 8.3.2
58
+ security-enabled: false
59
+
60
+ - name: Install dependencies
61
+ run: npm i --ignore-scripts
62
+
63
+ - name: Run tests
64
+ run: npm test
65
+
40
66
  automerge:
67
+ name: Automerge Dependabot PRs
68
+ if: >
69
+ github.event_name == 'pull_request' &&
70
+ github.event.pull_request.user.login == 'dependabot[bot]'
41
71
  needs: test
42
- runs-on: ubuntu-latest
43
72
  permissions:
44
73
  pull-requests: write
45
74
  contents: write
75
+ runs-on: ubuntu-latest
46
76
  steps:
47
77
  - uses: fastify/github-action-merge-dependabot@v3
48
78
  with:
49
79
  github-token: ${{ secrets.GITHUB_TOKEN }}
80
+ target: major
package/README.md CHANGED
@@ -1,8 +1,7 @@
1
- # fastify-elasticsearch
1
+ # @fastify/elasticsearch
2
2
 
3
3
  ![CI](https://github.com/fastify/fastify-elasticsearch/workflows/CI/badge.svg)
4
- [![NPM version](https://img.shields.io/npm/v/fastify-elasticsearch.svg?style=flat)](https://www.npmjs.com/package/fastify-elasticsearch)
5
- [![Known Vulnerabilities](https://snyk.io/test/github/fastify/fastify-elasticsearch/badge.svg)](https://snyk.io/test/github/fastify/fastify-elasticsearch)
4
+ [![NPM version](https://img.shields.io/npm/v/@fastify/elasticsearch.svg?style=flat)](https://www.npmjs.com/package/@fastify/elasticsearch)
6
5
  [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)
7
6
 
8
7
  Fastify plugin for [Elasticsearch](https://www.elastic.co/elasticsearch/) for sharing the same ES client in every part of your server.
@@ -12,7 +11,7 @@ Under the hood, the official [elasticsearch](https://www.npmjs.com/package/@elas
12
11
  ## Install
13
12
 
14
13
  ```
15
- npm i fastify-elasticsearch
14
+ npm i @fastify/elasticsearch
16
15
  ```
17
16
 
18
17
  ## Usage
@@ -22,7 +21,7 @@ The plugin accepts the [same options](https://github.com/elastic/elasticsearch-j
22
21
  ```js
23
22
  const fastify = require('fastify')()
24
23
 
25
- fastify.register(require('fastify-elasticsearch'), { node: 'http://localhost:9200' })
24
+ fastify.register(require('@fastify/elasticsearch'), { node: 'http://localhost:9200' })
26
25
 
27
26
  fastify.get('/user', async function (req, reply) {
28
27
  const { body } = await this.elastic.search({
@@ -35,14 +34,14 @@ fastify.get('/user', async function (req, reply) {
35
34
  return body.hits.hits
36
35
  })
37
36
 
38
- fastify.listen(3000, err => {
37
+ fastify.listen({ port: 3000 }, err => {
39
38
  if (err) throw err
40
39
  })
41
40
  ```
42
41
 
43
- By default, `fastify-elasticsearch` will try to ping the cluster as soon as you start Fastify, but in some cases pinging may not be supported due to the user permissions. If you want, you can disable the initial ping with the `healthcheck` option:
42
+ By default, `@fastify/elasticsearch` will try to ping the cluster as soon as you start Fastify, but in some cases pinging may not be supported due to the user permissions. If you want, you can disable the initial ping with the `healthcheck` option:
44
43
  ```js
45
- fastify.register(require('fastify-elasticsearch'), {
44
+ fastify.register(require('@fastify/elasticsearch'), {
46
45
  node: 'http://localhost:9200',
47
46
  healthcheck: false
48
47
  })
@@ -52,12 +51,12 @@ If you need to connect to different clusters, you can also pass a `namespace` op
52
51
  ```js
53
52
  const fastify = require('fastify')()
54
53
 
55
- fastify.register(require('fastify-elasticsearch'), {
54
+ fastify.register(require('@fastify/elasticsearch'), {
56
55
  node: 'http://localhost:9200',
57
56
  namespace: 'cluster1'
58
57
  })
59
58
 
60
- fastify.register(require('fastify-elasticsearch'), {
59
+ fastify.register(require('@fastify/elasticsearch'), {
61
60
  node: 'http://localhost:9201',
62
61
  namespace: 'cluster2'
63
62
  })
@@ -73,7 +72,7 @@ fastify.get('/user', async function (req, reply) {
73
72
  return body.hits.hits
74
73
  })
75
74
 
76
- fastify.listen(3000, err => {
75
+ fastify.listen({ port: 3000 }, err => {
77
76
  if (err) throw err
78
77
  })
79
78
  ```
@@ -85,7 +84,7 @@ If it is not, you can pass a custom client via the `client` option.
85
84
  const fastify = require('fastify')()
86
85
  const { Client } = require('@elastic/elasticsearch')
87
86
 
88
- fastify.register(require('fastify-elasticsearch'), {
87
+ fastify.register(require('@fastify/elasticsearch'), {
89
88
  client: new Client({ node: 'http://localhost:9200' })
90
89
  })
91
90
 
@@ -100,7 +99,7 @@ fastify.get('/user', async function (req, reply) {
100
99
  return body.hits.hits
101
100
  })
102
101
 
103
- fastify.listen(3000, err => {
102
+ fastify.listen({ port: 3000 }, err => {
104
103
  if (err) throw err
105
104
  })
106
105
  ```
package/es-docker.sh CHANGED
@@ -6,5 +6,6 @@
6
6
  exec docker run \
7
7
  --rm \
8
8
  -e "discovery.type=single-node" \
9
+ -e "xpack.security.enabled=false" \
9
10
  -p 9200:9200 \
10
- docker.elastic.co/elasticsearch/elasticsearch:7.4.0
11
+ docker.elastic.co/elasticsearch/elasticsearch:8.3.2
package/index.js CHANGED
@@ -25,19 +25,20 @@ async function fastifyElasticsearch (fastify, options) {
25
25
 
26
26
  fastify.elastic[namespace] = client
27
27
 
28
- fastify.addHook('onClose', (instance, done) => {
29
- instance.elastic[namespace].close(done)
28
+ fastify.addHook('onClose', async (instance) => {
29
+ // v8 client.close returns a promise and does not accept a callback
30
+ await instance.elastic[namespace].close()
30
31
  })
31
32
  } else {
32
33
  fastify
33
34
  .decorate('elastic', client)
34
- .addHook('onClose', (instance, done) => {
35
- instance.elastic.close(done)
35
+ .addHook('onClose', async (instance) => {
36
+ await instance.elastic.close()
36
37
  })
37
38
  }
38
39
  }
39
40
 
40
41
  module.exports = fp(fastifyElasticsearch, {
41
- fastify: '3.x',
42
- name: 'fastify-elasticsearch'
42
+ fastify: '4.x',
43
+ name: '@fastify/elasticsearch'
43
44
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fastify/elasticsearch",
3
- "version": "2.1.0",
3
+ "version": "3.0.0",
4
4
  "description": "Fastify plugin for elastic search",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -25,15 +25,12 @@
25
25
  "url": "https://github.com/fastify/fastify-elasticsearch/issues"
26
26
  },
27
27
  "homepage": "https://github.com/fastify/fastify-elasticsearch#readme",
28
- "engines": {
29
- "node": ">=10.0.0"
30
- },
31
28
  "dependencies": {
32
- "@elastic/elasticsearch": "^7.1.0",
33
- "fastify-plugin": "^3.0.0"
29
+ "@elastic/elasticsearch": "^8.2.1",
30
+ "fastify-plugin": "^4.0.0"
34
31
  },
35
32
  "devDependencies": {
36
- "fastify": "^3.0.0-rc.1",
33
+ "fastify": "^4.0.0-rc.2",
37
34
  "pre-commit": "^1.2.2",
38
35
  "snazzy": "^9.0.0",
39
36
  "standard": "^17.0.0",
package/test.js CHANGED
@@ -7,15 +7,16 @@ const fastifyElasticsearch = require('./index')
7
7
 
8
8
  test('with reachable cluster', async t => {
9
9
  const fastify = Fastify()
10
+ t.teardown(() => fastify.close())
10
11
  fastify.register(fastifyElasticsearch, { node: 'http://localhost:9200' })
11
12
 
12
13
  await fastify.ready()
13
- t.strictEqual(fastify.elastic.name, 'elasticsearch-js')
14
- await fastify.close()
14
+ t.equal(fastify.elastic.name, 'elasticsearch-js')
15
15
  })
16
16
 
17
17
  test('with unreachable cluster', async t => {
18
18
  const fastify = Fastify()
19
+ t.teardown(() => fastify.close())
19
20
  fastify.register(fastifyElasticsearch, { node: 'http://localhost:9201' })
20
21
 
21
22
  try {
@@ -23,12 +24,12 @@ test('with unreachable cluster', async t => {
23
24
  t.fail('should not boot successfully')
24
25
  } catch (err) {
25
26
  t.ok(err)
26
- await fastify.close()
27
27
  }
28
28
  })
29
29
 
30
30
  test('with unreachable cluster and healthcheck disabled', async t => {
31
31
  const fastify = Fastify()
32
+ t.teardown(() => fastify.close())
32
33
  fastify.register(fastifyElasticsearch, {
33
34
  node: 'http://localhost:9201',
34
35
  healthcheck: false
@@ -36,27 +37,27 @@ test('with unreachable cluster and healthcheck disabled', async t => {
36
37
 
37
38
  try {
38
39
  await fastify.ready()
39
- t.strictEqual(fastify.elastic.name, 'elasticsearch-js')
40
+ t.equal(fastify.elastic.name, 'elasticsearch-js')
40
41
  } catch (err) {
41
42
  t.fail('should not error')
42
43
  }
43
- await fastify.close()
44
44
  })
45
45
 
46
46
  test('namespaced', async t => {
47
47
  const fastify = Fastify()
48
+ t.teardown(() => fastify.close())
48
49
  fastify.register(fastifyElasticsearch, {
49
50
  node: 'http://localhost:9200',
50
51
  namespace: 'cluster'
51
52
  })
52
53
 
53
54
  await fastify.ready()
54
- t.strictEqual(fastify.elastic.cluster.name, 'elasticsearch-js')
55
- await fastify.close()
55
+ t.equal(fastify.elastic.cluster.name, 'elasticsearch-js')
56
56
  })
57
57
 
58
58
  test('namespaced (errored)', async t => {
59
59
  const fastify = Fastify()
60
+ t.teardown(() => fastify.close())
60
61
  fastify.register(fastifyElasticsearch, {
61
62
  node: 'http://localhost:9200',
62
63
  namespace: 'cluster'
@@ -72,7 +73,6 @@ test('namespaced (errored)', async t => {
72
73
  t.fail('should not boot successfully')
73
74
  } catch (err) {
74
75
  t.ok(err)
75
- await fastify.close()
76
76
  }
77
77
  })
78
78
 
@@ -83,15 +83,16 @@ test('custom client', async t => {
83
83
  })
84
84
 
85
85
  const fastify = Fastify()
86
+ t.teardown(() => fastify.close())
86
87
  fastify.register(fastifyElasticsearch, { client })
87
88
 
88
89
  await fastify.ready()
89
- t.strictEqual(fastify.elastic.name, 'custom')
90
- await fastify.close()
90
+ t.equal(fastify.elastic.name, 'custom')
91
91
  })
92
92
 
93
93
  test('Missing configuration', async t => {
94
94
  const fastify = Fastify()
95
+ t.teardown(() => fastify.close())
95
96
  fastify.register(fastifyElasticsearch)
96
97
 
97
98
  try {
@@ -99,6 +100,5 @@ test('Missing configuration', async t => {
99
100
  t.fail('should not boot successfully')
100
101
  } catch (err) {
101
102
  t.ok(err)
102
- await fastify.close()
103
103
  }
104
104
  })