halogen-websocket-ipc-playzone/src/AlternativeMain.purs

39 lines
1.1 KiB
Plaintext

-- | To run this alternative main: spago run -m AlternativeMain
module AlternativeMain where
import Prelude
import Effect (Effect)
import Effect.Class.Console as Console
import Data.Argonaut.Core as J
import Data.Codec.Argonaut as CA
import Data.Either (Either)
import Data.Codec.Argonaut.Record as CAR
import Data.Argonaut.Parser as JSONParser
import Data.Bifunctor (lmap)
import App.PermissionLevel as PermissionLevel
type Permission = { permission :: PermissionLevel.PermissionLevel }
codecPermission :: CA.JsonCodec Permission
codecPermission = CA.object "Permission" (CAR.record { permission: PermissionLevel.codec })
encode :: Permission -> String
encode = J.stringify <<< CA.encode codecPermission
decode :: String -> Either String Permission
decode = parseDecodeJSON codecPermission
parseDecodeJSON :: forall a. CA.JsonCodec a -> String -> Either String a
parseDecodeJSON codec str = do
json <- JSONParser.jsonParser str
lmap CA.printJsonDecodeError (CA.decode codec json)
main :: Effect Unit
main = do
Console.log ("Hello this is the main")
let origin = { permission: PermissionLevel.Read }
Console.log ("origin: " <> encode origin)