11module Node.Http2.Session
2- ( onClose
3- , onConnect
4- , onError
5- , onFrameError
6- , onGoAway
7- , onLocalSettings
8- , onPing
9- , onRemoteSettings
10- , onStream
11- , onTimeout
2+ ( toEventEmitter
3+ , closeHandle
4+ , connectHandle
5+ , errorHandle
6+ , frameErrorHandle
7+ , goAwayHandle
8+ , localSettingsHandle
9+ , pingHandle
10+ , remoteSettingsHandle
11+ , streamHandle
12+ , timeoutHandle
1213 , alpnProtocol
1314 , close
1415 , closed
@@ -41,8 +42,8 @@ module Node.Http2.Session
4142 , altsvcStreamId
4243 , altsvcOrigin
4344 , origin
44- , onAltsvc
45- , onOrigin
45+ , altsvcHandle
46+ , originHandle
4647 , RequestOptions
4748 , request
4849 , request'
@@ -57,61 +58,53 @@ import Data.Time.Duration (Milliseconds)
5758import Effect (Effect )
5859import Effect.Exception (Error )
5960import Effect.Uncurried (EffectFn1 , EffectFn2 , EffectFn3 , EffectFn4 , mkEffectFn1 , mkEffectFn2 , mkEffectFn3 , mkEffectFn4 , runEffectFn1 , runEffectFn2 , runEffectFn3 , runEffectFn4 )
61+ import Node.Buffer (Buffer )
6062import Node.Buffer.Immutable (ImmutableBuffer )
61- import Node.Http2.Types (Headers , Http2Session , Http2Stream , Settings )
63+ import Node.EventEmitter (EventEmitter , EventHandle (..))
64+ import Node.EventEmitter.UtilTypes (EventHandle0 , EventHandle1 , EventHandle2 , EventHandle3 , EventHandle4 )
65+ import Node.Http2.Flags (BitwiseFlag )
66+ import Node.Http2.Types (ErrorCode , FrameType , Headers , Http2Session , Http2Stream , Settings , StreamId )
6267import Node.Net.Types (Socket , TCP )
6368import Node.TLS.Types (Client , Server )
69+ import Unsafe.Coerce (unsafeCoerce )
6470
65- onClose :: forall endpoint . Http2Session endpoint -> Effect Unit -> Effect Unit
66- onClose session cb = runEffectFn2 onCloseImpl session cb
71+ toEventEmitter :: forall endpoint . Http2Session endpoint -> EventEmitter
72+ toEventEmitter = unsafeCoerce
6773
68- foreign import onCloseImpl :: forall endpoint . EffectFn2 (Http2Session endpoint ) (Effect Unit ) Unit
74+ closeHandle :: forall endpoint . EventHandle0 (Http2Session endpoint )
75+ closeHandle = EventHandle " close" identity
6976
70- onConnect :: forall endpoint . Http2Session endpoint -> (Http2Session endpoint -> Socket TCP -> Effect Unit ) -> Effect Unit
71- onConnect h2s cb = runEffectFn2 onConnectImpl h2s $ mkEffectFn2 cb
77+ connectHandle :: forall endpoint . EventHandle2 ( Http2Session endpoint ) (Http2Session endpoint ) ( Socket TCP )
78+ connectHandle = EventHandle " connect " \cb -> mkEffectFn2 \a b -> cb a b
7279
73- foreign import onConnectImpl :: forall endpoint . EffectFn2 (Http2Session endpoint ) (EffectFn2 (Http2Session endpoint ) (Socket TCP ) Unit ) Unit
80+ errorHandle :: forall endpoint . EventHandle1 (Http2Session endpoint ) Error
81+ errorHandle = EventHandle " error" mkEffectFn1
7482
75- onError :: forall endpoint . Http2Session endpoint -> ( Error -> Effect Unit ) -> Effect Unit
76- onError session cb = runEffectFn2 onErrorImpl session $ mkEffectFn1 cb
83+ frameErrorHandle :: forall endpoint . EventHandle3 ( Http2Session endpoint ) FrameType ErrorCode StreamId
84+ frameErrorHandle = EventHandle " frameError " \ cb -> mkEffectFn3 \a b c -> cb a b c
7785
78- foreign import onErrorImpl :: forall endpoint . EffectFn2 (Http2Session endpoint ) (EffectFn1 Error Unit ) (Unit )
86+ goAwayHandle
87+ :: forall endpoint
88+ . EventHandle
89+ (Http2Session endpoint )
90+ (ErrorCode -> StreamId -> (Maybe Buffer ) -> Effect Unit )
91+ (EffectFn3 ErrorCode StreamId (Nullable Buffer ) Unit )
92+ goAwayHandle = EventHandle " goAway" \cb -> mkEffectFn3 \a b c -> cb a b (toMaybe c)
7993
80- onFrameError :: forall endpoint . Http2Session endpoint -> ( Int -> Int -> Int -> Effect Unit ) -> Effect Unit
81- onFrameError session cb = runEffectFn2 onFrameErrorImpl session $ mkEffectFn3 cb
94+ localSettingsHandle :: forall endpoint . EventHandle1 ( Http2Session endpoint ) Settings
95+ localSettingsHandle = EventHandle " localSettings " mkEffectFn1
8296
83- foreign import onFrameErrorImpl :: forall endpoint . EffectFn2 (Http2Session endpoint ) (EffectFn3 Int Int Int Unit ) (Unit )
97+ pingHandle :: forall endpoint . EventHandle1 (Http2Session endpoint ) Buffer
98+ pingHandle = EventHandle " ping" mkEffectFn1
8499
85- onGoAway :: forall endpoint . Http2Session endpoint -> (Int -> Int -> Maybe ImmutableBuffer -> Effect Unit ) -> Effect Unit
86- onGoAway session cb = runEffectFn2 onGoAwayImpl session $ mkEffectFn3 \c lsi buf ->
87- cb c lsi (toMaybe buf)
100+ remoteSettingsHandle :: forall endpoint . EventHandle1 (Http2Session endpoint ) Settings
101+ remoteSettingsHandle = EventHandle " remoteSettings" mkEffectFn1
88102
89- foreign import onGoAwayImpl :: forall endpoint . EffectFn2 (Http2Session endpoint ) (EffectFn3 Int Int (Nullable ImmutableBuffer ) Unit ) (Unit )
103+ streamHandle :: forall endpoint . EventHandle4 (Http2Session endpoint ) (Http2Stream endpoint ) Headers BitwiseFlag (Array String )
104+ streamHandle = EventHandle " stream" \cb -> mkEffectFn4 \a b c d -> cb a b c d
90105
91- onLocalSettings :: forall endpoint . Http2Session endpoint -> (Settings -> Effect Unit ) -> Effect Unit
92- onLocalSettings session cb = runEffectFn2 onLocalSettingsImpl session $ mkEffectFn1 cb
93-
94- foreign import onLocalSettingsImpl :: forall endpoint . EffectFn2 (Http2Session endpoint ) (EffectFn1 Settings Unit ) (Unit )
95-
96- onPing :: forall endpoint . Http2Session endpoint -> (Maybe ImmutableBuffer -> Effect Unit ) -> Effect Unit
97- onPing sesson cb = runEffectFn2 onPingImpl sesson $ mkEffectFn1 \a -> cb $ toMaybe a
98-
99- foreign import onPingImpl :: forall endpoint . EffectFn2 (Http2Session endpoint ) (EffectFn1 (Nullable ImmutableBuffer ) Unit ) (Unit )
100-
101- onRemoteSettings :: forall endpoint . Http2Session endpoint -> (Settings -> Effect Unit ) -> Effect Unit
102- onRemoteSettings session cb = runEffectFn2 onRemoteSettingsImpl session $ mkEffectFn1 cb
103-
104- foreign import onRemoteSettingsImpl :: forall endpoint . EffectFn2 (Http2Session endpoint ) (EffectFn1 Settings Unit ) (Unit )
105-
106- onStream :: forall endpoint . Http2Session endpoint -> (Http2Stream endpoint -> Headers -> Number -> (Array String ) -> Effect Unit ) -> Effect Unit
107- onStream session cb = runEffectFn2 onStreamImpl session $ mkEffectFn4 cb
108-
109- foreign import onStreamImpl :: forall endpoint . EffectFn2 (Http2Session endpoint ) (EffectFn4 (Http2Stream endpoint ) Headers Number (Array String ) Unit ) (Unit )
110-
111- onTimeout :: forall endpoint . Http2Session endpoint -> Effect Unit -> Effect Unit
112- onTimeout session cb = runEffectFn2 onTimeoutImpl session cb
113-
114- foreign import onTimeoutImpl :: forall endpoint . EffectFn2 (Http2Session endpoint ) (Effect Unit ) (Unit )
106+ timeoutHandle :: forall endpoint . EventHandle0 (Http2Session endpoint )
107+ timeoutHandle = EventHandle " timeout" identity
115108
116109alpnProtocol :: forall endpoint . Http2Session endpoint -> Effect (Maybe String )
117110alpnProtocol session = map toMaybe $ runEffectFn1 alpnProtocolImpl session
@@ -143,15 +136,15 @@ destroyWithError s e = runEffectFn2 destroyWithErrorImpl s e
143136
144137foreign import destroyWithErrorImpl :: forall endpoint . EffectFn2 (Http2Session endpoint ) (Error ) (Unit )
145138
146- destroyWithCode :: forall endpoint . Http2Session endpoint -> Int -> Effect Unit
139+ destroyWithCode :: forall endpoint . Http2Session endpoint -> ErrorCode -> Effect Unit
147140destroyWithCode s c = runEffectFn2 destroyWithCodeImpl s c
148141
149- foreign import destroyWithCodeImpl :: forall endpoint . EffectFn2 (Http2Session endpoint ) (Int ) (Unit )
142+ foreign import destroyWithCodeImpl :: forall endpoint . EffectFn2 (Http2Session endpoint ) (ErrorCode ) (Unit )
150143
151- destroyWithErrorCode :: forall endpoint . Http2Session endpoint -> Error -> Int -> Effect Unit
144+ destroyWithErrorCode :: forall endpoint . Http2Session endpoint -> Error -> ErrorCode -> Effect Unit
152145destroyWithErrorCode s e c = runEffectFn3 destroyWithErrorCodeImpl s e c
153146
154- foreign import destroyWithErrorCodeImpl :: forall endpoint . EffectFn3 (Http2Session endpoint ) (Error ) (Int ) (Unit )
147+ foreign import destroyWithErrorCodeImpl :: forall endpoint . EffectFn3 (Http2Session endpoint ) (Error ) (ErrorCode ) (Unit )
155148
156149destroyed :: forall endpoint . Http2Session endpoint -> Effect Boolean
157150destroyed s = runEffectFn1 destroyedImpl s
@@ -168,20 +161,20 @@ goAway s = runEffectFn1 goAwayImpl s
168161
169162foreign import goAwayImpl :: forall endpoint . EffectFn1 (Http2Session endpoint ) (Unit )
170163
171- goAwayCode :: forall endpoint . Http2Session endpoint -> Int -> Effect Unit
164+ goAwayCode :: forall endpoint . Http2Session endpoint -> ErrorCode -> Effect Unit
172165goAwayCode s c = runEffectFn2 goAwayCodeImpl s c
173166
174- foreign import goAwayCodeImpl :: forall endpoint . EffectFn2 (Http2Session endpoint ) (Int ) (Unit )
167+ foreign import goAwayCodeImpl :: forall endpoint . EffectFn2 (Http2Session endpoint ) (ErrorCode ) (Unit )
175168
176- goAwayCodeLastStreamId :: forall endpoint . Http2Session endpoint -> Int -> Int -> Effect Unit
169+ goAwayCodeLastStreamId :: forall endpoint . Http2Session endpoint -> ErrorCode -> StreamId -> Effect Unit
177170goAwayCodeLastStreamId s c lsi = runEffectFn3 goAwayCodeLastStreamIdImpl s c lsi
178171
179- foreign import goAwayCodeLastStreamIdImpl :: forall endpoint . EffectFn3 (Http2Session endpoint ) (Int ) (Int ) (Unit )
172+ foreign import goAwayCodeLastStreamIdImpl :: forall endpoint . EffectFn3 (Http2Session endpoint ) (ErrorCode ) (StreamId ) (Unit )
180173
181- goAwayCodeLastStreamIdData :: forall endpoint . Http2Session endpoint -> Int -> Int -> ImmutableBuffer -> Effect Unit
174+ goAwayCodeLastStreamIdData :: forall endpoint . Http2Session endpoint -> ErrorCode -> StreamId -> Buffer -> Effect Unit
182175goAwayCodeLastStreamIdData s c lsi buf = runEffectFn4 goAwayCodeLastStreamIdOpaqueDataImpl s c lsi buf
183176
184- foreign import goAwayCodeLastStreamIdOpaqueDataImpl :: forall endpoint . EffectFn4 (Http2Session endpoint ) (Int ) (Int ) (ImmutableBuffer ) (Unit )
177+ foreign import goAwayCodeLastStreamIdOpaqueDataImpl :: forall endpoint . EffectFn4 (Http2Session endpoint ) (ErrorCode ) (StreamId ) (Buffer ) (Unit )
185178
186179localSettings :: forall endpoint . Http2Session endpoint -> Effect Settings
187180localSettings s = runEffectFn1 localSettingsImpl s
@@ -292,15 +285,11 @@ origin s o = runEffectFn2 originImpl s o
292285
293286foreign import originImpl :: EffectFn2 (Http2Session Server ) (Array String ) (Unit )
294287
295- onAltsvc :: Http2Session Client -> (String -> String -> Int -> Effect Unit ) -> Effect Unit
296- onAltsvc s cb = runEffectFn2 onAltsvcImpl s $ mkEffectFn3 cb
297-
298- foreign import onAltsvcImpl :: EffectFn2 (Http2Session Client ) (EffectFn3 String String Int Unit ) (Unit )
299-
300- onOrigin :: Http2Session Client -> (Array String -> Effect Unit ) -> Effect Unit
301- onOrigin s cb = runEffectFn2 onOriginImpl s $ mkEffectFn1 cb
288+ altsvcHandle :: EventHandle3 (Http2Session Client ) String String StreamId
289+ altsvcHandle = EventHandle " altsvc" \cb -> mkEffectFn3 \a b c -> cb a b c
302290
303- foreign import onOriginImpl :: EffectFn2 (Http2Session Client ) (EffectFn1 (Array String ) Unit ) (Unit )
291+ originHandle :: EventHandle1 (Http2Session Client ) (Array String )
292+ originHandle = EventHandle " origin" mkEffectFn1
304293
305294-- | `endStream` <boolean> true if the Http2Stream writable side should be closed initially, such as when sending a GET request that should not expect a payload body.
306295-- | `exclusive` <boolean> When true and parent identifies a parent Stream, the created stream is made the sole direct dependency of the parent, with all other existing dependents made a dependent of the newly created stream. Default: false.
0 commit comments