From de0d8c15b50b8d92daa86f617e701e3d7667ccad Mon Sep 17 00:00:00 2001 From: Adrian Sieber Date: Sat, 8 Sep 2018 20:46:12 +0000 Subject: [PATCH 1/3] Upgrade dependencies for PureScript 0.12 --- bower.json | 17 +++++++------- package-lock.json | 34 ++++++++++++++++++++++++++++ package.json | 7 +++--- src/Data/YAML/Foreign/Decode.purs | 10 ++++----- src/Data/YAML/Foreign/Encode.purs | 7 +----- test/Instances.purs | 22 +++++++++--------- test/Main.purs | 37 +++++++++++++------------------ 7 files changed, 79 insertions(+), 55 deletions(-) create mode 100644 package-lock.json diff --git a/bower.json b/bower.json index fc282ae..efbb607 100644 --- a/bower.json +++ b/bower.json @@ -14,15 +14,16 @@ ], "dependencies": { "js-yaml": "^3.4.6", - "purescript-functions": "^3.0.0", - "purescript-foreign": "^4.0.0", - "purescript-foreign-generic": "^4.1.0", - "purescript-unsafe-coerce": "^3.0.0", - "purescript-argonaut-core": "^3.1.0" + "purescript-argonaut-core": "^4.0.1", + "purescript-foreign": "^5.0.0", + "purescript-foreign-generic": "^7.0.0", + "purescript-functions": "^4.0.0", + "purescript-ordered-collections": "^1.1.0", + "purescript-unsafe-coerce": "^4.0.0" }, "devDependencies": { - "purescript-console": "^3.0.0", - "purescript-spec": "^1.0.0", - "purescript-argonaut-codecs": "^3.0.1" + "purescript-argonaut-codecs": "^4.0.2", + "purescript-console": "^4.1.0", + "purescript-spec": "^3.0.0" } } diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..a5a1e3a --- /dev/null +++ b/package-lock.json @@ -0,0 +1,34 @@ +{ + "name": "purescript-yaml-next", + "requires": true, + "lockfileVersion": 1, + "dependencies": { + "argparse": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", + "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", + "requires": { + "sprintf-js": "1.0.3" + } + }, + "esprima": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", + "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==" + }, + "js-yaml": { + "version": "3.12.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.12.0.tgz", + "integrity": "sha512-PIt2cnwmPfL4hKNwqeiuz4bKfnzHTBv6HyVgjahA6mPLwPDzjDWrplJBMjHUFxku/N3FlmrbyPclad+I+4mJ3A==", + "requires": { + "argparse": "1.0.10", + "esprima": "4.0.1" + } + }, + "sprintf-js": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", + "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=" + } + } +} diff --git a/package.json b/package.json index 1002b60..db97dbd 100644 --- a/package.json +++ b/package.json @@ -3,15 +3,14 @@ "license": "SEE LICENSE FILE", "repository": "", "private": true, - "contributors": [ ], + "contributors": [], "main": "main.js", "scripts": { "postinstall": "bower install", "build": "pulp build" }, - "devDependencies": { - }, + "devDependencies": {}, "dependencies": { - "js-yaml": "^3.4.6" + "js-yaml": "^3.12.0" } } diff --git a/src/Data/YAML/Foreign/Decode.purs b/src/Data/YAML/Foreign/Decode.purs index 74be7e8..ec0a88a 100644 --- a/src/Data/YAML/Foreign/Decode.purs +++ b/src/Data/YAML/Foreign/Decode.purs @@ -3,10 +3,10 @@ module Data.YAML.Foreign.Decode ( parseYAMLToJson ) where -import Data.Foreign (F, Foreign, ForeignError(..), fail) -import Data.Foreign.Generic (genericDecode) -import Data.Foreign.Generic.Class (class GenericDecode) -import Data.Foreign.Generic.Types (Options) +import Foreign (F, Foreign, ForeignError(..), fail) +import Foreign.Generic (genericDecode) +import Foreign.Generic.Class (class GenericDecode) +import Foreign.Generic.Types (Options) import Data.Function.Uncurried (Fn3, runFn3) import Data.Generic.Rep (class Generic) import Prelude ((>=>), (<<<), pure, (>>=)) @@ -17,7 +17,7 @@ foreign import parseYAMLImpl :: forall r. Fn3 (String -> r) (Foreign -> r) Strin -- | Attempt to parse a YAML string, returning the result as foreign data. parseYAML :: String -> F Foreign -parseYAML yaml = runFn3 parseYAMLImpl (fail <<< JSONError) pure yaml +parseYAML yaml = runFn3 parseYAMLImpl (fail <<< ForeignError) pure yaml -- | Attempt to parse a YAML string, returning the result as Json parseYAMLToJson :: String -> F Json diff --git a/src/Data/YAML/Foreign/Encode.purs b/src/Data/YAML/Foreign/Encode.purs index b00744c..8f17b3d 100644 --- a/src/Data/YAML/Foreign/Encode.purs +++ b/src/Data/YAML/Foreign/Encode.purs @@ -9,8 +9,6 @@ module Data.YAML.Foreign.Encode ( import Data.Map as M import Data.Map (Map) -import Data.StrMap as StrMap -import Data.StrMap (StrMap) import Data.Array (toUnfoldable) import Data.Function.Uncurried (Fn4, runFn4) import Data.List (List) @@ -54,11 +52,8 @@ instance eqYValue :: Eq YValue where class ToYAML a where toYAML :: a -> YValue -instance strMapToYAML :: (ToYAML a) => ToYAML (StrMap a) where - toYAML strMap = YObject $ StrMap.fold (\acc key value -> M.insert key (toYAML value) acc) M.empty strMap - instance mapToYAML :: (ToYAML a) => ToYAML (Map String a) where - toYAML m = YObject $ M.mapWithKey (\key value -> toYAML value) m + toYAML m = YObject $ map (\value -> toYAML value) m instance booleanToYAML :: ToYAML Boolean where toYAML = YBoolean diff --git a/test/Instances.purs b/test/Instances.purs index e686498..0d8f5c2 100644 --- a/test/Instances.purs +++ b/test/Instances.purs @@ -5,7 +5,9 @@ import Data.Argonaut.Core (toObject, toString) import Data.Argonaut.Decode (getField) import Data.Argonaut.Decode.Class (class DecodeJson) import Data.Either (Either(..)) -import Data.Generic (class Generic, gShow, gEq) +import Data.Generic.Rep (class Generic) +import Data.Generic.Rep.Eq (genericEq) +import Data.Generic.Rep.Show (genericShow) import Data.Maybe (maybe) import Prelude (class Eq, class Show, bind, pure, ($)) @@ -23,17 +25,17 @@ data GeoObject = GeoObject , coverage :: Number } -derive instance genericGeoObject :: Generic GeoObject -instance showGeoObject :: Show GeoObject where show = gShow -instance eqGeoObject :: Eq GeoObject where eq = gEq +derive instance genericGeoObject :: Generic GeoObject _ +instance showGeoObject :: Show GeoObject where show = genericShow +instance eqGeoObject :: Eq GeoObject where eq = genericEq -derive instance genericPoint :: Generic Point -instance showPoint :: Show Point where show = gShow -instance eqPoint :: Eq Point where eq = gEq +derive instance genericPoint :: Generic Point _ +instance showPoint :: Show Point where show = genericShow +instance eqPoint :: Eq Point where eq = genericEq -derive instance genericMobility :: Generic Mobility -instance showMobility :: Show Mobility where show = gShow -instance eqMobility :: Eq Mobility where eq = gEq +derive instance genericMobility :: Generic Mobility _ +instance showMobility :: Show Mobility where show = genericShow +instance eqMobility :: Eq Mobility where eq = genericEq instance geoJson :: DecodeJson GeoObject where decodeJson s = do diff --git a/test/Main.purs b/test/Main.purs index 9bf3c0d..a107dcb 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -1,21 +1,19 @@ module Test.Main where import Data.Map as Map -import Data.StrMap as StrMap -import Control.Monad.Eff (Eff) import Control.Monad.Except (runExcept) import Data.Argonaut.Decode (class DecodeJson, decodeJson) import Data.Either (Either(..)) import Data.Map (Map) -import Data.StrMap (StrMap) import Data.YAML.Foreign.Decode (parseYAMLToJson) import Data.YAML.Foreign.Encode (printYAML) +import Effect import Prelude (Unit, discard, pure, ($), (<<<), (>>=)) import Test.Instances (GeoObject(..), Mobility(..), Point(..)) import Test.Spec (describe, it) import Test.Spec.Assertions (shouldEqual) import Test.Spec.Reporter.Console (consoleReporter) -import Test.Spec.Runner (RunnerEffects, run) +import Test.Spec.Runner (run) yamlInput :: String yamlInput = """ @@ -45,7 +43,9 @@ yamlInput = """ """ yamlOutput :: String -yamlOutput = """- Mobility: Fix +yamlOutput = """- Coverage: 10 + Mobility: Fix + Name: House Points: - X: 10 Y: 10 @@ -53,10 +53,10 @@ yamlOutput = """- Mobility: Fix Y: 10 - X: 5 Y: 5 - Coverage: 10 - Name: House Scale: 9.5 -- Mobility: Fix +- Coverage: 10 + Mobility: Fix + Name: Tree Points: - X: 1 Y: 1 @@ -64,15 +64,15 @@ yamlOutput = """- Mobility: Fix Y: 2 - X: 0 Y: 0 - Coverage: 10 - Name: Tree Scale: 1 """ yamlMapOutput :: String yamlMapOutput = """key: - - Mobility: Fix + - Coverage: 10 + Mobility: Fix + Name: House Points: - X: 10 Y: 10 @@ -80,10 +80,10 @@ yamlMapOutput = """key: Y: 10 - X: 5 Y: 5 - Coverage: 10 - Name: House Scale: 9.5 - - Mobility: Fix + - Coverage: 10 + Mobility: Fix + Name: Tree Points: - X: 1 Y: 1 @@ -91,8 +91,6 @@ yamlMapOutput = """key: Y: 2 - X: 0 Y: 0 - Coverage: 10 - Name: Tree Scale: 1 """ @@ -106,8 +104,6 @@ yamlToData s = case runExcept $ parseYAMLToJson s of Left err -> Left "Could not parse yaml" Right json -> decodeJson json -testStrMap :: StrMap (Array GeoObject) -testStrMap = StrMap.singleton "key" parsedData testMap :: Map String (Array GeoObject) testMap = Map.singleton "key" parsedData @@ -137,7 +133,7 @@ readPoint = yamlToData fullCircle :: String -> Either String String fullCircle yamlString = (readPoint yamlString) >>= pure <<< printYAML -main :: Eff (RunnerEffects ()) Unit +main :: Effect Unit main = run [consoleReporter] do describe "purescript-yaml" do describe "decode" do @@ -149,9 +145,6 @@ main = run [consoleReporter] do let encoded = printYAML parsedData encoded `shouldEqual` yamlOutput - let encodedStrMap = printYAML testStrMap - encodedStrMap `shouldEqual` yamlMapOutput - let encodedMap = printYAML testMap encodedMap `shouldEqual` yamlMapOutput From edeed57c642de75d2be8579e4ddcb06be452a6f2 Mon Sep 17 00:00:00 2001 From: Adrian Sieber Date: Sat, 8 Sep 2018 20:51:22 +0000 Subject: [PATCH 2/3] Remove deprecated "version" field --- bower.json | 1 - 1 file changed, 1 deletion(-) diff --git a/bower.json b/bower.json index efbb607..a7d4645 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,5 @@ { "name": "purescript-yaml-next", - "version": "0.1.0", "moduleType": [ "node" ], From 66b7e993b7839010babb5c217f539c0c90977ca2 Mon Sep 17 00:00:00 2001 From: Adrian Sieber Date: Sat, 8 Sep 2018 20:51:46 +0000 Subject: [PATCH 3/3] v1.0.0