Skip to content

Commit 582324e

Browse files
committed
try to improve typescript definition
1 parent 2347deb commit 582324e

File tree

1 file changed

+63
-53
lines changed

1 file changed

+63
-53
lines changed

hapi-plugin-websocket.d.ts

Lines changed: 63 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -22,69 +22,79 @@
2222
** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2323
*/
2424

25-
import * as ws from "ws"
26-
import * as http from "node:http"
27-
import * as HAPI from "@hapi/hapi"
25+
import { Plugin, Request, ReqRef, ReqRefDefaults } from "@hapi/hapi"
26+
import { Podium } from "@hapi/podium"
27+
import * as ws from "ws"
28+
import * as http from "node:http"
2829

29-
interface HapiWebsocketPluginState {
30-
mode: "websocket"
31-
ctx: Record<string, any>
32-
wss: ws.Server
33-
ws: ws.WebSocket
34-
wsf: any
35-
req: http.IncomingMessage
36-
peers: ws.WebSocket[]
37-
initially: boolean
38-
}
30+
declare namespace HAPIPluginWebSockets {
31+
interface PluginState {
32+
mode: "websocket"
33+
ctx: Record<string, any>
34+
wss: ws.Server
35+
ws: ws.WebSocket
36+
wsf: any
37+
req: http.IncomingMessage
38+
peers: ws.WebSocket[]
39+
initially: boolean
40+
}
41+
42+
interface PluginSpecificConfiguration {
43+
only?: boolean
44+
subprotocol?: string
45+
error?: (
46+
this: PluginState["ctx"],
47+
pluginState: PluginState,
48+
error: Error
49+
) => void
50+
connect?: (
51+
this: PluginState["ctx"],
52+
pluginState: PluginState
53+
) => void
54+
disconnect?: (
55+
this: PluginState["ctx"],
56+
pluginState: PluginState
57+
) => void
58+
request?: (
59+
ctx: any,
60+
request: any,
61+
h?: any
62+
) => void
63+
response?: (
64+
ctx: any,
65+
request: any,
66+
h?: any
67+
) => void
68+
frame?: boolean
69+
frameEncoding?: "json" | string
70+
frameRequest?: "REQUEST" | string
71+
frameResponse?: "RESPONSE" | string
72+
frameMessage?: (
73+
this: PluginState["ctx"],
74+
pluginState: PluginState,
75+
frame: any
76+
) => void
77+
autoping?: number
78+
initially?: boolean
79+
}
3980

40-
interface HapiWebsocketPluginSpecificConfiguration {
41-
only?: boolean
42-
subprotocol?: string
43-
error?: (
44-
this: HapiWebsocketPluginState["ctx"],
45-
pluginState: HapiWebsocketPluginState,
46-
error: Error
47-
) => void
48-
connect?: (
49-
this: HapiWebsocketPluginState["ctx"],
50-
pluginState: HapiWebsocketPluginState
51-
) => void
52-
disconnect?: (
53-
this: HapiWebsocketPluginState["ctx"],
54-
pluginState: HapiWebsocketPluginState
55-
) => void
56-
request?: (
57-
ctx: any,
58-
request: any,
59-
h?: any
60-
) => void
61-
response?: (
62-
ctx: any,
63-
request: any,
64-
h?: any
65-
) => void
66-
frame?: boolean
67-
frameEncoding?: "json" | string
68-
frameRequest?: "REQUEST" | string
69-
frameResponse?: "RESPONSE" | string
70-
frameMessage?: (
71-
this: HapiWebsocketPluginState["ctx"],
72-
pluginState: HapiWebsocketPluginState,
73-
frame: any
74-
) => void
75-
autoping?: number
76-
initially?: boolean
81+
interface OptionalRegistrationOptions {
82+
}
7783
}
7884

85+
declare const HAPIPluginDucky: Plugin<HAPIPluginWebSockets.OptionalRegistrationOptions>
86+
87+
export = HAPIPluginWebSockets
88+
7989
declare module "@hapi/hapi" {
8090
export interface Request<Refs extends ReqRef = ReqRefDefaults> extends Podium {
81-
websocket(): HapiWebsocketPluginState
91+
websocket(): HAPIPluginWebSockets.PluginState
8292
}
8393
export interface PluginsStates {
84-
websocket: HapiWebsocketPluginState
94+
websocket: HAPIPluginWebSockets.PluginState
8595
}
8696
export interface PluginSpecificConfiguration {
87-
websocket?: HapiWebsocketPluginSpecificConfiguration
97+
websocket?: HAPIPluginWebSockets.PluginSpecificConfiguration
8898
}
8999
}
90100

0 commit comments

Comments
 (0)