Skip to content

Commit 52669ea

Browse files
authored
Merge pull request #82 from justinwoo/ivantomac-master
"purescript 0.14"
2 parents e654a1f + e6db0ba commit 52669ea

File tree

8 files changed

+62
-58
lines changed

8 files changed

+62
-58
lines changed

bower.json

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,17 @@
1212
"output"
1313
],
1414
"dependencies": {
15-
"purescript-prelude": "^4.1.1",
16-
"purescript-typelevel-prelude": "^5.0.0",
17-
"purescript-record": "^2.0.1",
18-
"purescript-variant": "^6.0.1",
19-
"purescript-nullable": "^4.1.1",
20-
"purescript-foreign-object": "^2.0.3",
21-
"purescript-globals": "^4.0.0",
22-
"purescript-foreign": "^5.0.0",
23-
"purescript-exceptions": "^4.0.0",
24-
"purescript-arrays": "^5.3.0"
15+
"purescript-prelude": "^5.0.0",
16+
"purescript-typelevel-prelude": "^6.0.0",
17+
"purescript-record": "^3.0.0",
18+
"purescript-variant": "^7.0.1",
19+
"purescript-nullable": "^5.0.0",
20+
"purescript-foreign-object": "^3.0.0",
21+
"purescript-foreign": "^6.0.0",
22+
"purescript-exceptions": "^5.0.0",
23+
"purescript-arrays": "^6.0.0"
2524
},
2625
"devDependencies": {
27-
"purescript-assert": "^4.1.0",
28-
"purescript-generics-rep": "^6.1.1"
26+
"purescript-assert": "^5.0.0"
2927
}
3028
}

ci.nix

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
11
let
22
nixpkgs = builtins.fetchTarball {
3-
# Commit to release-20.03 on 23 June 2020
43
url = "https://github.com/nixos/nixpkgs/archive/39da4240609ee0d8ea533f142ae4c7e25df95980.tar.gz";
54
sha256 = "10mp5rjnkl0s6pigbnkdf6pjwm074nf4aq7mwhfwxmz5gs5dpi71";
65
};
76
in
87

98
{ pkgs ? import nixpkgs {} }:
109

11-
let
12-
# Latest commit to the master branch as of 25 June 2020
13-
ezPscSrc = pkgs.fetchFromGitHub {
14-
owner = "justinwoo";
15-
repo = "easy-purescript-nix";
16-
rev = "2432d492b1f0cc3aa7bf8b4bdb2c7ee0219e1f4e";
17-
sha256 = "0gdg7b4yvs9rg2z6xv705miq5c9vbhimq21nfmhk9j48b3m3xkhf";
18-
};
19-
ezPsc = import ezPscSrc { inherit pkgs; };
20-
in
10+
let
11+
ezPscSrc = pkgs.fetchFromGitHub {
12+
owner = "justinwoo";
13+
repo = "easy-purescript-nix";
14+
rev = "e8a1ffafafcdf2e81adba419693eb35f3ee422f8";
15+
sha256 = "0bk32wckk82f1j5i5gva63f3b3jl8swc941c33bqc3pfg5cgkyyf";
16+
};
17+
ezPsc = import ezPscSrc { inherit pkgs; };
18+
in
2119

22-
pkgs.mkShell {
23-
buildInputs = [
24-
ezPsc.purs
25-
pkgs.nodePackages_10_x.bower
26-
pkgs.nodePackages_10_x.pulp
27-
];
28-
}
20+
pkgs.mkShell {
21+
buildInputs = [
22+
ezPsc.purs-0_14_0
23+
pkgs.nodePackages_10_x.bower
24+
pkgs.nodePackages_10_x.pulp
25+
];
26+
}

src/Simple/JSON.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
exports._parseJSON = JSON.parse;
22

33
exports._undefined = undefined;
4+
5+
exports._unsafeStringify = JSON.stringify;

src/Simple/JSON.purs

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module Simple.JSON
1010
, read_
1111
, parseJSON
1212
, undefined
13+
, unsafeStringify
1314

