Skip to content

Commit

Permalink
Update node libs (#48)
Browse files Browse the repository at this point in the history
* Update PS deps in bower.json

* Make code compile again

* Add entry

* Close server after responding to first test; disable testUpgrades
  • Loading branch information
JordanMartinez committed Jul 27, 2023
1 parent 9baab9d commit cfd1a28
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 72 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Notable changes to this project are documented in this file. The format is based
## [Unreleased]

Breaking changes:
- Update node libraries to latest releases (#48 by @JordanMartinez)

New features:

Expand Down
6 changes: 3 additions & 3 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
"purescript-foreign": "^7.0.0",
"purescript-foreign-object": "^4.0.0",
"purescript-maybe": "^6.0.0",
"purescript-node-buffer": "^8.0.0",
"purescript-node-net": "^4.0.0",
"purescript-node-streams": "^7.0.0",
"purescript-node-buffer": "^9.0.0",
"purescript-node-net": "^5.1.0",
"purescript-node-streams": "^9.0.0",
"purescript-node-url": "^6.0.0",
"purescript-nullable": "^6.0.0",
"purescript-options": "^7.0.0",
Expand Down
6 changes: 3 additions & 3 deletions src/Node/HTTP.purs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import Data.Nullable (Nullable, toNullable)
import Effect (Effect)
import Foreign.Object (Object)
import Node.Buffer (Buffer)
import Node.Net.Socket (Socket)
import Node.Net.Types (Socket, TCP)
import Node.Stream (Writable, Readable)
import Unsafe.Coerce (unsafeCoerce)

Expand Down Expand Up @@ -72,10 +72,10 @@ type ListenOptions =
foreign import listenSocket :: Server -> String -> Effect Unit -> Effect Unit

-- | Listen to `connect` events on the server
foreign import onConnect :: Server -> (Request -> Socket -> Buffer -> Effect Unit) -> Effect Unit
foreign import onConnect :: Server -> (Request -> Socket TCP -> Buffer -> Effect Unit) -> Effect Unit

-- | Listen to `upgrade` events on the server
foreign import onUpgrade :: Server -> (Request -> Socket -> Buffer -> Effect Unit) -> Effect Unit
foreign import onUpgrade :: Server -> (Request -> Socket TCP -> Buffer -> Effect Unit) -> Effect Unit

-- | Get the request HTTP version
httpVersion :: Request -> String
Expand Down
47 changes: 40 additions & 7 deletions src/Node/HTTP/Secure.purs
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,17 @@ import Unsafe.Coerce (unsafeCoerce)

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

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

-- | The type of HTTPS server options
Expand All @@ -120,16 +121,22 @@ rejectUnauthorized = opt "rejectUnauthorized"
-- | The npnProtocols option can be a String, a Buffer, a Uint8Array, or an
-- | array of any of those types.
data NPNProtocols

npnProtocolsString :: String -> NPNProtocols
npnProtocolsString = unsafeCoerce

npnProtocolsBuffer :: Buffer -> NPNProtocols
npnProtocolsBuffer = unsafeCoerce

npnProtocolsUint8Array :: Uint8Array -> NPNProtocols
npnProtocolsUint8Array = unsafeCoerce

npnProtocolsStringArray :: Array String -> NPNProtocols
npnProtocolsStringArray = unsafeCoerce

npnProtocolsBufferArray :: Array Buffer -> NPNProtocols
npnProtocolsBufferArray = unsafeCoerce

npnProtocolsUint8ArrayArray :: Array Uint8Array -> NPNProtocols
npnProtocolsUint8ArrayArray = unsafeCoerce

Expand All @@ -140,16 +147,22 @@ npnProtocols = opt "NPNProtocols"
-- | The alpnProtocols option can be a String, a Buffer, a Uint8Array, or an
-- | array of any of those types.
data ALPNProtocols

alpnProtocolsString :: String -> ALPNProtocols
alpnProtocolsString = unsafeCoerce

alpnProtocolsBuffer :: Buffer -> ALPNProtocols
alpnProtocolsBuffer = unsafeCoerce

alpnProtocolsUint8Array :: Uint8Array -> ALPNProtocols
alpnProtocolsUint8Array = unsafeCoerce

alpnProtocolsStringArray :: Array String -> ALPNProtocols
alpnProtocolsStringArray = unsafeCoerce

alpnProtocolsBufferArray :: Array Buffer -> ALPNProtocols
alpnProtocolsBufferArray = unsafeCoerce

alpnProtocolsUint8ArrayArray :: Array Uint8Array -> ALPNProtocols
alpnProtocolsUint8ArrayArray = unsafeCoerce

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

-- | The PFX option can take either a String or a Buffer
data PFX

pfxString :: String -> PFX
pfxString = unsafeCoerce

pfxBuffer :: Buffer -> PFX
pfxBuffer = unsafeCoerce

Expand All @@ -179,12 +194,16 @@ pfx = opt "pfx"
-- | The key option can be a String, a Buffer, an array of strings, or an array
-- | of buffers.
data Key

keyString :: String -> Key
keyString = unsafeCoerce

keyBuffer :: Buffer -> Key
keyBuffer = unsafeCoerce

keyStringArray :: Array String -> Key
keyStringArray = unsafeCoerce

keyBufferArray :: Array Buffer -> Key
keyBufferArray = unsafeCoerce

Expand All @@ -199,12 +218,16 @@ passphrase = opt "passphrase"
-- | The cert option can be a String, a Buffer, an array of strings, or an array
-- | of buffers.
data Cert

certString :: String -> Cert
certString = unsafeCoerce

certBuffer :: Buffer -> Cert
certBuffer = unsafeCoerce

certStringArray :: Array String -> Cert
certStringArray = unsafeCoerce

certBufferArray :: Array Buffer -> Cert
certBufferArray = unsafeCoerce

Expand All @@ -215,12 +238,16 @@ cert = opt "cert"
-- | The CA option can be a String, a Buffer, an array of strings, or an array
-- | of buffers.
data CA

caString :: String -> CA
caString = unsafeCoerce

caBuffer :: Buffer -> CA
caBuffer = unsafeCoerce

caStringArray :: Array String -> CA
caStringArray = unsafeCoerce

caBufferArray :: Array Buffer -> CA
caBufferArray = unsafeCoerce

Expand All @@ -231,12 +258,16 @@ ca = opt "ca"
-- | The CRL option can be a String, a Buffer, an array of strings, or an array
-- | of buffers.
data CRL

crlString :: String -> CRL
crlString = unsafeCoerce

crlBuffer :: Buffer -> CRL
crlBuffer = unsafeCoerce

crlStringArray :: Array String -> CRL
crlStringArray = unsafeCoerce

crlBufferArray :: Array Buffer -> CRL
crlBufferArray = unsafeCoerce

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

-- | The DHParam option can take either a String or a Buffer
data DHParam

dhparamString :: String -> DHParam
dhparamString = unsafeCoerce

dhparamBuffer :: Buffer -> DHParam
dhparamBuffer = unsafeCoerce

Expand Down
6 changes: 6 additions & 0 deletions test/Main.js
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
import http from "node:http";
import https from "node:https";
export const createServerOnly = () => http.createServer();
export const createSecureServerOnlyImpl = (opts) => https.createServer(opts);
export const onRequestImpl = (server, cb) => server.on("request", cb);
export const stdout = process.stdout;
export const setTimeoutImpl = (int, cb) => setTimeout(cb, int);
Loading

0 comments on commit cfd1a28

Please sign in to comment.