2023-05-27 17:04:23 +02:00
|
|
|
-- | 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
|
2023-05-31 00:22:38 +02:00
|
|
|
import Data.Either (Either)
|
2023-05-27 17:04:23 +02:00
|
|
|
import Data.Codec.Argonaut.Record as CAR
|
|
|
|
import Data.Argonaut.Parser as JSONParser
|
|
|
|
import Data.Bifunctor (lmap)
|
|
|
|
|
|
|
|
import App.PermissionLevel as PermissionLevel
|
|
|
|
|
2023-05-31 00:22:38 +02:00
|
|
|
type Permission = { permission :: PermissionLevel.PermissionLevel }
|
2023-05-27 17:04:23 +02:00
|
|
|
|
2023-05-31 00:22:38 +02:00
|
|
|
codecPermission :: CA.JsonCodec Permission
|
|
|
|
codecPermission = CA.object "Permission" (CAR.record { permission: PermissionLevel.codec })
|
2023-05-27 17:04:23 +02:00
|
|
|
|
2023-05-31 00:22:38 +02:00
|
|
|
encode :: Permission -> String
|
|
|
|
encode = J.stringify <<< CA.encode codecPermission
|
|
|
|
|
|
|
|
decode :: String -> Either String Permission
|
|
|
|
decode = parseDecodeJSON codecPermission
|
2023-05-27 17:04:23 +02:00
|
|
|
|
|
|
|
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)
|