11import { encode , decode } from "@msgpack/msgpack" ;
2- import { Pool } from "pg" ;
2+ import { type Pool , type PoolClient , type Notification } from "pg" ;
33import { ClusterAdapterWithHeartbeat , MessageType } from "socket.io-adapter" ;
44import type {
55 ClusterAdapterOptions ,
@@ -101,8 +101,8 @@ export function createAdapter(
101101
102102 const channelToAdapters = new Map < string , PostgresAdapter > ( ) ;
103103 let isConnectionInProgress = false ;
104- let client : any ;
105- let cleanupTimer : NodeJS . Timer ;
104+ let client : PoolClient | undefined ;
105+ let cleanupTimer : NodeJS . Timeout ;
106106
107107 const scheduleReconnection = ( ) => {
108108 const reconnectionDelay = Math . floor ( 2000 * ( 0.5 + Math . random ( ) ) ) ;
@@ -120,11 +120,11 @@ export function createAdapter(
120120 await client . query ( `LISTEN "${ channel } "` ) ;
121121 }
122122
123- client . on ( "notification" , async ( msg : any ) => {
123+ client . on ( "notification" , async ( msg : Notification ) => {
124124 try {
125125 await channelToAdapters . get ( msg . channel ) ?. onEvent ( msg . payload ) ;
126126 } catch ( err ) {
127- errorHandler ( err ) ;
127+ errorHandler ( err as Error ) ;
128128 }
129129 } ) ;
130130
@@ -137,7 +137,7 @@ export function createAdapter(
137137 scheduleReconnection ( ) ;
138138 } ) ;
139139 } catch ( err ) {
140- errorHandler ( err ) ;
140+ errorHandler ( err as Error ) ;
141141 debug ( "error while initializing client, scheduling reconnection..." ) ;
142142 scheduleReconnection ( ) ;
143143 }
@@ -150,7 +150,7 @@ export function createAdapter(
150150 `DELETE FROM ${ tableName } WHERE created_at < now() - interval '${ cleanupInterval } milliseconds'`
151151 ) ;
152152 } catch ( err ) {
153- errorHandler ( err ) ;
153+ errorHandler ( err as Error ) ;
154154 }
155155 scheduleCleanup ( ) ;
156156 } , cleanupInterval ) ;
@@ -182,7 +182,7 @@ export function createAdapter(
182182 if ( client ) {
183183 client . removeAllListeners ( "end" ) ;
184184 client . release ( ) ;
185- client = null ;
185+ client = undefined ;
186186 }
187187 if ( cleanupTimer ) {
188188 clearTimeout ( cleanupTimer ) ;
@@ -288,7 +288,7 @@ export class PostgresAdapter extends ClusterAdapterWithHeartbeat {
288288 payload ,
289289 ] ) ;
290290 } catch ( err ) {
291- this . errorHandler ( err ) ;
291+ this . errorHandler ( err as Error ) ;
292292 }
293293 }
294294
0 commit comments