diff --git a/.dependabot/config.yml b/.dependabot/config.yml new file mode 100644 index 0000000..cae63e3 --- /dev/null +++ b/.dependabot/config.yml @@ -0,0 +1,5 @@ +version: 1 +update_configs: + - package_manager: "javascript" + directory: "/" + update_schedule: "daily" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..ae589bb --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,24 @@ +name: CI workflow +on: [push, pull_request] +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [10.x, 12.x, 14.x] + services: + redis: + image: redis + ports: + - 6379:6379 + options: --entrypoint redis-server + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - name: Install Dependencies + run: npm install --ignore-scripts + - name: Test + run: npm test \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index aee56aa..0000000 --- a/.travis.yml +++ /dev/null @@ -1,16 +0,0 @@ -language: node_js - -node_js: - - "14" - - "12" - - "10" - - "8" - - "6" - -services: - - redis-server - -notifications: - email: - on_success: never - on_failure: always diff --git a/README.md b/README.md index 4cb2598..3389659 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # fastify-redis -[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/) [![Build Status](https://travis-ci.org/fastify/fastify-redis.svg?branch=master)](https://travis-ci.org/fastify/fastify-redis) [![Greenkeeper badge](https://badges.greenkeeper.io/fastify/fastify-redis.svg)](https://greenkeeper.io/) +[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/) ![CI workflow](https://github.com/fastify/fastify-redis/workflows/CI%20workflow/badge.svg) Fastify Redis connection plugin, with this you can share the same Redis connection in every part of your server. diff --git a/index.d.ts b/index.d.ts index 4c9b0ad..16bd1b6 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,28 +1,14 @@ -import * as Fastify from 'fastify'; +import Fastify, { FastifyPlugin } from 'fastify'; import { Redis, RedisOptions } from 'ioredis'; -import { Server, IncomingMessage, ServerResponse } from 'http'; -import { Http2Server, Http2SecureServer, Http2ServerRequest, Http2ServerResponse } from 'http2'; - declare module 'fastify' { - interface FastifyInstance { + interface FastifyInstance { redis: Redis; } } -declare interface FastifyRedisPlugin - extends Fastify.Plugin< - HttpServer, - HttpRequest, - HttpResponse, - RedisOptions | { client: Redis } - > {} - +export type FastifyRedisPlugin = RedisOptions | { client: Redis } -declare const fastifyRedis: FastifyRedisPlugin< - Server | Http2Server | Http2SecureServer, - IncomingMessage | Http2ServerRequest, - ServerResponse | Http2ServerResponse ->; +declare const fastifyRedis: FastifyPlugin; -export = fastifyRedis; +export default fastifyRedis; diff --git a/package.json b/package.json index 3acc141..f2327fd 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "test": "npm run lint && npm run unit && npm run typescript", "lint": "standard", "unit": "tap test/test.js", - "typescript": "tsc --project ./test/types/tsconfig.json", + "typescript": "tsd", "redis": "docker run -p 6379:6379 --rm redis:5" }, "repository": { @@ -32,19 +32,18 @@ "devDependencies": { "@types/ioredis": "^4.0.18", "@types/node": "^12.11.1", - "fastify": "^2.5.0", + "fastify": "^3.0.0-rc.1", "proxyquire": "^2.1.3", "redis": "^2.8.0", "standard": "^14.0.2", - "tap": "^12.7.0" + "tap": "^12.7.0", + "tsd": "^0.11.0" }, "dependencies": { - "fastify-plugin": "^1.6.0", + "fastify-plugin": "^2.0.0", "ioredis": "^4.10.0" }, - "greenkeeper": { - "ignore": [ - "tap" - ] + "tsd": { + "directory": "test/types" } } diff --git a/test/types/index.ts b/test/types/index.ts index 8cde0f5..af35e1c 100644 --- a/test/types/index.ts +++ b/test/types/index.ts @@ -1,30 +1,30 @@ -import * as Fastify from 'fastify'; -import * as fastifyRedis from '../..'; +import Fastify, { FastifyRequest } from 'fastify'; +import fastifyRedis from '../..'; import * as IORedis from 'ioredis'; -import * as http from 'http'; -import * as http2 from 'http2'; - -const app: Fastify.FastifyInstance< - http.Server | http2.Http2Server | http2.Http2SecureServer, - http.IncomingMessage | http2.Http2ServerRequest, - http.ServerResponse | http2.Http2ServerResponse - > = Fastify(); +const app = Fastify(); const redis = new IORedis({ host: 'localhost', port: 6379 }); app.register(fastifyRedis, { host: '127.0.0.1' }); app.register(fastifyRedis, { client: redis }); -app.get('/foo', (req, reply) => { +app.get('/foo', (req: FastifyRequest, reply) => { const { redis } = app; - redis.get(req.query.key, (err, val) => { + const query = req.query as { + key: string + } + redis.get(query.key, (err, val) => { reply.send(err || val); }); }); app.post('/foo', (req, reply) => { const { redis } = app; - redis.set(req.body.key, req.body.value, err => { + const body = req.body as { + key: string, + value: string + } + redis.set(body.key, body.value, err => { reply.send(err || { status: 'ok' }); }); }); diff --git a/test/types/tsconfig.json b/test/types/tsconfig.json deleted file mode 100644 index b170f36..0000000 --- a/test/types/tsconfig.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "compilerOptions": { - "target": "es6", - "module": "commonjs", - "noEmit": true, - "strict": true - }, - "files": ["./index.ts"] -}