@fastify/elasticsearch 3.0.0 → 4.0.0-pre.fv5.1

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.
package/.gitattributes ADDED
@@ -0,0 +1,2 @@
1
+ # Set default behavior to automatically convert line endings
2
+ * text=auto eol=lf
@@ -2,6 +2,11 @@ name: CI
2
2
 
3
3
  on:
4
4
  push:
5
+ branches:
6
+ - main
7
+ - master
8
+ - next
9
+ - 'v*'
5
10
  paths-ignore:
6
11
  - 'docs/**'
7
12
  - '*.md'
@@ -11,70 +16,8 @@ on:
11
16
  - '*.md'
12
17
 
13
18
  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
-
29
19
  test:
30
- runs-on: ubuntu-latest
31
- permissions:
32
- contents: read
33
- strategy:
34
- matrix:
35
- node-version: [14, 16, 18]
36
- steps:
37
- - name: Check out repo
38
- uses: actions/checkout@v3
39
- with:
40
- persist-credentials: false
41
-
42
- - name: Setup Node ${{ matrix.node-version }}
43
- uses: actions/setup-node@v3
44
- with:
45
- node-version: ${{ matrix.node-version }}
46
-
47
- - name: Configure sysctl limits
48
- run: |
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
-
66
- automerge:
67
- name: Automerge Dependabot PRs
68
- if: >
69
- github.event_name == 'pull_request' &&
70
- github.event.pull_request.user.login == 'dependabot[bot]'
71
- needs: test
72
- permissions:
73
- pull-requests: write
74
- contents: write
75
- runs-on: ubuntu-latest
76
- steps:
77
- - uses: fastify/github-action-merge-dependabot@v3
78
- with:
79
- github-token: ${{ secrets.GITHUB_TOKEN }}
80
- target: major
20
+ uses: fastify/workflows/.github/workflows/plugins-ci-elasticsearch.yml@v4.2.0
21
+ with:
22
+ lint: true
23
+ license-check: true
package/.taprc ADDED
@@ -0,0 +1,2 @@
1
+ files:
2
+ - test/**/*.test.js
package/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  const fp = require('fastify-plugin')
4
4
  const { Client } = require('@elastic/elasticsearch')
5
+ const isElasticsearchClient = require('./lib/isElasticsearchClient')
5
6
 
