Skip to content

Commit 335ee6a

Browse files
committed
WIP JS errors and purs-tidy
1 parent e1e1027 commit 335ee6a

File tree

9 files changed

+216
-190
lines changed

9 files changed

+216
-190
lines changed

src/Node/HTTP/Secure.purs

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,17 @@ import Unsafe.Coerce (unsafeCoerce)
9090

9191
-- | Create an HTTPS server, given the SSL options and a function to be executed
9292
-- | when a request is received.
93-
foreign import createServerImpl ::
94-
Foreign ->
95-
(Request -> Response -> Effect Unit) ->
96-
Effect Server
93+
foreign import createServerImpl
94+
:: Foreign
95+
-> (Request -> Response -> Effect Unit)
96+
-> Effect Server
9797

9898
-- | Create an HTTPS server, given the SSL options and a function to be executed
9999
-- | when a request is received.
100-
createServer :: Options SSLOptions ->
101-
(Request -> Response -> Effect Unit) ->
102-
Effect Server
100+
createServer
101+
:: Options SSLOptions
102+
-> (Request -> Response -> Effect Unit)
103+
-> Effect Server
103104
createServer = createServerImpl <<< options
104105

105106
-- | The type of HTTPS server options
@@ -120,16 +121,22 @@ rejectUnauthorized = opt "rejectUnauthorized"
120121
-- | The npnProtocols option can be a String, a Buffer, a Uint8Array, or an
121122
-- | array of any of those types.
122123
data NPNProtocols
124+
123125
npnProtocolsString :: String -> NPNProtocols
124126
npnProtocolsString = unsafeCoerce
127+
125128
npnProtocolsBuffer :: Buffer -> NPNProtocols
126129
npnProtocolsBuffer = unsafeCoerce
130+
127131
npnProtocolsUint8Array :: Uint8Array -> NPNProtocols
128132
npnProtocolsUint8Array = unsafeCoerce
133+
129134
npnProtocolsStringArray :: Array String -> NPNProtocols
130135
npnProtocolsStringArray = unsafeCoerce
136+
131137
npnProtocolsBufferArray :: Array Buffer -> NPNProtocols
132138
npnProtocolsBufferArray = unsafeCoerce
139+
133140
npnProtocolsUint8ArrayArray :: Array Uint8Array -> NPNProtocols
134141
npnProtocolsUint8ArrayArray = unsafeCoerce
135142

@@ -140,16 +147,22 @@ npnProtocols = opt "NPNProtocols"
140147
-- | The alpnProtocols option can be a String, a Buffer, a Uint8Array, or an
141148
-- | array of any of those types.
142149
data ALPNProtocols
150+
143151
alpnProtocolsString :: String -> ALPNProtocols
144152
alpnProtocolsString = unsafeCoerce
153+
145154
alpnProtocolsBuffer :: Buffer -> ALPNProtocols
146155
alpnProtocolsBuffer = unsafeCoerce
156+
147157
alpnProtocolsUint8Array :: Uint8Array -> ALPNProtocols
148158
alpnProtocolsUint8Array = unsafeCoerce
159+
149160
alpnProtocolsStringArray :: Array String -> ALPNProtocols
150161
alpnProtocolsStringArray = unsafeCoerce
162+
151163
alpnProtocolsBufferArray :: Array Buffer -> ALPNProtocols
152164
alpnProtocolsBufferArray = unsafeCoerce
165+
153166
alpnProtocolsUint8ArrayArray :: Array Uint8Array -> ALPNProtocols
154167
alpnProtocolsUint8ArrayArray = unsafeCoerce
155168

@@ -167,8 +180,10 @@ ticketKeys = opt "ticketKeys"
167180

168181
-- | The PFX option can take either a String or a Buffer
169182
data PFX
183+
170184
pfxString :: String -> PFX
171185
pfxString = unsafeCoerce
186+
172187
pfxBuffer :: Buffer -> PFX
173188
pfxBuffer = unsafeCoerce
174189

