@fastify/elasticsearch 3.0.0 → 3.1.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.
@@ -24,7 +24,7 @@ jobs:
24
24
  persist-credentials: false
25
25
 
26
26
  - name: Dependency review
27
- uses: actions/dependency-review-action@v2
27
+ uses: actions/dependency-review-action@v3
28
28
 
29
29
  test:
30
30
  runs-on: ubuntu-latest
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,14 @@
1
1
  {
2
2
  "name": "@fastify/elasticsearch",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "Fastify plugin for elastic search",
5
5
  "main": "index.js",
6
+ "types": "types/index.d.ts",
6
7
  "scripts": {
7
- "lint": "standard | snazzy",
8
- "test": "npm run lint && npm run unit",
9
- "unit": "tap test.js"
8
+ "lint": "standard",
9
+ "test": "npm run test:unit && npm run test:typescript",
10
+ "test:unit": "tap",
11
+ "test:typescript": "tsd"
10
12
  },
11
13
  "repository": {
12
14
  "type": "git",
@@ -30,11 +32,12 @@
30
32
  "fastify-plugin": "^4.0.0"
31
33
  },
32
34
  "devDependencies": {
35
+ "@types/node": "^18.6.4",
36
+ "@fastify/pre-commit": "^2.0.2",
33
37
  "fastify": "^4.0.0-rc.2",
34
- "pre-commit": "^1.2.2",
35
- "snazzy": "^9.0.0",
36
38
  "standard": "^17.0.0",
37
- "tap": "^16.0.0"
39
+ "tap": "^16.0.0",
40
+ "tsd": "^0.22.0"
38
41
  },
39
42
  "publishConfig": {
40
43
  "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()
@@ -52,7 +53,10 @@ test('namespaced', async t => {
52
53
  })
53
54
 
54
55
  await fastify.ready()
55
- t.equal(fastify.elastic.cluster.name, 'elasticsearch-js')
56
+ t.strictEqual(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()
90
- t.equal(fastify.elastic.name, 'custom')
94
+ t.equal(isElasticsearchClient(fastify.elastic), true)
95
+ t.strictEqual(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)