Skip to content

Commit 482283a

Browse files
authored
nodenext compatibility (#165)
* nodenext compatibility * non breaking * add back deprecated FastifyRedisPlugin interface * Apply suggestions from code review
1 parent 7cd5976 commit 482283a

File tree

3 files changed

+33
-23
lines changed

3 files changed

+33
-23
lines changed

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,5 @@ module.exports = fp(fastifyRedis, {
122122
fastify: '4.x',
123123
name: '@fastify/redis'
124124
})
125+
module.exports.default = fastifyRedis
126+
module.exports.fastifyRedis = fastifyRedis

types/index.d.ts

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,38 @@
11
import { FastifyPluginCallback } from 'fastify';
22
import { Cluster, Redis, RedisOptions } from 'ioredis';
33

4-
export interface FastifyRedisNamespacedInstance {
5-
[namespace: string]: Redis;
6-
}
7-
8-
export type FastifyRedis = FastifyRedisNamespacedInstance & Redis;
4+
type FastifyRedisPluginType = FastifyPluginCallback<fastifyRedis.FastifyRedisPluginOptions>
95

106
declare module 'fastify' {
117
interface FastifyInstance {
12-
redis: FastifyRedis;
8+
redis: fastifyRedis.FastifyRedis;
139
}
1410
}
1511

16-
export type FastifyRedisPluginOptions = (RedisOptions &
17-
{
18-
url?: string;
19-
namespace?: string;
20-
}) | {
21-
client: Redis | Cluster;
22-
namespace?: string;
23-
closeClient?: boolean;
24-
}
12+
declare namespace fastifyRedis {
2513

26-
/**
27-
* @deprecated Use `FastifyRedisPluginOptions` instead
28-
*/
29-
export type FastifyRedisPlugin = FastifyRedisPluginOptions;
14+
export interface FastifyRedisNamespacedInstance {
15+
[namespace: string]: Redis;
16+
}
17+
18+
export type FastifyRedis = FastifyRedisNamespacedInstance & Redis;
19+
20+
export type FastifyRedisPluginOptions = (RedisOptions &
21+
{
22+
url?: string;
23+
namespace?: string;
24+
}) | {
25+
client: Redis | Cluster;
26+
namespace?: string;
27+
closeClient?: boolean;
28+
}
29+
/*
30+
* @deprecated Use `FastifyRedisPluginOptions` instead
31+
*/
32+
export type FastifyRedisPlugin = FastifyRedisPluginOptions;
33+
export const fastifyRedis: FastifyRedisPluginType
34+
export { fastifyRedis as default }
35+
}
3036

31-
declare const fastifyRedis: FastifyPluginCallback<FastifyRedisPluginOptions>;
32-
export default fastifyRedis;
37+
declare function fastifyRedis(...params: Parameters<FastifyRedisPluginType>): ReturnType<FastifyRedisPluginType>
38+
export = fastifyRedis

types/index.test-d.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Fastify, { FastifyInstance } from 'fastify'
22
import IORedis, { Redis } from 'ioredis'
3-
import { expectAssignable, expectError, expectType } from 'tsd'
4-
import fastifyRedis, { FastifyRedis, FastifyRedisNamespacedInstance, FastifyRedisPluginOptions } from '..'
3+
import { expectAssignable, expectDeprecated, expectError, expectType } from 'tsd'
4+
import fastifyRedis, { FastifyRedis, FastifyRedisPlugin, FastifyRedisNamespacedInstance, FastifyRedisPluginOptions } from '..'
55

66
const app: FastifyInstance = Fastify()
77
const redis: Redis = new IORedis({ host: 'localhost', port: 6379 })
@@ -38,3 +38,5 @@ app.after(() => {
3838
expectType<Redis>(app.redis.one)
3939
expectType<Redis>(app.redis.two)
4040
})
41+
42+
expectDeprecated({} as FastifyRedisPlugin)

0 commit comments

Comments
 (0)