diff --git a/types/index.d.ts b/types/index.d.ts index 2f81209..575dfd2 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -103,8 +103,8 @@ declare namespace fastifyWebsocket { Logger extends FastifyBaseLogger = FastifyBaseLogger > extends fastify.RouteOptions, WebsocketRouteOptions { } - export const websocketPlugin: FastifyWebsocket - export { websocketPlugin as default } + export const fastifyWebsocket: FastifyWebsocket + export { fastifyWebsocket as default } } declare function fastifyWebsocket(...params: Parameters): ReturnType diff --git a/types/index.test-d.ts b/types/index.test-d.ts index 8a48e9a..4a8eb77 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -1,4 +1,4 @@ -import wsPlugin, { WebsocketHandler, SocketStream } from '..'; +import fastifyWebsocket, { WebsocketHandler, SocketStream, fastifyWebsocket as namedFastifyWebsocket, default as defaultFastifyWebsocket } from '..'; import type { IncomingMessage } from "http"; import fastify, { RouteOptions, FastifyRequest, FastifyInstance, FastifyReply, RequestGenericInterface, FastifyBaseLogger, RawServerDefault, FastifySchema, RawRequestDefaultExpression, RawServerBase, ContextConfigDefault, RawReplyDefaultExpression } from 'fastify'; import { expectType } from 'tsd'; @@ -9,10 +9,10 @@ import { Static, Type } from '@sinclair/typebox' import { ResolveFastifyRequestType } from 'fastify/types/type-provider'; const app: FastifyInstance = fastify(); -app.register(wsPlugin); -app.register(wsPlugin, {}); -app.register(wsPlugin, { options: { maxPayload: 123 } }); -app.register(wsPlugin, { +app.register(fastifyWebsocket); +app.register(fastifyWebsocket, {}); +app.register(fastifyWebsocket, { options: { maxPayload: 123 } }); +app.register(fastifyWebsocket, { errorHandler: function errorHandler(error: Error, connection: SocketStream, request: FastifyRequest, reply: FastifyReply): void { expectType(this); expectType(error) @@ -21,9 +21,9 @@ app.register(wsPlugin, { expectType(reply) } }); -app.register(wsPlugin, { options: { perMessageDeflate: true } }); -app.register(wsPlugin, { preClose: function syncPreclose() {} }); -app.register(wsPlugin, { preClose: async function asyncPreclose(){} }); +app.register(fastifyWebsocket, { options: { perMessageDeflate: true } }); +app.register(fastifyWebsocket, { preClose: function syncPreclose() {} }); +app.register(fastifyWebsocket, { preClose: async function asyncPreclose(){} }); app.get('/websockets-via-inferrence', { websocket: true }, async function (connection, request) { expectType(this); @@ -197,4 +197,8 @@ server.get('/websockets-no-type-inference', expectType(request.body); expectType(request.query); expectType(request.headers); - }); \ No newline at end of file + }); + + expectType(namedFastifyWebsocket); + expectType(defaultFastifyWebsocket); + \ No newline at end of file