Skip to content

Commit

Permalink
Convert doc to json immediately; drop types
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanMartinez committed Nov 24, 2023
1 parent 3ed5360 commit edff201
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 37 deletions.
5 changes: 1 addition & 4 deletions app/src/App/PackageManagers/Spago.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ import Yaml from 'yaml';
export function yamlDocParserImpl(fail, succ, s) {
const doc = Yaml.parseDocument(s);
if (doc.errors.length === 0) {
return succ(doc);
return succ(doc.toJSON());
} else {
// TODO: eh, we should return properly structured errors here
return fail(JSON.stringify(doc.errors));
}
}

export function toJsonImpl(doc) {
return doc.toJSON();
}
38 changes: 5 additions & 33 deletions app/src/App/PackageManagers/Spago.purs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Data.Array.NonEmpty as NonEmptyArray
import Data.Codec.Argonaut as CA
import Data.Codec.Argonaut.Record as CAR
import Data.Either as Either
import Data.Function.Uncurried (Fn1, Fn3, runFn1, runFn3)
import Data.Function.Uncurried (Fn3, runFn3)
import Data.List as List
import Data.Map as Map
import Data.Profunctor as Profunctor
Expand All @@ -22,16 +22,13 @@ import Node.FS.Sync as FS
import Registry.App.Effect.Log (LOG)
import Registry.App.Effect.Log as Log
import Registry.Internal.Codec as Internal.Codec
import Registry.License (License)
import Registry.License as License
import Registry.Location (Location)
import Registry.Location as Location
import Registry.Manifest (Manifest(..))
import Registry.PackageName (PackageName)
import Registry.PackageName as PackageName
import Registry.Range (Range)
import Registry.Range as Range
import Registry.Version (Version)
import Registry.Version as Version
import Run (AFF, EFFECT, Run)
import Run.Except (EXCEPT)
Expand Down Expand Up @@ -64,8 +61,8 @@ getSpagoManifest spagoYamlPath = do
result <- Aff.attempt $ FS.Aff.readTextFile UTF8 path
pure do
yamlStr <- lmap Aff.message result
doc <- lmap (append "YAML: ") (yamlParser yamlStr)
lmap CA.printJsonDecodeError $ CA.decode configCodec (toJson doc)
docAsJson <- lmap (append "YAML: ") (yamlParser yamlStr)
lmap CA.printJsonDecodeError $ CA.decode configCodec docAsJson
where
configCodec = CAR.object "PartialSpagoConfig"
{ package: CAR.optional $ CAR.object "PackageConfig"
Expand Down Expand Up @@ -158,35 +155,10 @@ getSpagoManifest spagoYamlPath = do
, excludeFiles
}

type PartialSpagoConfig =
{ package :: Maybe PartialPackageConfig
}

type PartialPackageConfig =
{ name :: PackageName
, description :: Maybe String
, dependencies :: Map PackageName (Maybe Range)
, publish :: Maybe PublishConfig
}

type PublishConfig =
{ version :: Version
, license :: License
, location :: Maybe Location
, include :: Maybe (Array FilePath)
, exclude :: Maybe (Array FilePath)
}

foreign import data YamlDoc :: Type -> Type

-- | Parse a JSON string, constructing the `Toml` value described by the string.
-- | To convert a string into a `Toml` string, see `fromString`.
yamlParser :: forall a. String -> Either String (YamlDoc a)
yamlParser :: String -> Either String Core.Json
yamlParser j = runFn3 yamlDocParserImpl Left Right j

foreign import yamlDocParserImpl :: forall a b. Fn3 (String -> a) (YamlDoc b -> a) String a

toJson :: forall a. YamlDoc a -> Core.Json
toJson = runFn1 toJsonImpl
foreign import yamlDocParserImpl :: forall a. Fn3 (String -> a) (Core.Json -> a) String a

foreign import toJsonImpl :: forall a. Fn1 (YamlDoc a) Core.Json

0 comments on commit edff201

Please sign in to comment.