diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 06ed895..a5839aa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: - uses: actions/setup-node@v2 with: - node-version: "14" + node-version: "20" - name: Install dependencies run: | diff --git a/package.json b/package.json index 4ea39f9..7e321c0 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,8 @@ "private": true, "scripts": { "clean": "rimraf output && rimraf .pulp-cache", - "build": "eslint src && pulp build -- --censor-lib --strict" + "build": "eslint src && pulp build -- --censor-lib --strict", + "test": "spago -x test.dhall test" }, "devDependencies": { "eslint": "^7.15.0", diff --git a/src/Fetch/Core/Duplex.purs b/src/Fetch/Core/Duplex.purs new file mode 100644 index 0000000..12870a3 --- /dev/null +++ b/src/Fetch/Core/Duplex.purs @@ -0,0 +1,21 @@ +module Fetch.Core.Duplex where + +import Prelude + +import Data.Maybe (Maybe(..)) + +data Duplex = Half | Full + +derive instance Eq Duplex +derive instance Ord Duplex + +toString :: Duplex -> String +toString = case _ of + Half -> "half" + Full -> "full" + +fromString :: String -> Maybe Duplex +fromString = case _ of + "full" -> Just Full + "half" -> Just Half + _ -> Nothing diff --git a/src/Fetch/Core/Request.purs b/src/Fetch/Core/Request.purs index 5b539dc..9237b00 100644 --- a/src/Fetch/Core/Request.purs +++ b/src/Fetch/Core/Request.purs @@ -20,6 +20,8 @@ import Data.Newtype (un) import Data.Symbol (class IsSymbol) import Effect (Effect) import Effect.Uncurried (EffectFn2, runEffectFn2) +import Fetch.Core.Duplex (Duplex) +import Fetch.Core.Duplex as Duplex import Fetch.Core.Headers (Headers) import Fetch.Core.Integrity (Integrity(..)) import Fetch.Core.Referrer (Referrer) @@ -53,6 +55,7 @@ type UnsafeRequestOptions = , referrer :: String , referrerPolicy :: String , integrity :: String + , duplex :: String ) type RequestOptions = @@ -65,6 +68,7 @@ type RequestOptions = , referrer :: Referrer , referrerPolicy :: ReferrerPolicy , integrity :: Integrity + , duplex :: Duplex ) toUnsafeOptions @@ -150,3 +154,5 @@ instance ToInternalConverter ReferrerPolicy String where instance ToInternalConverter Integrity String where convertImpl = un Integrity +instance ToInternalConverter Duplex String where + convertImpl = Duplex.toString diff --git a/test.dhall b/test.dhall index 06eb399..b49bd5f 100644 --- a/test.dhall +++ b/test.dhall @@ -6,10 +6,9 @@ in conf conf.dependencies # [ "aff" , "aff-promise" - , "effect" - , "spec" - , "spec-discovery" - , "strings" + , "console" , "debug" + , "effect" + , "unsafe-coerce" ] } diff --git a/test/Main.purs b/test/Main.purs index 5418ad4..d90480c 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -6,10 +6,11 @@ import Control.Promise as Promise import Data.HTTP.Method (Method(..)) import Debug (spy) import Effect (Effect) -import Effect.Aff (launchAff, launchAff_) +import Effect.Aff (launchAff_) import Effect.Class (liftEffect) import Effect.Class.Console (log) import Fetch.Core as Fetch +import Fetch.Core.Duplex (Duplex(..)) import Fetch.Core.Headers as Headers import Fetch.Core.Request as Request import Fetch.Core.RequestBody as RequestBody @@ -20,12 +21,12 @@ main :: Effect Unit main = launchAff_ do let requestBody = """{"hello":"world"}""" request <- liftEffect $ Request.new "http://httpbin.org/post" - { method: POST - , body: RequestBody.fromString requestBody - , headers: Headers.fromRecord { "Content-Type": "application/json" } - } - let - _ = spy "request" request + { method: POST + , body: RequestBody.fromString requestBody + , headers: Headers.fromRecord { "Content-Type": "application/json" } + , duplex: Half + } + let _ = spy "request" request response <- Promise.toAffE $ unsafeCoerce $ Fetch.fetch request responseBody <- Promise.toAffE $ unsafeCoerce $ Response.text response let _ = spy "response" response