Merge pull request #9 from archaeron/upgrade-ps-0.14

Upgrade for PureScript 0.14
This commit is contained in:
Dominick Gendill 2021-03-18 19:28:37 -06:00 committed by GitHub
commit 627d1f3e95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 67 additions and 55 deletions

56
package-lock.json generated
View File

@ -1,34 +1,46 @@
{
"name": "purescript-yaml-next",
"lockfileVersion": 2,
"requires": true,
"lockfileVersion": 1,
"packages": {
"": {
"hasInstallScript": true,
"license": "SEE LICENSE FILE",
"dependencies": {
"js-yaml": "^4.0.0"
},
"devDependencies": {}
},
"node_modules/argparse": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
"integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q=="
},
"node_modules/js-yaml": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.0.0.tgz",
"integrity": "sha512-pqon0s+4ScYUvX30wxQi3PogGFAlUyH0awepWvwkj4jD4v+ova3RiYw8bmA6x2rDrEaj8i/oWKoRxpVNW+Re8Q==",
"dependencies": {
"argparse": "^2.0.1"
},
"bin": {
"js-yaml": "bin/js-yaml.js"
}
}
},
"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.2"
}
},
"esprima": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz",
"integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A=="
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
"integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q=="
},
"js-yaml": {
"version": "3.13.1",
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz",
"integrity": "sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==",
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.0.0.tgz",
"integrity": "sha512-pqon0s+4ScYUvX30wxQi3PogGFAlUyH0awepWvwkj4jD4v+ova3RiYw8bmA6x2rDrEaj8i/oWKoRxpVNW+Re8Q==",
"requires": {
"argparse": "^1.0.7",
"esprima": "^4.0.0"
"argparse": "^2.0.1"
}
},
"sprintf-js": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz",
"integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw="
}
}
}

View File

@ -6,10 +6,11 @@
"contributors": [],
"main": "main.js",
"scripts": {
"test": "spago test",
"postinstall": "spago build"
},
"devDependencies": {},
"dependencies": {
"js-yaml": "^3.13.1"
"js-yaml": "^4.0.0"
}
}

View File

@ -1,5 +1,5 @@
let upstream =
https://github.com/purescript/package-sets/releases/download/psc-0.13.3-20191005/packages.dhall sha256:ba287d858ada09c4164792ad4e643013b742c208cbedf5de2e35ee27b64b6817
https://github.com/purescript/package-sets/releases/download/psc-0.14.0-20210317/packages.dhall sha256:e2e744972f9b60188dcf07f41418661b505c9ee2e9f91e57e67daefad3a5ae09
let overrides = {=}

View File

@ -6,7 +6,6 @@
, "console"
, "effect"
, "foreign"
, "foreign-generic"
, "functions"
, "ordered-collections"
, "psci-support"

View File