1415
, class ReadForeign
1516
, readImpl
@@ -49,14 +50,13 @@ import Foreign (F, Foreign, ForeignError(..), MultipleErrors, fail, isNull, isUn
4950
import Foreign.Index (readProp)
5051
import Foreign.Object (Object)
5152
import Foreign.Object as Object
52-
import Global.Unsafe (unsafeStringify)
5353
import Partial.Unsafe (unsafeCrashWith)
5454
import Prim.Row as Row
55-
import Prim.RowList (class RowToList, Cons, Nil, kind RowList)
55+
import Prim.RowList (class RowToList, Cons, Nil, RowList)
5656
import Record (get)
5757
import Record.Builder (Builder)
5858
import Record.Builder as Builder
59-
import Type.Prelude (RLProxy(..))
59+
import Type.Prelude (Proxy(..))
6060

6161
-- | An alias for the Either result of decoding
6262
type E a = Either MultipleErrors a
@@ -84,12 +84,19 @@ readJSON_ :: forall a
8484
-> Maybe a
8585
readJSON_ = hush <<< readJSON
8686

87+
-- | Uses the global JSON object to turn anything into a string. Careful! Trying
88+
-- | to serialize functions returns undefined
89+
foreign import _unsafeStringify :: forall a. a -> String
90+
91+
unsafeStringify :: forall a. a -> String
92+
unsafeStringify = _unsafeStringify
93+
8794
-- | Write a JSON string from a type `a`.
8895
writeJSON :: forall a
8996
. WriteForeign a
9097
=> a
9198
-> String
92-
writeJSON = unsafeStringify <<< writeImpl
99+
writeJSON = _unsafeStringify <<< writeImpl
93100

94101
write :: forall a
95102
. WriteForeign a
@@ -199,12 +206,12 @@ instance readRecord ::
199206
) => ReadForeign (Record fields) where
200207
readImpl o = flip Builder.build {} <$> getFields fieldListP o
201208
where
202-
fieldListP = RLProxy :: RLProxy fieldList
209+
fieldListP = Proxy :: Proxy fieldList
203210

