Skip to content

Commit 6538a79

Browse files
committed
WIP JS errors and purs-tidy
1 parent e1e1027 commit 6538a79

File tree

11 files changed

+259
-222
lines changed

11 files changed

+259
-222
lines changed

bower.json

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,45 @@
11
{
2-
"name": "purescript-node-http",
3-
"license": "MIT",
4-
"ignore": [
5-
"**/.*",
6-
"node_modules",
7-
"bower_components",
8-
"output"
9-
],
10-
"repository": {
11-
"type": "git",
12-
"url": "https://github.com/purescript-node/purescript-node-http.git"
13-
},
14-
"devDependencies": {
15-
"purescript-console": "^6.0.0"
16-
},
17-
"dependencies": {
18-
"purescript-arraybuffer-types": "^3.0.2",
19-
"purescript-contravariant": "^6.0.0",
20-
"purescript-effect": "^4.0.0",
21-
"purescript-foreign": "^7.0.0",
22-
"purescript-foreign-object": "^4.0.0",
23-
"purescript-maybe": "^6.0.0",
24-
"purescript-node-buffer": "^8.0.0",
25-
"purescript-node-net": "^4.0.0",
26-
"purescript-node-streams": "^7.0.0",
27-
"purescript-node-url": "^6.0.0",
28-
"purescript-nullable": "^6.0.0",
29-
"purescript-options": "^7.0.0",
30-
"purescript-prelude": "^6.0.0",
31-
"purescript-unsafe-coerce": "^6.0.0"
32-
}
2+
"name": "purescript-node-http",
3+
"license": [
4+
"MIT"
5+
],
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/purescript-node/purescript-node-http"
9+
},
10+
"ignore": [
11+
"**/.*",
12+
"node_modules",
13+
"bower_components",
14+
"output"
15+
],
16+
"dependencies": {
17+
"purescript-aff": "^v7.1.0",
18+
"purescript-arraybuffer-types": "^v3.0.2",
19+
"purescript-console": "^v6.0.0",
20+
"purescript-contravariant": "^v6.0.0",
21+
"purescript-control": "^v6.0.0",
22+
"purescript-effect": "^v4.0.0",
23+
"purescript-either": "^v6.1.0",
24+
"purescript-exceptions": "^v6.0.0",
25+
"purescript-foldable-traversable": "^v6.0.0",
26+
"purescript-foreign": "^v7.0.0",
27+
"purescript-foreign-object": "^v4.1.0",
28+
"purescript-maybe": "^v6.0.0",
29+
"purescript-node-buffer": "^v8.0.0",
30+
"purescript-node-net": "^v4.0.0",
31+
"purescript-node-streams": "^v7.0.0",
32+
"purescript-node-streams-aff": "https://github.com/purescript-node/purescript-node-streams-aff.git#v4.0.0",
33+
"purescript-node-url": "^v6.0.0",
34+
"purescript-nullable": "^v6.0.0",
35+
"purescript-options": "^v7.0.0",
36+
"purescript-partial": "^v4.0.0",
37+
"purescript-prelude": "^v6.0.1",
38+
"purescript-st": "^v6.2.0",
39+
"purescript-strings": "^v6.0.1",
40+
"purescript-transformers": "^v6.0.0",
41+
"purescript-tuples": "^v7.0.0",
42+
"purescript-unsafe-coerce": "^v6.0.0",
43+
"purescript-web-fetch": "https://github.com/purescript-web/purescript-web-fetch.git#v3.0.0"
44+
}
3345
}

spago.dhall

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ to generate this file without the comments in this block.
1414
, dependencies =
1515
[ "aff"
1616
, "arraybuffer-types"
17-
, "arrays"
1817
, "console"
1918
, "contravariant"
2019
, "control"
@@ -34,7 +33,6 @@ to generate this file without the comments in this block.
3433
, "options"
3534
, "partial"
3635
, "prelude"
37-
, "record"
3836
, "st"
3937
, "strings"
4038
, "transformers"
@@ -44,4 +42,6 @@ to generate this file without the comments in this block.
4442
]
4543
, packages = ./packages.dhall
4644
, sources = [ "src/**/*.purs", "test/**/*.purs" ]
45+
, license = "MIT"
46+
, repository = "https://github.com/purescript-node/purescript-node-http"
4747
}

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)