Skip to content

Commit 44fc324

Browse files
authored
Merge pull request #15 from purescript-contrib/0.9.1-updates
Updates for 0.9.1
2 parents dfa3559 + 717f785 commit 44fc324

File tree

12 files changed

+447
-408
lines changed

12 files changed

+447
-408
lines changed

.gitignore

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/.*
22
!/.gitignore
33
!/.travis.yml
4-
bower_components/
5-
node_modules/
6-
output/
7-
dist/
8-
npm-debug.log
4+
/bower_components/
5+
/node_modules/
6+
/output/

.travis.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
language: node_js
2-
sudo: false
3-
node_js:
4-
- 5
2+
dist: trusty
3+
sudo: required
4+
node_js: 6
55
install:
66
- npm install -g bower
77
- npm install
88
script:
9-
- npm test
9+
- bower install --production
10+
- npm run -s build
11+
- bower install
12+
- npm -s test
1013
after_success:
1114
- >-
1215
test $TRAVIS_TAG &&
13-
node_modules/.bin/psc-publish > .pursuit.json &&
14-
curl -X POST http://pursuit.purescript.org/packages \
15-
-d @.pursuit.json \
16-
-H 'Accept: application/json' \
17-
-H "Authorization: token ${GITHUB_TOKEN}"
16+
echo $GITHUB_TOKEN | pulp login &&
17+
echo y | pulp publish --no-push

bower.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222
},
2323
"license": "MIT",
2424
"dependencies": {
25-
"purescript-argonaut-core": "^0.2.0",
26-
"purescript-generics": "^0.7.0",
27-
"purescript-integers": "^0.2.1"
25+
"purescript-argonaut-core": "^1.0.0",
26+
"purescript-generics": "^1.0.0",
27+
"purescript-integers": "^1.0.0"
2828
},
2929
"devDependencies": {
30-
"purescript-strongcheck-generics": "^0.3.0"
30+
"purescript-strongcheck": "^1.1.1",
31+
"purescript-strongcheck-generics": "garyb/purescript-strongcheck-generics#0.9.1-updates"
3132
}
3233
}

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"private": true,
33
"scripts": {
4-
"postinstall": "pulp dep install",
54
"clean": "rimraf output && rimraf .pulp-cache",
6-
"build": "pulp build",
5+
"build": "pulp build --censor-lib --strict",
76
"test": "pulp test"
87
},
98
"devDependencies": {
10-
"pulp": "^7.0.0",
11-
"purescript": "^0.7.6",
12-
"rimraf": "^2.4.4"
9+
"pulp": "^9.0.0",
10+
"purescript-psa": "^0.3.9",
11+
"purescript": "^0.9.1",
12+
"rimraf": "^2.5.0"
1313
}
1414
}

src/Data/Argonaut/Combinators.purs

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/Data/Argonaut/Decode.purs

