Skip to content

Commit

Permalink
fix(types): aedes.handle type definition (#772)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilomon10 authored Sep 14, 2022
1 parent 74ebd1d commit c80a8df
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion test/types/aedes.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { AedesPublishPacket, ConnackPacket, ConnectPacket, PingreqPacket, P
import type { AuthenticateError, Brokers, Connection } from 'aedes:server'
import Server, { Aedes } from 'aedes:server'

import { IncomingMessage } from 'node:http'
import type { Client } from 'aedes:client'
import { Socket } from 'node:net'
import { expectType } from 'tsd'
Expand Down Expand Up @@ -124,11 +125,12 @@ expectType<void>(broker.close())
expectType<void>(broker.close(() => {}))

// Aedes client
const client = broker.handle({} as Connection)
const client = broker.handle({} as Connection, {} as IncomingMessage)

expectType<Client>(client)

expectType<Connection>(client.conn)
expectType<IncomingMessage>(client.req!)

expectType<Client>(client.on('connected', () => {}))
expectType<Client>(client.on('error', (error: Error) => {
Expand Down
3 changes: 2 additions & 1 deletion types/instance.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
declare module 'aedes' {
import { Duplex } from 'node:stream'
import { Socket } from 'node:net'
import { IncomingMessage } from 'http'
import { Client } from 'aedes:client'
import type { AedesPublishPacket, ConnectPacket, ConnackPacket, Subscription, PingreqPacket, PublishPacket, PubrelPacket } from 'aedes:packet'
import { EventEmitter } from 'node:events'
Expand Down Expand Up @@ -65,7 +66,7 @@ declare module 'aedes' {
brokers: Readonly<Brokers>

constructor(option?: AedesOptions)
handle: (stream: Connection) => Client
handle: (stream: Connection, request: IncomingMessage) => Client

on (event: 'closed', listener: () => void): this
on (event: 'client' | 'clientReady' | 'clientDisconnect' | 'keepaliveTimeout', listener: (client: Client) => void): this
Expand Down

0 comments on commit c80a8df

Please sign in to comment.