Skip to content

Commit 6677362

Browse files
committed
Use newtype for Gzip
1 parent ca71737 commit 6677362

File tree

4 files changed

+13
-17
lines changed

4 files changed

+13
-17
lines changed

app/src/Fetch/Retry.purs

+3-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Registry.App.Prelude
88

99
import Effect.Aff (Error)
1010
import Effect.Aff as Aff
11-
import Fetch (class ToCoreRequestOptions, class ToRequestBody, HighlevelRequestOptions, Response, new)
11+
import Fetch (class ToCoreRequestOptions, HighlevelRequestOptions, Response, new)
1212
import Fetch (Response) as ReExport
1313
import Fetch.Core as Core
1414
import Fetch.Core.Request as CoreRequest
@@ -23,8 +23,7 @@ data RetryRequestError
2323

2424
withRetryRequest
2525
:: forall input output thruIn thruOut headers @body
26-
. ToRequestBody body
27-
=> Union input thruIn (HighlevelRequestOptions headers body)
26+
. Union input thruIn (HighlevelRequestOptions headers body)
2827
=> Union output thruOut CoreRequest.UnsafeRequestOptions
2928
=> ToCoreRequestOptions input output
3029
=> String
@@ -63,8 +62,7 @@ withRetryRequest url r =
6362
-- | https://github.com/rowtype-yoga/purescript-fetch/issues/9
6463
fetchBody
6564
:: forall input output @thruIn thruOut headers body
66-
. ToRequestBody body
67-
=> Union input thruIn (HighlevelRequestOptions headers body)
65+
. Union input thruIn (HighlevelRequestOptions headers body)
6866
=> Union output thruOut CoreRequest.UnsafeRequestOptions
6967
=> ToCoreRequestOptions input output
7068
=> String

foreign/src/Foreign/Gzip.js

-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@ export const compressImpl = (input, onError, onBuffer) =>
66
);
77

88
export const toRequestBodyImpl = (a) => a;
9-
export const toBuffer = (a) => a;

foreign/src/Foreign/Gzip.purs

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module Registry.Foreign.Gzip
2-
( compress
3-
, toBuffer
4-
, Gzipped
2+
( Gzip(..)
3+
, compress
54
) where
65

76
import Prelude
@@ -15,18 +14,17 @@ import Fetch (class ToRequestBody)
1514
import Fetch.Core.RequestBody (RequestBody)
1615
import Node.Buffer (Buffer)
1716

18-
foreign import compressImpl :: EffectFn3 String (EffectFn1 Error Unit) (EffectFn1 Gzipped Unit) Unit
17+
foreign import compressImpl :: EffectFn3 String (EffectFn1 Error Unit) (EffectFn1 Gzip Unit) Unit
1918

20-
foreign import data Gzipped :: Type
19+
foreign import toRequestBodyImpl :: Buffer -> RequestBody
2120

22-
foreign import toRequestBodyImpl :: Gzipped -> RequestBody
23-
foreign import toBuffer :: Gzipped -> Buffer
21+
newtype Gzip = Gzip Buffer
2422

25-
instance ToRequestBody Gzipped where
26-
toRequestBody = toRequestBodyImpl
23+
instance ToRequestBody Gzip where
24+
toRequestBody (Gzip buffer) = toRequestBodyImpl buffer
2725

2826
-- | Compress a string using gzip.
29-
compress :: forall m. MonadAff m => String -> m Gzipped
27+
compress :: forall m. MonadAff m => String -> m Gzip
3028
compress input = liftAff do
3129
makeAff \handle -> do
3230
runEffectFn3 compressImpl input

foreign/test/Foreign/Gzip.purs

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Data.Either (Either(..))
66
import Node.FS.Aff as FS.Aff
77
import Node.Library.Execa as Execa
88
import Node.Path as Path
9+
import Registry.Foreign.Gzip (Gzip(..))
910
import Registry.Foreign.Gzip as Gzip
1011
import Registry.Foreign.Tmp as Tmp
1112
import Registry.Test.Assert as Assert
@@ -19,7 +20,7 @@ spec = do
1920
let
2021
file = Path.concat [ tmp, "out.gz" ]
2122
contents = "<contents>"
22-
buffer <- Gzip.toBuffer <$> Gzip.compress contents
23+
Gzip buffer <- Gzip.compress contents
2324
FS.Aff.writeFile file buffer
2425
result <- _.result =<< Execa.execa "zcat" [ file ] identity
2526
(_.stdout <$> result) `Assert.shouldEqual` Right contents

0 commit comments

Comments
 (0)