6
7
  async function fastifyElasticsearch (fastify, options) {
7
8
  const { namespace, healthcheck } = options
@@ -42,3 +43,7 @@ module.exports = fp(fastifyElasticsearch, {
42
43
  fastify: '4.x',
43
44
  name: '@fastify/elasticsearch'
44
45
  })
46
+ module.exports.default = fastifyElasticsearch
47
+ module.exports.fastifyElasticsearch = fastifyElasticsearch
48
+
49
+ module.exports.isElasticsearchClient = isElasticsearchClient
@@ -0,0 +1,7 @@
1
+ 'use strict'
2
+
3
+ const { Client } = require('@elastic/elasticsearch')
4
+
5
+ module.exports = function isElasticsearchClient (value) {
6
+ return value instanceof Client
7
+ }
package/package.json CHANGED
@@ -1,12 +1,15 @@
1
1
  {
2
2
  "name": "@fastify/elasticsearch",
3
- "version": "3.0.0",
3
+ "version": "4.0.0-pre.fv5.1",
4
4
  "description": "Fastify plugin for elastic search",
5
5
  "main": "index.js",
6
+ "type": "commonjs",
7
+ "types": "types/index.d.ts",
6
8
  "scripts": {
7
- "lint": "standard | snazzy",
8
- "test": "npm run lint && npm run unit",
9
- "unit": "tap test.js"
9
+ "lint": "standard",
10
+ "test": "npm run test:unit && npm run test:typescript",
11
+ "test:unit": "tap",
12
+ "test:typescript": "tsd"
10
13
  },
11
14
  "repository": {
12
15
  "type": "git",
@@ -26,15 +29,16 @@
26
29
  },
27
30
  "homepage": "https://github.com/fastify/fastify-elasticsearch#readme",
28
31
  "dependencies": {
29
- "@elastic/elasticsearch": "^8.2.1",
30
- "fastify-plugin": "^4.0.0"
32
+ "@elastic/elasticsearch": "^8.13.1",
33
+ "fastify-plugin": "^4.5.1"
31
34
  },
32
35
  "devDependencies": {
33
- "fastify": "^4.0.0-rc.2",
34
- "pre-commit": "^1.2.2",
35
- "snazzy": "^9.0.0",
36
- "standard": "^17.0.0",
37
- "tap": "^16.0.0"
36
+ "@types/node": "^20.12.7",
37
+ "@fastify/pre-commit": "^2.1.0",
38
+ "fastify": "^4.26.2",
39
+ "standard": "^17.1.0",
40
+ "tap": "^18.7.2",
41
+ "tsd": "^0.31.0"
38
42
  },
39
43
  "publishConfig": {
40
44
  "access": "public"
@@ -3,7 +3,8 @@
3
3
  const { test } = require('tap')
4
4
  const { Client } = require('@elastic/elasticsearch')
5
5
  const Fastify = require('fastify')
6
- const fastifyElasticsearch = require('./index')
6
+ const fastifyElasticsearch = require('..')
7
+ const isElasticsearchClient = require('..').isElasticsearchClient
7
8
 
8
9
  test('with reachable cluster', async t => {
9
10
  const fastify = Fastify()
@@ -53,6 +54,9 @@ test('namespaced', async t => {
53
54
 
54
55
  await fastify.ready()
55
56
  t.equal(fastify.elastic.cluster.name, 'elasticsearch-js')
57
+ t.equal(isElasticsearchClient(fastify.elastic), false)
58
+ t.equal(isElasticsearchClient(fastify.elastic.cluster), true)
59
+ await fastify.close()
56
60
  })
57
61
 
58
62
  test('namespaced (errored)', async t => {
@@ -87,7 +91,9 @@ test('custom client', async t => {
87
91
  fastify.register(fastifyElasticsearch, { client })
88
92
 
89
93
  await fastify.ready()
94
+ t.equal(isElasticsearchClient(fastify.elastic), true)
90
95
  t.equal(fastify.elastic.name, 'custom')
96
+ await fastify.close()
91
97
  })
92
98
 
93
99
  test('Missing configuration', async t => {
@@ -0,0 +1,27 @@
1
+ import type { FastifyPluginAsync } from 'fastify';
2
+ import type { Client, ClientOptions } from '@elastic/elasticsearch';
3
+
4
+ declare module 'fastify' {
5
+ interface FastifyInstance {
6
+ elastic: Client & Record<string, Client>;
7
+ isElasticsearchClient(value: unknown): value is Client
8
+ }
9
+ }
10
+
11
+ type FastifyElasticsearch = FastifyPluginAsync<fastifyElasticsearch.FastifyElasticsearchOptions> & {
12
+ isElasticsearchClient: (value: any) => value is Client
13
+ }
14
+
15
+ declare namespace fastifyElasticsearch {
16
+ export interface FastifyElasticsearchOptions extends ClientOptions {
17
+ namespace?: string;
18
+ healthcheck?: boolean;
19
+ client?: Client;
20
+ }
21
+
22
+ export const fastifyElasticsearch: FastifyElasticsearch
23
+ export { fastifyElasticsearch as default }
24
+ }
25
+
26
+ declare function fastifyElasticsearch(...params: Parameters<FastifyElasticsearch>): ReturnType<FastifyElasticsearch>
27
+ export = fastifyElasticsearch
@@ -0,0 +1,13 @@
1
+ import fastifyElasticsearch from '..';
2
+ import Fastify from 'fastify';
3
+ import { expectAssignable, expectType } from 'tsd';
4
+ import { Client } from '@elastic/elasticsearch';
5
+
6
+
7
+ const fastify = Fastify()
8
+ fastify.register(fastifyElasticsearch, { node: 'http://localhost:9200' })
9
+
10
+ expectType<boolean>(fastify.isElasticsearchClient(fastify.elastic))
11
+ expectType<boolean>(fastify.isElasticsearchClient(fastify.elastic.asyncSearch))
12
+ expectType<boolean>(fastify.isElasticsearchClient(fastify.elastic.aasdf))
13
+ expectAssignable<(value: any) => value is Client>(fastifyElasticsearch.isElasticsearchClient)