From f03909f83db118cdf572a7b9d49014116e54ff20 Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Mon, 10 Jul 2023 03:15:32 +0200 Subject: [PATCH] ResourceRecord type is now implemented to handle incoming messages. --- src/App/ResourceRecord.purs | 59 +++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 9 deletions(-) diff --git a/src/App/ResourceRecord.purs b/src/App/ResourceRecord.purs index d03dd34..8060ea1 100644 --- a/src/App/ResourceRecord.purs +++ b/src/App/ResourceRecord.purs @@ -1,18 +1,59 @@ module App.ResourceRecord where -import Prelude +import Data.Maybe (Maybe) import Data.Codec.Argonaut (JsonCodec) import Data.Codec.Argonaut as CA -import Data.Newtype (class Newtype) -import Data.Profunctor (wrapIso) +import Data.Codec.Argonaut.Record as CAR -newtype ResourceRecord = ResourceRecord String +type ResourceRecord + = { rrid :: Int + , name :: String + , ttl :: Int + , target :: String + , readonly :: Boolean -derive instance newtypeResourceRecord :: Newtype ResourceRecord _ -derive instance eqResourceRecord :: Eq ResourceRecord -derive instance ordResourceRecord :: Ord ResourceRecord + -- MX (and SRV) specific entry. + , priority :: Maybe Int + + -- SRV specific entries. + , port :: Maybe Int + , protocol :: Maybe String + , weight :: Maybe Int + + -- SOA specific entries. + , mname :: Maybe String + , rname :: Maybe String + , serial :: Maybe Int + , refresh :: Maybe Int + , retry :: Maybe Int + , expire :: Maybe Int + , minttl :: Maybe Int + } --- | ResourceRecord.codec can be used to parse and encode email addresses. codec :: JsonCodec ResourceRecord -codec = wrapIso ResourceRecord CA.string +codec = CA.object "ResourceRecord" + (CAR.record + { rrid: CA.int + , name: CA.string + , ttl: CA.int + , target: CA.string + , readonly: CA.boolean + + -- MX (and SRV) specific entry. + , priority: CAR.optional CA.int + + -- SRV specific entries. + , port: CAR.optional CA.int + , protocol: CAR.optional CA.string + , weight: CAR.optional CA.int + + -- SOA specific entries. + , mname: CAR.optional CA.string + , rname: CAR.optional CA.string + , serial: CAR.optional CA.int + , refresh: CAR.optional CA.int + , retry: CAR.optional CA.int + , expire: CAR.optional CA.int + , minttl: CAR.optional CA.int + })