11module Node.Http2.Stream
22 ( toDuplex
3- , onAbort
4- , onClose
5- , onError
6- , onFrameError
7- , onReady
8- , onTimeout
9- , onTrailers
10- , onWantTrailers
3+ , abortedHandle
4+ , closeHandle
5+ , errorHandle
6+ , frameErrorHandle
7+ , readyHandle
8+ , timeoutHandle
9+ , trailersHandle
10+ , wantTrailersHandle
1111 , bufferSize
1212 , close
1313 , closed
@@ -38,10 +38,10 @@ module Node.Http2.Stream
3838 , respondWithFd
3939 , RespondWithFileOptions
4040 , respondWithFile
41- , onContinue
42- , onHeaders
43- , onPush
44- , onResponse
41+ , continueHandle
42+ , headersHandle
43+ , pushHandle
44+ , responseHandle
4545 ) where
4646
4747import Prelude
@@ -53,64 +53,52 @@ import Data.Time.Duration (Milliseconds)
5353import Effect (Effect )
5454import Effect.Exception (Error )
5555import Effect.Uncurried (EffectFn1 , EffectFn2 , EffectFn3 , EffectFn4 , mkEffectFn1 , mkEffectFn2 , mkEffectFn3 , runEffectFn1 , runEffectFn2 , runEffectFn3 , runEffectFn4 )
56+ import Node.EventEmitter (EventHandle (..))
57+ import Node.EventEmitter.UtilTypes (EventHandle0 , EventHandle1 , EventHandle3 , EventHandle2 )
5658import Node.FS (FileDescriptor )
57- import Node.Http2.Types ( Headers , Http2Session , Http2Stream )
58- import Node.TLS .Types (Client , Server )
59+ import Node.Http2.Flags ( BitwiseFlag )
60+ import Node.Http2 .Types (ErrorCode (..), FrameType , Headers , Http2Session , Http2Stream , Settings , StreamId (..) )
5961import Node.Path (FilePath )
6062import Node.Stream (Duplex )
63+ import Node.TLS.Types (Client , Server )
6164import Partial.Unsafe (unsafeCrashWith )
65+ import Safe.Coerce (coerce )
6266import Unsafe.Coerce (unsafeCoerce )
6367
6468toDuplex :: forall endpoint . Http2Stream endpoint -> Duplex
6569toDuplex = unsafeCoerce
6670
67- onAbort :: forall endpoint . Http2Stream endpoint -> Effect Unit -> Effect Unit
68- onAbort s cb = runEffectFn2 onAbortImpl s cb
69-
70- foreign import onAbortImpl :: forall endpoint . EffectFn2 (Http2Stream endpoint ) (Effect Unit ) Unit
71-
72- onClose :: forall endpoint . Http2Stream endpoint -> Effect Unit -> Effect Unit
73- onClose s cb = runEffectFn2 onCloseImpl s cb
74-
75- foreign import onCloseImpl :: forall endpoint . EffectFn2 (Http2Stream endpoint ) (Effect Unit ) (Unit )
76-
77- onError :: forall endpoint . Http2Stream endpoint -> (Error -> Effect Unit ) -> Effect Unit
78- onError s cb = runEffectFn2 onErrorImpl s $ mkEffectFn1 cb
79-
80- foreign import onErrorImpl :: forall endpoint . EffectFn2 (Http2Stream endpoint ) (EffectFn1 Error Unit ) (Unit )
71+ abortedHandle :: forall endpoint . EventHandle0 (Http2Stream endpoint )
72+ abortedHandle = EventHandle " aborted" identity
8173
82- onFrameError :: forall endpoint . Http2Stream endpoint -> ( Int -> Int -> Int -> Effect Unit ) -> Effect Unit
83- onFrameError s cb = runEffectFn2 onFrameErrorImpl s $ mkEffectFn3 cb
74+ closeHandle :: forall endpoint . EventHandle0 ( Http2Stream endpoint )
75+ closeHandle = EventHandle " close " identity
8476
85- foreign import onFrameErrorImpl :: forall endpoint . EffectFn2 (Http2Stream endpoint ) (EffectFn3 Int Int Int Unit ) (Unit )
77+ errorHandle :: forall endpoint . EventHandle1 (Http2Stream endpoint ) Error
78+ errorHandle = EventHandle " error" mkEffectFn1
8679
87- onReady :: forall endpoint . Http2Stream endpoint -> Effect Unit -> Effect Unit
88- onReady s cb = runEffectFn2 onReadyImpl s cb
80+ frameErrorHandle :: forall endpoint . EventHandle3 ( Http2Stream endpoint ) FrameType ErrorCode StreamId
81+ frameErrorHandle = EventHandle " frameError " \ cb -> mkEffectFn3 \a b c -> cb a b c
8982
90- foreign import onReadyImpl :: forall endpoint . EffectFn2 (Http2Stream endpoint ) (Effect Unit ) (Unit )
83+ readyHandle :: forall endpoint . EventHandle0 (Http2Stream endpoint )
84+ readyHandle = EventHandle " ready" identity
9185
92- onTimeout :: forall endpoint . Http2Stream endpoint -> Effect Unit -> Effect Unit
93- onTimeout s cb = runEffectFn2 onTimeoutImpl s cb
86+ timeoutHandle :: forall endpoint . EventHandle0 ( Http2Stream endpoint )
87+ timeoutHandle = EventHandle " timeout " identity
9488
95- foreign import onTimeoutImpl :: forall endpoint . EffectFn2 (Http2Stream endpoint ) (Effect Unit ) (Unit )
89+ trailersHandle :: forall endpoint . EventHandle2 (Http2Stream endpoint ) Settings BitwiseFlag
90+ trailersHandle = EventHandle " trailers" \cb -> mkEffectFn2 \a b -> cb a b
9691
97- onTrailers :: forall endpoint . Http2Stream endpoint -> (Headers -> Int -> Effect Unit ) -> Effect Unit
98- onTrailers s cb = runEffectFn2 onTrailersImpl s $ mkEffectFn2 cb
99-
100- foreign import onTrailersImpl :: forall endpoint . EffectFn2 (Http2Stream endpoint ) (EffectFn2 Headers Int Unit ) (Unit )
101-
102- onWantTrailers :: forall endpoint . Http2Stream endpoint -> Effect Unit -> Effect Unit
103- onWantTrailers s cb = runEffectFn2 onWantTrailersImpl s cb
104-
105- foreign import onWantTrailersImpl :: forall endpoint . EffectFn2 (Http2Stream endpoint ) (Effect Unit ) (Unit )
92+ wantTrailersHandle :: forall endpoint . EventHandle0 (Http2Stream endpoint )
93+ wantTrailersHandle = EventHandle " wantTrailers" identity
10694
10795bufferSize :: forall endpoint . Http2Stream endpoint -> Effect Int
10896bufferSize s = runEffectFn1 bufferSizeImpl s
10997
11098foreign import bufferSizeImpl :: forall endpoint . EffectFn1 (Http2Stream endpoint ) (Int )
11199
112- close :: forall endpoint . Http2Stream endpoint -> Int -> Effect Unit
113- close s code = runEffectFn2 closeImpl s code
100+ close :: forall endpoint . Http2Stream endpoint -> ErrorCode -> Effect Unit
101+ close s code = runEffectFn2 closeImpl s (coerce code)
114102
115103foreign import closeImpl :: forall endpoint . EffectFn2 (Http2Stream endpoint ) Int (Unit )
116104
@@ -129,8 +117,8 @@ endAfterHeaders s = runEffectFn1 endAfterHeadersImpl s
129117
130118foreign import endAfterHeadersImpl :: forall endpoint . EffectFn1 (Http2Stream endpoint ) (Boolean )
131119
132- id :: forall endpoint . Http2Stream endpoint -> Effect (Maybe Int )
133- id s = map toMaybe $ runEffectFn1 idImpl s
120+ id :: forall endpoint . Http2Stream endpoint -> Effect (Maybe StreamId )
121+ id s = map (coerce <<< toMaybe) $ runEffectFn1 idImpl s
134122
135123foreign import idImpl :: forall endpoint . EffectFn1 (Http2Stream endpoint ) (Nullable Int )
136124
@@ -156,8 +144,8 @@ priority s p = runEffectFn2 priorityImpl s $ p { weight = clamp 1 256 p.weight }
156144
157145foreign import priorityImpl :: forall endpoint . EffectFn2 (Http2Stream endpoint ) (PriorityOptions ) (Unit )
158146
159- rstCode :: forall endpoint . Http2Stream endpoint -> Effect (Maybe Int )
160- rstCode s = map toMaybe $ runEffectFn1 rstCodeImpl s
147+ rstCode :: forall endpoint . Http2Stream endpoint -> Effect (Maybe ErrorCode )
148+ rstCode s = map (coerce <<< toMaybe) $ runEffectFn1 rstCodeImpl s
161149
162150foreign import rstCodeImpl :: forall endpoint . EffectFn1 (Http2Stream endpoint ) (Nullable Int )
163151
@@ -194,7 +182,7 @@ foreign import setTimeoutImpl :: forall endpoint. EffectFn3 (Http2Stream endpoin
194182-- | `weight` <number> The priority weight of this Http2Stream peer.
195183type Http2StreamState =
196184 { localWindowSize :: Int
197- , state :: Int
185+ , state :: BitwiseFlag
198186 , localClose :: Int
199187 , remoteClose :: Int
200188 , sumDependencyWeight :: Int
@@ -295,23 +283,15 @@ respondWithFile s fp h o = runEffectFn4 respondWithFileImpl s fp h o
295283
296284foreign import respondWithFileImpl :: EffectFn4 (Http2Stream Server ) (FilePath ) (Headers ) (RespondWithFileOptions ) (Unit )
297285
298- onContinue :: Http2Stream Client -> Effect Unit -> Effect Unit
299- onContinue s cb = runEffectFn2 onContinueImpl s cb
300-
301- foreign import onContinueImpl :: EffectFn2 (Http2Stream Client ) (Effect Unit ) (Unit )
302-
303- onHeaders :: Http2Stream Client -> (Headers -> Int -> Effect Unit ) -> Effect Unit
304- onHeaders s cb = runEffectFn2 onHeadersImpl s $ mkEffectFn2 cb
305-
306- foreign import onHeadersImpl :: EffectFn2 (Http2Stream Client ) (EffectFn2 Headers Int Unit ) (Unit )
307-
308- onPush :: Http2Stream Client -> (Headers -> Int -> Effect Unit ) -> Effect Unit
309- onPush s cb = runEffectFn2 onPushImpl s $ mkEffectFn2 cb
286+ continueHandle :: EventHandle0 (Http2Stream Client )
287+ continueHandle = EventHandle " continue" identity
310288
311- foreign import onPushImpl :: EffectFn2 (Http2Stream Client ) (EffectFn2 Headers Int Unit ) (Unit )
289+ headersHandle :: EventHandle2 (Http2Stream Client ) Headers BitwiseFlag
290+ headersHandle = EventHandle " headers" \cb -> mkEffectFn2 \a b -> cb a b
312291
313- onResponse :: Http2Stream Client -> ( Headers -> Int -> Effect Unit ) -> Effect Unit
314- onResponse s cb = runEffectFn2 onResponseImpl s $ mkEffectFn2 cb
292+ pushHandle :: EventHandle2 ( Http2Stream Client ) Headers BitwiseFlag
293+ pushHandle = EventHandle " push " \cb -> mkEffectFn2 \a b -> cb a b
315294
316- foreign import onResponseImpl :: EffectFn2 (Http2Stream Client ) (EffectFn2 Headers Int Unit ) (Unit )
295+ responseHandle :: EventHandle2 (Http2Stream Client ) Headers BitwiseFlag
296+ responseHandle = EventHandle " response" \cb -> mkEffectFn2 \a b -> cb a b
317297
0 commit comments