@ -4,7 +4,7 @@ var yaml = require('js-yaml');
exports.parseYAMLImpl = function(left, right, str) {
try {
return right(yaml.safeLoad(str));
return right(yaml.load(str));
} catch (e) {
return left(e.toString());
}

View File

@ -1,27 +1,23 @@
module Data.YAML.Foreign.Decode (
readYAMLGeneric,
parseYAMLToJson
) where
module Data.YAML.Foreign.Decode (parseYAMLToJson)
where
import Foreign (F, Foreign, ForeignError(..), fail)
import Foreign.Generic (genericDecode)
import Foreign.Generic.Class (class GenericDecode, Options)
import Data.Function.Uncurried (Fn3, runFn3)
import Data.Generic.Rep (class Generic)
import Prelude ((>=>), (<<<), pure, (>>=))
import Prelude (pure, (<<<), (>>=))
import Unsafe.Coerce (unsafeCoerce)
import Data.Argonaut.Core (Json)
foreign import parseYAMLImpl :: forall r. Fn3 (String -> r) (Foreign -> r) String r
foreign import parseYAMLImpl :: forall r.
Fn3 (String -> r) (Foreign -> r) String r
-- | Attempt to parse a YAML string, returning the result as foreign data.
parseYAML :: String -> F Foreign
parseYAML yaml = runFn3 parseYAMLImpl (fail <<< ForeignError) 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
parseYAMLToJson yaml = parseYAML yaml >>= pure <<< unsafeCoerce
-- | Automatically generate a YAML parser for your data from a generic instance.
readYAMLGeneric :: forall a rep. (Generic a rep) => (GenericDecode rep) => Options -> String -> F a
readYAMLGeneric opts = parseYAML >=> genericDecode opts
parseYAMLToJson yaml =
parseYAML yaml >>= pure <<< unsafeCoerce

View File

@ -14,5 +14,5 @@ exports.objToHash = function(valueToYAMLImpl, fst, snd, obj) {
exports.toYAMLImpl = function(a) {
// noCompatMode does not support YAML 1.1
return yaml.safeDump(a, {noCompatMode : true});
return yaml.dump(a, {noCompatMode : true});
}

View File

@ -1,14 +1,14 @@
module Test.Instances where
import Data.YAML.Foreign.Encode
import Data.Argonaut.Core (toObject, toString)
import Data.Argonaut.Decode (decodeJson)
import Data.Argonaut.Decode.Combinators (getField)
import Data.Argonaut.Decode.Class (class DecodeJson)
import Data.Argonaut.Decode.Error (JsonDecodeError(TypeMismatch))
import Data.Either (Either(..))
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Eq (genericEq)
import Data.Generic.Rep.Show (genericShow)
import Data.Maybe (maybe)
import Data.Eq.Generic (genericEq)
import Data.Show.Generic (genericShow)
import Prelude (class Eq, class Show, bind, pure, ($))
data Point = Point Int Int
@ -38,8 +38,8 @@ instance showMobility :: Show Mobility where show = genericShow
instance eqMobility :: Eq Mobility where eq = genericEq
instance geoJson :: DecodeJson GeoObject where
decodeJson s = do
obj <- maybe (Left "GeoObject is not an object.") Right (toObject s)
decodeJson json = do
obj <- decodeJson json
name <- getField obj "Name"
scale <- getField obj "Scale"
points <- getField obj "Points"
@ -48,16 +48,17 @@ instance geoJson :: DecodeJson GeoObject where
pure $ GeoObject { name, scale, points, mobility, coverage }
instance mobilityJson :: DecodeJson Mobility where
decodeJson s = do
mob <- maybe (Left "Mobility is not a string.") Right (toString s)
decodeJson json = do
mob <- decodeJson json
case mob of
"Fix" -> pure Fix
"Flex" -> pure Flex
_ -> Left "Mobility must be either Flex or Fix"
_ -> Left $ TypeMismatch "Mobility must be either Flex or Fix"
instance pointJson :: DecodeJson Point where
decodeJson s = do
obj <- maybe (Left "Point is not an object.") Right (toObject s)
decodeJson json = do
obj <- decodeJson json
x <- getField obj "X"
y <- getField obj "Y"
pure $ Point x y

View File

@ -2,6 +2,7 @@ module Test.Main where
import Control.Monad.Except (runExcept)
import Data.Argonaut.Decode (class DecodeJson, decodeJson)
import Data.Argonaut.Decode.Error (printJsonDecodeError)
import Data.Either (Either(..))
import Data.Map (Map)
import Data.Map as Map
@ -103,8 +104,10 @@ Y: 1
yamlToData :: forall a. (DecodeJson a) => String -> Either String a
yamlToData s = case runExcept $ parseYAMLToJson s of
Left err -> Left "Could not parse yaml"
Right json -> decodeJson json
Left err -> Left "Could not parse YAML"
Right json -> case decodeJson json of
Left error -> Left $ printJsonDecodeError error
Right value -> Right value
testMap :: Map String (Array GeoObject)