Skip to content

Commit 3b9e2da

Browse files
authored
Upgrade to fastify v3 (#47)
1 parent 6484bb4 commit 3b9e2da

File tree

8 files changed

+55
-66
lines changed

8 files changed

+55
-66
lines changed

.dependabot/config.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
version: 1
2+
update_configs:
3+
- package_manager: "javascript"
4+
directory: "/"
5+
update_schedule: "daily"

.github/workflows/ci.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: CI workflow
2+
on: [push, pull_request]
3+
jobs:
4+
test:
5+
runs-on: ubuntu-latest
6+
strategy:
7+
matrix:
8+
node-version: [10.x, 12.x, 14.x]
9+
services:
10+
redis:
11+
image: redis
12+
ports:
13+
- 6379:6379
14+
options: --entrypoint redis-server
15+
steps:
16+
- uses: actions/checkout@v2
17+
- name: Use Node.js ${{ matrix.node-version }}
18+
uses: actions/setup-node@v1
19+
with:
20+
node-version: ${{ matrix.node-version }}
21+
- name: Install Dependencies
22+
run: npm install --ignore-scripts
23+
- name: Test
24+
run: npm test

.travis.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# fastify-redis
22

3-
[![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/)
3+
[![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)
44

55
Fastify Redis connection plugin, with this you can share the same Redis connection in every part of your server.
66

index.d.ts

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,14 @@
1-
import * as Fastify from 'fastify';
1+
import Fastify, { FastifyPlugin } from 'fastify';
22
import { Redis, RedisOptions } from 'ioredis';
33

4-
import { Server, IncomingMessage, ServerResponse } from 'http';
5-
import { Http2Server, Http2SecureServer, Http2ServerRequest, Http2ServerResponse } from 'http2';
6-
74
declare module 'fastify' {
8-
interface FastifyInstance<HttpServer, HttpRequest, HttpResponse> {
5+
interface FastifyInstance {
96
redis: Redis;
107
}
118
}
129

13-
declare interface FastifyRedisPlugin<HttpServer, HttpRequest, HttpResponse>
14-
extends Fastify.Plugin<
15-
HttpServer,
16-
HttpRequest,
17-
HttpResponse,
18-
RedisOptions | { client: Redis }
19-
> {}
20-
10+
export type FastifyRedisPlugin = RedisOptions | { client: Redis }
2111

22-
declare const fastifyRedis: FastifyRedisPlugin<
23-
Server | Http2Server | Http2SecureServer,
24-
IncomingMessage | Http2ServerRequest,
25-
ServerResponse | Http2ServerResponse
26-
>;
12+
declare const fastifyRedis: FastifyPlugin<FastifyRedisPlugin>;
2713

28-
export = fastifyRedis;
14+
export default fastifyRedis;

package.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"test": "npm run lint && npm run unit && npm run typescript",
99
"lint": "standard",
1010
"unit": "tap test/test.js",
11-
"typescript": "tsc --project ./test/types/tsconfig.json",
11+
"typescript": "tsd",
1212
"redis": "docker run -p 6379:6379 --rm redis:5"
1313
},
1414
"repository": {
@@ -32,19 +32,18 @@
3232
"devDependencies": {
3333
"@types/ioredis": "^4.0.18",
3434
"@types/node": "^12.11.1",
35-
"fastify": "^2.5.0",
35+
"fastify": "^3.0.0-rc.1",
3636
"proxyquire": "^2.1.3",
3737
"redis": "^2.8.0",
3838
"standard": "^14.0.2",
39-
"tap": "^12.7.0"
39+
"tap": "^12.7.0",
40+
"tsd": "^0.11.0"
4041
},
4142
"dependencies": {
42-
"fastify-plugin": "^1.6.0",
43+
"fastify-plugin": "^2.0.0",
4344
"ioredis": "^4.10.0"
4445
},
45-
"greenkeeper": {
46-
"ignore": [
47-
"tap"
48-
]
46+
"tsd": {
47+
"directory": "test/types"
4948
}
5049
}

test/types/index.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
import * as Fastify from 'fastify';
2-
import * as fastifyRedis from '../..';
1+
import Fastify, { FastifyRequest } from 'fastify';
2+
import fastifyRedis from '../..';
33
import * as IORedis from 'ioredis';
44

5-
import * as http from 'http';
6-
import * as http2 from 'http2';
7-
8-
const app: Fastify.FastifyInstance<
9-
http.Server | http2.Http2Server | http2.Http2SecureServer,
10-
http.IncomingMessage | http2.Http2ServerRequest,
11-
http.ServerResponse | http2.Http2ServerResponse
12-
> = Fastify();
5+
const app = Fastify();
136
const redis = new IORedis({ host: 'localhost', port: 6379 });
147

158
app.register(fastifyRedis, { host: '127.0.0.1' });
169
app.register(fastifyRedis, { client: redis });
1710

18-
app.get('/foo', (req, reply) => {
11+
app.get('/foo', (req: FastifyRequest, reply) => {
1912
const { redis } = app;
20-
redis.get(req.query.key, (err, val) => {
13+
const query = req.query as {
14+
key: string
15+
}
16+
redis.get(query.key, (err, val) => {
2117
reply.send(err || val);
2218
});
2319
});
2420

2521
app.post('/foo', (req, reply) => {
2622
const { redis } = app;
27-
redis.set(req.body.key, req.body.value, err => {
23+
const body = req.body as {
24+
key: string,
25+
value: string
26+
}
27+
redis.set(body.key, body.value, err => {
2828
reply.send(err || { status: 'ok' });
2929
});
3030
});

test/types/tsconfig.json

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)