204211
-- | A class for reading foreign values from properties
205-
class ReadForeignFields (xs :: RowList) (from :: # Type) (to :: # Type)
212+
class ReadForeignFields (xs :: RowList Type) (from :: Row Type) (to :: Row Type)
206213
| xs -> from to where
207-
getFields :: RLProxy xs
214+
getFields :: Proxy xs
208215
-> Foreign
209216
-> F (Builder (Record from) (Record to))
210217

@@ -222,7 +229,7 @@ instance readFieldsCons ::
222229
pure $ Builder.insert nameP value
223230
rest = getFields tailP obj
224231
nameP = SProxy :: SProxy name
225-
tailP = RLProxy :: RLProxy tail
232+
tailP = Proxy :: Proxy tail
226233
name = reflectSymbol nameP
227234
withExcept' = withExcept <<< map $ ErrorAtProperty name
228235

@@ -246,11 +253,11 @@ instance readForeignVariant ::
246253
( RowToList variants rl
247254
, ReadForeignVariant rl variants
248255
) => ReadForeign (Variant variants) where
249-
readImpl o = readVariantImpl (RLProxy :: RLProxy rl) o
256+
readImpl o = readVariantImpl (Proxy :: Proxy rl) o
250257

251-
class ReadForeignVariant (xs :: RowList) (row :: # Type)
258+
class ReadForeignVariant (xs :: RowList Type) (row :: Row Type)
252259
| xs -> row where
253-
readVariantImpl :: RLProxy xs
260+
readVariantImpl :: Proxy xs
254261
-> Foreign
255262
-> F (Variant row)
256263

@@ -272,7 +279,7 @@ instance readVariantCons ::
272279
pure $ inj namep value
273280
else
274281
(fail <<< ForeignError $ "Did not match variant tag " <> name)
275-
<|> readVariantImpl (RLProxy :: RLProxy tail) o
282+
<|> readVariantImpl (Proxy :: Proxy tail) o
276283
where
277284
namep = SProxy :: SProxy name
278285
name = reflectSymbol namep
@@ -318,10 +325,10 @@ instance recordWriteForeign ::
318325
) => WriteForeign (Record row) where
319326
writeImpl rec = unsafeToForeign $ Builder.build steps {}
320327
where
321-
rlp = RLProxy :: RLProxy rl
328+
rlp = Proxy :: Proxy rl
322329
steps = writeImplFields rlp rec
323330

324-
class WriteForeignFields (rl :: RowList) row (from :: # Type) (to :: # Type)
331+
class WriteForeignFields (rl :: RowList Type) row (from :: Row Type) (to :: Row Type)
325332
| rl -> row from to where
326333
writeImplFields :: forall g. g rl -> Record row -> Builder (Record from) (Record to)
327334

@@ -337,7 +344,7 @@ instance consWriteForeignFields ::
337344
where
338345
namep = SProxy :: SProxy name
339346
value = writeImpl $ get namep rec
340-
tailp = RLProxy :: RLProxy tail
347+
tailp = Proxy :: Proxy tail
341348
rest = writeImplFields tailp rec
342349
result = Builder.insert namep value <<< rest
343350
instance nilWriteForeignFields ::
@@ -348,9 +355,9 @@ instance writeForeignVariant ::
348355
( RowToList row rl
349356
, WriteForeignVariant rl row
350357
) => WriteForeign (Variant row) where
351-
writeImpl variant = writeVariantImpl (RLProxy :: RLProxy rl) variant
358+
writeImpl variant = writeVariantImpl (Proxy :: Proxy rl) variant
352359

353-
class WriteForeignVariant (rl :: RowList) (row :: # Type)
360+
class WriteForeignVariant (rl :: RowList Type) (row :: Row Type)
354361
| rl -> row where
355362
writeVariantImpl :: forall g. g rl -> Variant row -> Foreign
356363

@@ -370,7 +377,7 @@ instance consWriteForeignVariant ::
370377
on
371378
namep
372379
writeVariant
373-
(writeVariantImpl (RLProxy :: RLProxy tail))
380+
(writeVariantImpl (Proxy :: Proxy tail))
374381
variant
375382
where
376383
namep = SProxy :: SProxy name

test/EnumSumGeneric.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Control.Alt ((<|>))
66
import Control.Monad.Except (throwError)
77
import Data.Either (Either, isRight)
88
import Data.Generic.Rep (class Generic, Constructor(..), NoArguments(..), Sum(..), to)
9-
import Data.Generic.Rep.Show (genericShow)
9+
import Data.Show.Generic (genericShow)
1010
import Effect (Effect)
1111
import Foreign (Foreign)
1212
import Foreign as Foreign

test/Generic.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Prelude
55
import Control.Alt ((<|>))
66
import Data.Either (Either, isRight)
77
import Data.Generic.Rep as GR
8-
import Data.Generic.Rep.Show (genericShow)
8+
import Data.Show.Generic (genericShow)
99
import Effect (Effect)
1010
import Foreign (Foreign)
1111
import Foreign as Foreign

test/Main.purs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Prelude
44

55
import Control.Monad.Except (runExcept)
66
import Data.Bifunctor (lmap)
7-
import Data.Either (Either(..), either, fromLeft, isRight)
7+
import Data.Either (Either(..), either, isRight)
88
import Data.List (List(..), (:))
99
import Data.List.NonEmpty (NonEmptyList(..))
1010
import Data.Maybe (Maybe)
@@ -15,7 +15,6 @@ import Effect (Effect)
1515
import Effect.Exception (throw)
1616
import Foreign (Foreign, ForeignError(..), MultipleErrors)
1717
import Foreign.Object (Object)
18-
import Partial.Unsafe (unsafePartial)
1918
import Simple.JSON (class ReadForeign, class WriteForeign, parseJSON, readJSON, writeJSON)
2019
import Test.Assert (assertEqual)
2120
import Test.EnumSumGeneric as Test.EnumSumGeneric
@@ -98,8 +97,8 @@ main = do
9897

9998
-- "fails with invalid JSON"
10099
let r1 = readJSON """{ "c": 1, "d": 2}"""
101-
(unsafePartial $ fromLeft r1) `shouldEqual`
102-
(NonEmptyList (NonEmpty (ErrorAtProperty "a" (TypeMismatch "Int" "Undefined")) ((ErrorAtProperty "b" (TypeMismatch "String" "Undefined")) : (ErrorAtProperty "c" (TypeMismatch "Boolean" "Number")) : (ErrorAtProperty "d" (TypeMismatch "array" "Number")) : Nil)))
100+
r1 `shouldEqual`
101+
(Left (NonEmptyList (NonEmpty (ErrorAtProperty "a" (TypeMismatch "Int" "Undefined")) ((ErrorAtProperty "b" (TypeMismatch "String" "Undefined")) : (ErrorAtProperty "c" (TypeMismatch "Boolean" "Number")) : (ErrorAtProperty "d" (TypeMismatch "array" "Number")) : Nil))))
103102
isRight (r1 :: E MyTest) `shouldEqual` false
104103

105104
-- "works with missing Maybe fields by setting them to Nothing"
@@ -110,8 +109,8 @@ main = do
110109
let r3 = readJSON """
111110
{ "a": "asdf" }
112111
"""
113-
(unsafePartial $ fromLeft r3) `shouldEqual`
114-
(NonEmptyList (NonEmpty (ErrorAtProperty "b" (TypeMismatch "Nullable String" "Undefined")) Nil))
112+
r3 `shouldEqual`
113+
(Left (NonEmptyList (NonEmpty (ErrorAtProperty "b" (TypeMismatch "Nullable String" "Undefined")) Nil)))
115114
(isRight (r3 :: E MyTestNullable)) `shouldEqual` false
116115

117116
-- roundtrips

test/Util.purs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module Test.Util where
33
import Prelude
44

55
import Prim.Row as Row
6-
import Prim.RowList (class RowToList, Cons, Nil, kind RowList)
6+
import Prim.RowList (class RowToList, Cons, Nil, RowList)
77
import Record (get)
88
import Type.Prelude (class IsSymbol, RLProxy(..), SProxy(..))
99

@@ -17,7 +17,7 @@ equal
1717
-> Boolean
1818
equal a b = equalFields (RLProxy :: RLProxy rs) a b
1919

20-
class EqualFields (rs :: RowList) (row :: # Type) | rs -> row where
20+
class EqualFields (rs :: RowList Type) (row :: Row Type) | rs -> row where
2121
equalFields :: RLProxy rs -> Record row -> Record row -> Boolean
2222

2323
instance equalFieldsCons

0 commit comments

Comments
 (0)