@@ -179,12 +194,16 @@ pfx = opt "pfx"
179194
-- | The key option can be a String, a Buffer, an array of strings, or an array
180195
-- | of buffers.
181196
data Key
197+
182198
keyString :: String -> Key
183199
keyString = unsafeCoerce
200+
184201
keyBuffer :: Buffer -> Key
185202
keyBuffer = unsafeCoerce
203+
186204
keyStringArray :: Array String -> Key
187205
keyStringArray = unsafeCoerce
206+
188207
keyBufferArray :: Array Buffer -> Key
189208
keyBufferArray = unsafeCoerce
190209

@@ -199,12 +218,16 @@ passphrase = opt "passphrase"
199218
-- | The cert option can be a String, a Buffer, an array of strings, or an array
200219
-- | of buffers.
201220
data Cert
221+
202222
certString :: String -> Cert
203223
certString = unsafeCoerce
224+
204225
certBuffer :: Buffer -> Cert
205226
certBuffer = unsafeCoerce
227+
206228
certStringArray :: Array String -> Cert
207229
certStringArray = unsafeCoerce
230+
208231
certBufferArray :: Array Buffer -> Cert
209232
certBufferArray = unsafeCoerce
210233

@@ -215,12 +238,16 @@ cert = opt "cert"
215238
-- | The CA option can be a String, a Buffer, an array of strings, or an array
216239
-- | of buffers.
217240
data CA
241+
218242
caString :: String -> CA
219243
caString = unsafeCoerce
244+
220245
caBuffer :: Buffer -> CA
221246
caBuffer = unsafeCoerce
247+
222248
caStringArray :: Array String -> CA
223249
caStringArray = unsafeCoerce
250+
224251
caBufferArray :: Array Buffer -> CA
225252
caBufferArray = unsafeCoerce
226253

@@ -231,12 +258,16 @@ ca = opt "ca"
231258
-- | The CRL option can be a String, a Buffer, an array of strings, or an array
232259
-- | of buffers.
233260
data CRL
261+
234262
crlString :: String -> CRL
235263
crlString = unsafeCoerce
264+
236265
crlBuffer :: Buffer -> CRL
237266
crlBuffer = unsafeCoerce
267+
238268
crlStringArray :: Array String -> CRL
239269
crlStringArray = unsafeCoerce
270+
240271
crlBufferArray :: Array Buffer -> CRL
241272
crlBufferArray = unsafeCoerce
242273

@@ -258,8 +289,10 @@ ecdhCurve = opt "ecdhCurve"
258289

259290
-- | The DHParam option can take either a String or a Buffer
260291
data DHParam
292+
261293
dhparamString :: String -> DHParam
262294
dhparamString = unsafeCoerce
295+
263296
dhparamBuffer :: Buffer -> DHParam
264297
dhparamBuffer = unsafeCoerce
265298

src/Node/HTTP2.purs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ module Node.HTTP2
1919
, Options
2020
, toOptions
2121
, Flags
22-
)
23-
where
22+
) where
2423

2524
import Prelude
2625

@@ -47,8 +46,6 @@ instance Semigroup Headers where
4746
instance Monoid Headers where
4847
mempty = unsafeCoerce {}
4948

50-
51-
5249
-- | https://nodejs.org/docs/latest/api/http2.html#headers-object
5350
-- |
5451
-- | Use this function to construct a `Headers` object. Rules for `Headers`:

