Validation: first draft. WIP. Cannot build atm.
This commit is contained in:
parent
bf0db1417d
commit
db6987b3a8
@ -30,6 +30,7 @@
|
||||
, "transformers"
|
||||
, "tuples"
|
||||
, "uint"
|
||||
, "validation"
|
||||
, "web-encoding"
|
||||
, "web-events"
|
||||
, "web-socket"
|
||||
|
112
src/App/Validation.purs
Normal file
112
src/App/Validation.purs
Normal file
@ -0,0 +1,112 @@
|
||||
module App.Validation where
|
||||
|
||||
import Data.Tuple (Tuple(..))
|
||||
import App.ResourceRecord (ResourceRecord)
|
||||
|
||||
data Attribute
|
||||
= Name
|
||||
| TTL
|
||||
| RRType
|
||||
| Id
|
||||
| Name
|
||||
| Target
|
||||
| Priority
|
||||
| Protocol
|
||||
| Weight
|
||||
| Port
|
||||
| NotAnAttribute
|
||||
|
||||
type Errors = Array (Tuple Attribute String)
|
||||
|
||||
validateA :: forall l. SimpleRR (|l) -> V Errors ResourceRecord
|
||||
validateA _ = invalid [Tuple NotAnAttribute "validation not implemented"]
|
||||
validateAAAA :: forall l. SimpleRR (|l) -> V Errors ResourceRecord
|
||||
validateAAAA _ = invalid [Tuple NotAnAttribute "validation not implemented"]
|
||||
validateTXT :: forall l. SimpleRR (|l) -> V Errors ResourceRecord
|
||||
validateTXT _ = invalid [Tuple NotAnAttribute "validation not implemented"]
|
||||
validateMX :: forall l. MXRR (|l) -> V Errors ResourceRecord
|
||||
validateMX _ = invalid [Tuple NotAnAttribute "validation not implemented"]
|
||||
validateSRV :: forall l. SRVRR (|l) -> V Errors ResourceRecord
|
||||
validateSRV _ = invalid [Tuple NotAnAttribute "validation not implemented"]
|
||||
|
||||
validateSRR :: forall l. SimpleRR (|l) -> V Errors ResourceRecord
|
||||
validateSRR form = case form.rrtype of
|
||||
"A" -> validateA form
|
||||
"AAAA" -> validateAAAA form
|
||||
"TXT" -> validateTXT form
|
||||
"CNAME" -> validateCNAME form
|
||||
"NS" -> validateNS form
|
||||
_ -> invalid [Tuple NotAnAttribute $ "invalid type: " <> form.rrtype]
|
||||
|
||||
validateMXRR :: forall l. MXRR (|l) -> V Errors ResourceRecord
|
||||
validateMXRR form = case form.rrtype of
|
||||
"MX" -> validateMX form
|
||||
_ -> invalid [Tuple NotAnAttribute $ "invalid type (expected: MX): " <> form.rrtype]
|
||||
|
||||
validateSRVRR :: forall l. SRVRR (|l) -> V Errors ResourceRecord
|
||||
validateSRVRR form = case form.rrtype of
|
||||
"SRV" -> validateSRV form
|
||||
_ -> invalid [Tuple NotAnAttribute $ "invalid type (expected: SRV): " <> form.rrtype]
|
||||
|
||||
fromLocalSimpleRRRepresentationToResourceRecord :: forall l. SimpleRR (|l) -> ResourceRecord
|
||||
fromLocalSimpleRRRepresentationToResourceRecord form
|
||||
= { rrtype: form.rrtype
|
||||
, rrid: form.rrid
|
||||
, name: form.name
|
||||
, ttl: fromMaybe 3600 $ fromString form.ttl
|
||||
, target: form.target
|
||||
, readonly: form.readonly
|
||||
, priority: Nothing
|
||||
, port: Nothing
|
||||
, protocol: Nothing
|
||||
, weight: Nothing
|
||||
, mname: Nothing
|
||||
, rname: Nothing
|
||||
, serial: Nothing
|
||||
, refresh: Nothing
|
||||
, retry: Nothing
|
||||
, expire: Nothing
|
||||
, minttl: Nothing
|
||||
}
|
||||
|
||||
fromLocalMXRRRepresentationToResourceRecord :: forall l. MXRR (|l) -> ResourceRecord
|
||||
fromLocalMXRRRepresentationToResourceRecord form
|
||||
= { rrtype: form.rrtype
|
||||
, rrid: form.rrid
|
||||
, name: form.name
|
||||
, ttl: fromMaybe 3600 $ fromString form.ttl
|
||||
, target: form.target
|
||||
, readonly: form.readonly
|
||||
, priority: Just $ fromMaybe 10 $ fromString form.priority
|
||||
, port: Nothing
|
||||
, protocol: Nothing
|
||||
, weight: Nothing
|
||||
, mname: Nothing
|
||||
, rname: Nothing
|
||||
, serial: Nothing
|
||||
, refresh: Nothing
|
||||
, retry: Nothing
|
||||
, expire: Nothing
|
||||
, minttl: Nothing
|
||||
}
|
||||
|
||||
fromLocalSRVRRepresentationToResourceRecord :: forall l. SRVRR (|l) -> ResourceRecord
|
||||
fromLocalSRVRRepresentationToResourceRecord form
|
||||
= { rrtype: form.rrtype
|
||||
, rrid: form.rrid
|
||||
, name: form.name
|
||||
, ttl: fromMaybe 3600 $ fromString form.ttl
|
||||
, target: form.target
|
||||
, readonly: form.readonly
|
||||
, priority: Just $ fromMaybe 10 $ fromString form.priority
|
||||
, port: Just $ fromMaybe 10 $ fromString form.port
|
||||
, protocol: Just form.protocol
|
||||
, weight: Just $ fromMaybe 10 $ fromString form.weight
|
||||
, mname: Nothing
|
||||
, rname: Nothing
|
||||
, serial: Nothing
|
||||
, refresh: Nothing
|
||||
, retry: Nothing
|
||||
, expire: Nothing
|
||||
, minttl: Nothing
|
||||
}
|
@ -922,69 +922,6 @@ fromResourceRecordToLocalRepresentationSOARR new_rr = do
|
||||
, minttl: show minttl -- :: RR (Maybe Int) Local (String)
|
||||
}
|
||||
|
||||
fromLocalSimpleRRRepresentationToResourceRecord :: forall l. SimpleRR (|l) -> ResourceRecord
|
||||
fromLocalSimpleRRRepresentationToResourceRecord form
|
||||
= { rrtype: form.rrtype
|
||||
, rrid: form.rrid
|
||||
, name: form.name
|
||||
, ttl: fromMaybe 3600 $ fromString form.ttl
|
||||
, target: form.target
|
||||
, readonly: form.readonly
|
||||
, priority: Nothing
|
||||
, port: Nothing
|
||||
, protocol: Nothing
|
||||
, weight: Nothing
|
||||
, mname: Nothing
|
||||
, rname: Nothing
|
||||
, serial: Nothing
|
||||
, refresh: Nothing
|
||||
, retry: Nothing
|
||||
, expire: Nothing
|
||||
, minttl: Nothing
|
||||
}
|
||||
|
||||
fromLocalMXRRRepresentationToResourceRecord :: forall l. MXRR (|l) -> ResourceRecord
|
||||
fromLocalMXRRRepresentationToResourceRecord form
|
||||
= { rrtype: form.rrtype
|
||||
, rrid: form.rrid
|
||||
, name: form.name
|
||||
, ttl: fromMaybe 3600 $ fromString form.ttl
|
||||
, target: form.target
|
||||
, readonly: form.readonly
|
||||
, priority: Just $ fromMaybe 10 $ fromString form.priority
|
||||
, port: Nothing
|
||||
, protocol: Nothing
|
||||
, weight: Nothing
|
||||
, mname: Nothing
|
||||
, rname: Nothing
|
||||
, serial: Nothing
|
||||
, refresh: Nothing
|
||||
, retry: Nothing
|
||||
, expire: Nothing
|
||||
, minttl: Nothing
|
||||
}
|
||||
|
||||
fromLocalSRVRRepresentationToResourceRecord :: forall l. SRVRR (|l) -> ResourceRecord
|
||||
fromLocalSRVRRepresentationToResourceRecord form
|
||||
= { rrtype: form.rrtype
|
||||
, rrid: form.rrid
|
||||
, name: form.name
|
||||
, ttl: fromMaybe 3600 $ fromString form.ttl
|
||||
, target: form.target
|
||||
, readonly: form.readonly
|
||||
, priority: Just $ fromMaybe 10 $ fromString form.priority
|
||||
, port: Just $ fromMaybe 10 $ fromString form.port
|
||||
, protocol: Just form.protocol
|
||||
, weight: Just $ fromMaybe 10 $ fromString form.weight
|
||||
, mname: Nothing
|
||||
, rname: Nothing
|
||||
, serial: Nothing
|
||||
, refresh: Nothing
|
||||
, retry: Nothing
|
||||
, expire: Nothing
|
||||
, minttl: Nothing
|
||||
}
|
||||
|
||||
first :: forall a. (a -> Boolean) -> Array a -> Maybe a
|
||||
first condition = A.head <<< (A.filter condition)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user