Lines changed: 4 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -1,141 +1,7 @@
11
module Data.Argonaut.Decode
2-
( DecodeJson
3-
, decodeJson
4-
, gDecodeJson
5-
, gDecodeJson'
6-
, decodeMaybe
2+
( module Data.Argonaut.Decode.Class
3+
, module Data.Argonaut.Decode.Combinators
74
) where
85

9-
import Prelude
10-
11-
import Control.Alt ((<|>))
12-
import Control.Bind ((=<<))
13-
import Data.Argonaut.Core (Json(), isNull, foldJsonNull, foldJsonBoolean, foldJsonNumber, foldJsonString, toArray, toNumber, toObject, toString, toBoolean)
14-
import Data.Array (zipWithA)
15-
import Data.Either (either, Either(..))
16-
import Data.Foldable (find)
17-
import Data.Generic (Generic, GenericSpine(..), GenericSignature(..), fromSpine, toSignature)
18-
import Data.Int (fromNumber)
19-
import Data.List (List(..), toList)
20-
import Data.Map as Map
21-
import Data.Maybe (maybe, Maybe(..))
22-
import Data.String (charAt, toChar)
23-
import Data.StrMap as M
24-
import Data.Traversable (traverse, for)
25-
import Data.Tuple (Tuple(..))
26-
import Type.Proxy (Proxy(..))
27-
28-
class DecodeJson a where
29-
decodeJson :: Json -> Either String a
30-
31-
-- | Decode `Json` representation of a value which has a `Generic` type.
32-
gDecodeJson :: forall a. (Generic a) => Json -> Either String a
33-
gDecodeJson json = maybe (Left "fromSpine failed") Right <<< fromSpine
34-
=<< gDecodeJson' (toSignature (Proxy :: Proxy a)) json
35-
36-
-- | Decode `Json` representation of a `GenericSpine`.
37-
gDecodeJson' :: GenericSignature -> Json -> Either String GenericSpine
38-
gDecodeJson' signature json = case signature of
39-
SigNumber -> SNumber <$> mFail "Expected a number" (toNumber json)
40-
SigInt -> SInt <$> mFail "Expected an integer number" (fromNumber =<< toNumber json)
41-
SigString -> SString <$> mFail "Expected a string" (toString json)
42-
SigChar -> SChar <$> mFail "Expected a char" (toChar =<< toString json)
43-
SigBoolean -> SBoolean <$> mFail "Expected a boolean" (toBoolean json)
44-
SigArray thunk -> do
45-
jArr <- mFail "Expected an array" $ toArray json
46-
SArray <$> traverse (map const <<< gDecodeJson' (thunk unit)) jArr
47-
SigRecord props -> do
48-
jObj <- mFail "Expected an object" $ toObject json
49-
SRecord <$> for props \({recLabel: lbl, recValue: val}) -> do
50-
pf <- mFail ("'" <> lbl <> "' property missing") (M.lookup lbl jObj)
51-
sp <- gDecodeJson' (val unit) pf
52-
pure { recLabel: lbl, recValue: const sp }
53-
SigProd typeConstr alts -> do
54-
let decodingErr msg = "When decoding a " ++ typeConstr ++ ": " ++ msg
55-
jObj <- mFail (decodingErr "expected an object") (toObject json)
56-
tagJson <- mFail (decodingErr "'tag' property is missing") (M.lookup "tag" jObj)
57-
tag <- mFail (decodingErr "'tag' property is not a string") (toString tagJson)
58-
case find ((tag ==) <<< _.sigConstructor) alts of
59-
Nothing -> Left (decodingErr ("'" <> tag <> "' isn't a valid constructor"))
60-
Just { sigValues: sigValues } -> do
61-
vals <- mFail (decodingErr "'values' array is missing") (toArray =<< M.lookup "values" jObj)
62-
sps <- zipWithA (\k -> gDecodeJson' (k unit)) sigValues vals
63-
pure (SProd tag (const <$> sps))
64-
where
65-
mFail :: forall a. String -> Maybe a -> Either String a
66-
mFail msg = maybe (Left msg) Right
67-
68-
instance decodeJsonMaybe :: (DecodeJson a) => DecodeJson (Maybe a) where
69-
decodeJson j
70-
| isNull j = pure Nothing
71-
| otherwise = (Just <$> decodeJson j) <|> (pure Nothing)
72-
73-
instance decodeJsonTuple :: (DecodeJson a, DecodeJson b) => DecodeJson (Tuple a b) where
74-
decodeJson j = decodeJson j >>= f
75-
where
76-
f (Cons a (Cons b Nil)) = Tuple <$> decodeJson a <*> decodeJson b
77-
f _ = Left "Couldn't decode Tuple"
78-
79-
instance decodeJsonEither :: (DecodeJson a, DecodeJson b) => DecodeJson (Either a b) where
80-
decodeJson j =
81-
case toObject j of
82-
Just obj -> do
83-
tag <- just (M.lookup "tag" obj)
84-
val <- just (M.lookup "value" obj)
85-
case toString tag of
86-
Just "Right" ->
87-
Right <$> decodeJson val
88-
Just "Left" ->
89-
Left <$> decodeJson val
90-
_ ->
91-
Left "Couldn't decode Either"
92-
_ ->
93-
Left "Couldn't decode Either"
94-
where
95-
just (Just x) = Right x
96-
just Nothing = Left "Couldn't decode Either"
97-
98-
instance decodeJsonNull :: DecodeJson Unit where
99-
decodeJson = foldJsonNull (Left "Not null") (const $ Right unit)
100-
101-
instance decodeJsonBoolean :: DecodeJson Boolean where
102-
decodeJson = foldJsonBoolean (Left "Not a Boolean") Right
103-
104-
instance decodeJsonNumber :: DecodeJson Number where
105-
decodeJson = foldJsonNumber (Left "Not a Number") Right
106-
107-
instance decodeJsonInt :: DecodeJson Int where
108-
decodeJson num = foldJsonNumber (Left "Not a Number") go num
109-
where go num = maybe (Left "Not an Int") Right $ fromNumber num
110-
111-
instance decodeJsonString :: DecodeJson String where
112-
decodeJson = foldJsonString (Left "Not a String") Right
113-
114-
instance decodeJsonJson :: DecodeJson Json where
115-
decodeJson = Right
116-
117-
instance decodeJsonChar :: DecodeJson Char where
118-
decodeJson j = (charAt 0 <$> decodeJson j) >>= go where
119-
go Nothing = Left $ "Expected character but found: " ++ show j
120-
go (Just c) = Right c
121-
122-
instance decodeStrMap :: (DecodeJson a) => DecodeJson (M.StrMap a) where
123-
decodeJson json = maybe (Left "Couldn't decode StrMap") Right $ do
124-
obj <- toObject json
125-
traverse decodeMaybe obj
126-
127-
instance decodeArray :: (DecodeJson a) => DecodeJson (Array a) where
128-
decodeJson json = maybe (Left "Couldn't decode Array") Right $ do
129-
obj <- toArray json
130-
traverse decodeMaybe obj
131-
132-
instance decodeList :: (DecodeJson a) => DecodeJson (List a) where
133-
decodeJson json = maybe (Left "Couldn't decode List") Right $ do
134-
lst <- toList <$> toArray json
135-
traverse decodeMaybe lst
136-
137-
instance decodeMap :: (Ord a, DecodeJson a, DecodeJson b) => DecodeJson (Map.Map a b) where
138-
decodeJson j = Map.fromList <$> decodeJson j
139-
140-
decodeMaybe :: forall a. (DecodeJson a) => Json -> Maybe a
141-
decodeMaybe json = either (const Nothing) pure $ decodeJson json
6+
import Data.Argonaut.Decode.Class (class DecodeJson, decodeJson, gDecodeJson, gDecodeJson')
7+
import Data.Argonaut.Decode.Combinators (getField, (.?))

0 commit comments

Comments
 (0)