src/Node/HTTP2/Client.Aff.purs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,19 @@ close session = makeAff \complete -> do
8989
-- | [`Node.Stream.Aff.readAll`](https://pursuit.purescript.org/packages/purescript-node-streams-aff/docs/Node.Stream.Aff#v:readAll).
9090
request :: ClientHttp2Session -> Options -> Headers -> Aff ClientHttp2Stream
9191
request session options headers = makeAff \complete -> do
92-
-- how do we get errors out of the request?
93-
-- by catching exceptions? this is just a guess.
94-
-- or maybe like this?
95-
--
96-
-- onceErrorCancel <- Client.onceErrorSession session \err -> complete (Left err)
97-
--
98-
abortcontroller <- Web.Fetch.AbortController.new
99-
let abortsignal = Web.Fetch.AbortController.signal abortcontroller
100-
stream <- catchException (pure <<< Left) do
101-
Right <$> Client.request session headers (toOptions {"signal":abortsignal} <> options)
102-
complete stream
103-
pure $ effectCanceler do
104-
Web.Fetch.AbortController.abort abortcontroller
92+
-- how do we get errors out of the request?
93+
-- by catching exceptions? this is just a guess.
94+
-- or maybe like this?
95+
--
96+
-- onceErrorCancel <- Client.onceErrorSession session \err -> complete (Left err)
97+
--
98+
abortcontroller <- Web.Fetch.AbortController.new
99+
let abortsignal = Web.Fetch.AbortController.signal abortcontroller
100+
stream <- catchException (pure <<< Left) do
101+
Right <$> Client.request session headers (toOptions { "signal": abortsignal } <> options)
102+
complete stream
103+
pure $ effectCanceler do
104+
Web.Fetch.AbortController.abort abortcontroller
105105

106106
-- | Wait to receive response headers from the server.
107107
waitResponse :: ClientHttp2Stream -> Aff Headers
@@ -122,11 +122,11 @@ waitResponse stream = makeAff \complete -> do
122122
-- | [`Node.Stream.Aff.readAll`](https://pursuit.purescript.org/packages/purescript-node-streams-aff/docs/Node.Stream.Aff#v:readAll).
123123
waitPush
124124
:: ClientHttp2Session
125-
-> Aff {headersRequest :: Headers, headersResponse :: Headers, streamPushed :: ClientHttp2Stream}
125+
-> Aff { headersRequest :: Headers, headersResponse :: Headers, streamPushed :: ClientHttp2Stream }
126126
waitPush session = makeAff \complete -> do
127127
onceStreamCancel <- Client.onceStream session \streamPushed headersRequest _ -> do
128128
_oncePushCancel <- Client.oncePush streamPushed \headersResponse _ ->
129-
complete (Right {headersRequest, headersResponse, streamPushed})
129+
complete (Right { headersRequest, headersResponse, streamPushed })
130130
pure unit
131131
pure $ effectCanceler do
132132
-- I'm not sure how to _oncePushCancel.

src/Node/HTTP2/Client.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
1-
import http2 from 'http2';
1+
import http2 from "http2";
22

33
// https://nodejs.org/docs/latest/api/http2.html#http2connectauthority-options-listener
44
// https://nodejs.org/docs/latest/api/http2.html#event-connect
55
export const connect = authority => options => listener => () => {
66
return http2.connect(authority, options,
77
(session,socket) => listener(session)(socket)()
88
);
9-
}
9+
};
1010

1111
// https://nodejs.org/docs/latest/api/http2.html#clienthttp2sessionrequestheaders-options
1212
export const request = clienthttp2session => headers => options => () => {
1313
return clienthttp2session.request(headers, options);
14-
}
14+
};
1515

1616
export const destroy = clienthttp2stream => () => {
1717
clienthttp2stream.destroy();
18-
}
18+
};
1919

2020
// https://nodejs.org/docs/latest/api/http2.html#event-response
2121
export const onceResponse = clienthttp2stream => callback => () => {
2222
const cb = (headers,flags) => callback(headers)(flags)();
23-
clienthttp2stream.once('response', cb);
24-
return () => clienthttp2stream.removeEventListener('response', cb);
25-
}
23+
clienthttp2stream.once("response", cb);
24+
return () => clienthttp2stream.removeEventListener("response", cb);
25+
};
2626

2727
// https://nodejs.org/docs/latest/api/http2.html#event-headers
2828
export const onceHeaders = clienthttp2stream => callback => () => {
2929
const cb = (headers,flags) => callback(headers)(flags)();
30-
clienthttp2stream.once('headers', cb);
31-
return () => clienthttp2stream.removeEventListener('headers', cb);
32-
}
30+
clienthttp2stream.once("headers", cb);
31+
return () => clienthttp2stream.removeEventListener("headers", cb);
32+
};
3333

3434
// https://nodejs.org/docs/latest/api/http2.html#event-push
3535
export const oncePush = clienthttp2stream => callback => () => {
3636
const cb = (headers,flags) => callback(headers)(flags)();
37-
clienthttp2stream.once('push', cb);
38-
return () => clienthttp2stream.removeEventListener('push', cb);
39-
}
37+
clienthttp2stream.once("push", cb);
38+
return () => clienthttp2stream.removeEventListener("push", cb);
39+
};

0 commit comments

Comments
 (0)