Skip to content

Commit 83aad59

Browse files
Add duplex option (#3)
1 parent a4bb941 commit 83aad59

File tree

6 files changed

+41
-13
lines changed

6 files changed

+41
-13
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818

1919
- uses: actions/setup-node@v2
2020
with:
21-
node-version: "14"
21+
node-version: "20"
2222

2323
- name: Install dependencies
2424
run: |

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"private": true,
33
"scripts": {
44
"clean": "rimraf output && rimraf .pulp-cache",
5-
"build": "eslint src && pulp build -- --censor-lib --strict"
5+
"build": "eslint src && pulp build -- --censor-lib --strict",
6+
"test": "spago -x test.dhall test"
67
},
78
"devDependencies": {
89
"eslint": "^7.15.0",

src/Fetch/Core/Duplex.purs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module Fetch.Core.Duplex where
2+
3+
import Prelude
4+
5+
import Data.Maybe (Maybe(..))
6+
7+
data Duplex = Half | Full
8+
9+
derive instance Eq Duplex
10+
derive instance Ord Duplex
11+
12+
toString :: Duplex -> String
13+
toString = case _ of
14+
Half -> "half"
15+
Full -> "full"
16+
17+
fromString :: String -> Maybe Duplex
18+
fromString = case _ of
19+
"full" -> Just Full
20+
"half" -> Just Half
21+
_ -> Nothing

src/Fetch/Core/Request.purs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import Data.Newtype (un)
2020
import Data.Symbol (class IsSymbol)
2121
import Effect (Effect)
2222
import Effect.Uncurried (EffectFn2, runEffectFn2)
23+
import Fetch.Core.Duplex (Duplex)
24+
import Fetch.Core.Duplex as Duplex
2325
import Fetch.Core.Headers (Headers)
2426
import Fetch.Core.Integrity (Integrity(..))
2527
import Fetch.Core.Referrer (Referrer)
@@ -53,6 +55,7 @@ type UnsafeRequestOptions =
5355
, referrer :: String
5456
, referrerPolicy :: String
5557
, integrity :: String
58+
, duplex :: String
5659
)
5760

5861
type RequestOptions =
@@ -65,6 +68,7 @@ type RequestOptions =
6568
, referrer :: Referrer
6669
, referrerPolicy :: ReferrerPolicy
6770
, integrity :: Integrity
71+
, duplex :: Duplex
6872
)
6973

7074
toUnsafeOptions
@@ -150,3 +154,5 @@ instance ToInternalConverter ReferrerPolicy String where
150154
instance ToInternalConverter Integrity String where
151155
convertImpl = un Integrity
152156

157+
instance ToInternalConverter Duplex String where
158+
convertImpl = Duplex.toString

test.dhall

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ in conf
66
conf.dependencies
77
# [ "aff"
88
, "aff-promise"
9-
, "effect"
10-
, "spec"
11-
, "spec-discovery"
12-
, "strings"
9+
, "console"
1310
, "debug"
11+
, "effect"
12+
, "unsafe-coerce"
1413
]
1514
}

test/Main.purs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import Control.Promise as Promise
66
import Data.HTTP.Method (Method(..))
77
import Debug (spy)
88
import Effect (Effect)
9-
import Effect.Aff (launchAff, launchAff_)
9+
import Effect.Aff (launchAff_)
1010
import Effect.Class (liftEffect)
1111
import Effect.Class.Console (log)
1212
import Fetch.Core as Fetch
13+
import Fetch.Core.Duplex (Duplex(..))
1314
import Fetch.Core.Headers as Headers
1415
import Fetch.Core.Request as Request
1516
import Fetch.Core.RequestBody as RequestBody
@@ -20,12 +21,12 @@ main :: Effect Unit
2021
main = launchAff_ do
2122
let requestBody = """{"hello":"world"}"""
2223
request <- liftEffect $ Request.new "http://httpbin.org/post"
23-
{ method: POST
24-
, body: RequestBody.fromString requestBody
25-
, headers: Headers.fromRecord { "Content-Type": "application/json" }
26-
}
27-
let
28-
_ = spy "request" request
24+
{ method: POST
25+
, body: RequestBody.fromString requestBody
26+
, headers: Headers.fromRecord { "Content-Type": "application/json" }
27+
, duplex: Half
28+
}
29+
let _ = spy "request" request
2930
response <- Promise.toAffE $ unsafeCoerce $ Fetch.fetch request
3031
responseBody <- Promise.toAffE $ unsafeCoerce $ Response.text response
3132
let _ = spy "response" response

0 commit comments

Comments
 (0)