Skip to content

Commit 9c2e538

Browse files
authored
chore: update lint and test types (#21)
1 parent 5da6900 commit 9c2e538

4 files changed

Lines changed: 31 additions & 11 deletions

File tree

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# @fastify/sse
22

3-
[![NPM Version](https://img.shields.io/npm/v/@fastify/sse.svg)](https://npmjs.org/package/@fastify/sse)
3+
[![NPM Version](https://img.shields.io/npm/v/@fastify/sse.svg?style=flat)](https://www.npmjs.com/package/@fastify/sse)
44
[![CI](https://github.com/fastify/sse/workflows/CI/badge.svg)](https://github.com/fastify/sse/actions)
5+
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)
56

67
Server-Sent Events plugin for Fastify. Provides first-class SSE support with clean API integration, session management, and streaming capabilities.
78

@@ -224,11 +225,13 @@ fastify.get('/events', { sse: true }, async (request, reply) => {
224225
### Properties and Methods
225226

226227
#### Properties
228+
227229
- `reply.sse.lastEventId`: Client's last received event ID (string | null)
228230
- `reply.sse.isConnected`: Connection status (boolean)
229231
- `reply.sse.shouldKeepAlive`: Whether connection should be kept alive after handler completion (boolean)
230232

231233
#### Methods
234+
232235
- `reply.sse.send(source)`: Send SSE messages from various source types
233236
- `reply.sse.stream()`: Create a transform stream for pipeline operations
234237
- `reply.sse.keepAlive()`: Prevent connection from auto-closing after handler returns
@@ -399,4 +402,4 @@ See the [examples](examples/) directory for complete working examples:
399402
400403
## License
401404
402-
[MIT](LICENSE)
405+
[MIT](LICENSE)

eslint.config.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
const neostandard = require('neostandard')
1+
'use strict'
22

3-
module.exports = neostandard()
3+
module.exports = require('neostandard')({
4+
ignores: require('neostandard').resolveIgnoresFromGitignore(),
5+
ts: true
6+
})

test-types/index.test-d.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
'use strict'
2+
13
import { expectType, expectError, expectAssignable } from 'tsd'
2-
import fastify, { FastifyInstance, FastifyReply, RouteShorthandOptions } from 'fastify'
4+
import fastify, { FastifyInstance, RouteShorthandOptions } from 'fastify'
35
import fastifySSE, { SSEPluginOptions, SSEMessage, SSESource, SSEReplyInterface } from '..'
46
import { Readable } from 'stream'
57

@@ -63,17 +65,26 @@ expectType<string | undefined>(message.id)
6365
expectType<string | undefined>(message.event)
6466
expectType<any>(message.data)
6567
expectType<number | undefined>(message.retry)
68+
expectAssignable<SSEMessage>(fullMessage)
6669

6770
// Test SSE sources
6871
const stringSource: SSESource = 'hello'
72+
expectAssignable<SSESource>(stringSource)
73+
6974
const bufferSource: SSESource = Buffer.from('hello')
75+
expectAssignable<SSESource>(bufferSource)
76+
7077
const messageSource: SSESource = { data: 'test' }
78+
expectAssignable<SSESource>(messageSource)
79+
7180
const streamSource: SSESource = new Readable()
81+
expectAssignable<SSESource>(streamSource)
7282

73-
async function* asyncGenerator(): AsyncIterable<SSEMessage> {
83+
async function * asyncGenerator (): AsyncIterable<SSEMessage> {
7484
yield { data: 'test' }
7585
}
7686
const asyncIterableSource: SSESource = asyncGenerator()
87+
expectAssignable<SSESource>(asyncIterableSource)
7788

7889
// Test SSE reply interface
7990
app.get('/test-reply', { sse: true }, async (request, reply) => {
@@ -130,11 +141,11 @@ const complexMessage: SSEMessage = {
130141
expectAssignable<SSESource>(complexMessage)
131142

132143
// Test async iterator types
133-
async function* typedAsyncGenerator(): AsyncIterable<string> {
144+
async function * typedAsyncGenerator (): AsyncIterable<string> {
134145
yield 'test'
135146
}
136147

137-
async function* mixedAsyncGenerator(): AsyncIterable<SSEMessage | string | Buffer> {
148+
async function * mixedAsyncGenerator (): AsyncIterable<SSEMessage | string | Buffer> {
138149
yield { data: 'message' }
139150
yield 'string'
140151
yield Buffer.from('buffer')
@@ -151,6 +162,7 @@ const pluginOptions: SSEPluginOptions = {
151162
return JSON.stringify(data)
152163
}
153164
}
165+
expectAssignable<SSEPluginOptions>(pluginOptions)
154166

155167
// Test serializer function type
156168
const customSerializer = (data: any): string => {
@@ -159,7 +171,6 @@ const customSerializer = (data: any): string => {
159171
}
160172
return String(data)
161173
}
162-
163174
expectAssignable<SSEPluginOptions>({
164175
serializer: customSerializer
165176
})
@@ -168,17 +179,20 @@ expectAssignable<SSEPluginOptions>({
168179
const routeOptions1: RouteShorthandOptions = {
169180
sse: true
170181
}
182+
expectAssignable<RouteShorthandOptions>(routeOptions1)
171183

172184
const routeOptions2: RouteShorthandOptions = {
173185
sse: false
174186
}
187+
expectAssignable<RouteShorthandOptions>(routeOptions2)
175188

176189
const routeOptions3: RouteShorthandOptions = {
177190
sse: {
178191
heartbeat: false,
179192
serializer: (data) => String(data)
180193
}
181194
}
195+
expectAssignable<RouteShorthandOptions>(routeOptions3)
182196

183197
// Test invalid route options - these tests verify type checking
184198
expectError(app.get('/invalid', {
@@ -189,4 +203,4 @@ expectError(app.get('/invalid2', {
189203
sse: {
190204
unknownOption: true
191205
}
192-
}, async (request, reply) => {}))
206+
}, async (request, reply) => {}))

types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,4 @@ export interface SSEReplyInterface {
116116

117117
export declare const fastifySSE: FastifyPluginAsync<SSEPluginOptions>
118118

119-
export default fastifySSE
119+
export default fastifySSE

0 commit comments

Comments
 (0)