@@ -7,9 +7,12 @@ module Data.Schematic
7 , module Data.Schematic.Utils
7 , module Data.Schematic.Utils
8 , decodeAndValidateJson
8 , decodeAndValidateJson
9 , parseAndValidateJson
9 , parseAndValidateJson
10+ , parseAndValidateJsonBy
10 , parseAndValidateVersionedJson
11 , parseAndValidateVersionedJson
11 , parseAndValidateTopVersionJson
12 , parseAndValidateTopVersionJson
12 , decodeAndValidateVersionedJson
13 , decodeAndValidateVersionedJson
14+ , parseAndValidateWithMList
15+ , decodeAndValidateVersionedWithMList
14 , isDecodingError
17 , isDecodingError
15 , isValidationError
18 , isValidationError
@@ -46,6 +49,13 @@ parseAndValidateJson v =
46 Left em -> ValidationError em
49 Left em -> ValidationError em
47 Right () -> Valid jsonRepr
50 Right () -> Valid jsonRepr
52+parseAndValidateJsonBy
53+ :: (J.FromJSON (JsonRepr schema), TopLevel schema, SingI schema)
56+ -> ParseResult (JsonRepr schema)
57+parseAndValidateJsonBy _ = parseAndValidateJson
49parseAndValidateTopVersionJson
59parseAndValidateTopVersionJson
50 :: forall proxy (v :: Versioned)
60 :: forall proxy (v :: Versioned)
51 . (SingI (TopVersion (AllVersions v)))
61 . (SingI (TopVersion (AllVersions v)))
@@ -93,6 +103,16 @@ parseAndValidateVersionedJson
93 -> ParseResult (JsonRepr (Snd (Head (AllVersions v))))
103 -> ParseResult (JsonRepr (Snd (Head (AllVersions v))))
94parseAndValidateVersionedJson _ v = mparse (sing :: Sing (AllVersions v)) v
104parseAndValidateVersionedJson _ v = mparse (sing :: Sing (AllVersions v)) v
106+parseAndValidateWithMList
109+ -> ParseResult (JsonRepr (Head revisions))
110+parseAndValidateWithMList MNil v = parseAndValidateJson v
111+parseAndValidateWithMList ((:&&) p f tl) v = case parseAndValidateJsonBy p v of
113+ DecodingError _ -> f <$> parseAndValidateWithMList tl v
114+ ValidationError _ -> f <$> parseAndValidateWithMList tl v
96decodeAndValidateJson
116decodeAndValidateJson
97 :: forall schema
117 :: forall schema
98 . (J.FromJSON (JsonRepr schema), TopLevel schema, SingI schema)
118 . (J.FromJSON (JsonRepr schema), TopLevel schema, SingI schema)
@@ -110,3 +130,16 @@ decodeAndValidateVersionedJson
110decodeAndValidateVersionedJson vp bs = case decode bs of
130decodeAndValidateVersionedJson vp bs = case decode bs of
111 Nothing -> DecodingError "malformed json"
131 Nothing -> DecodingError "malformed json"
112 Just x -> parseAndValidateVersionedJson vp x
132 Just x -> parseAndValidateVersionedJson vp x
134+type family MapSnd (l :: [(a,k)]) = (r :: [k]) where
136+ MapSnd ( '(a, b) ': tl) = b ': MapSnd tl
138+decodeAndValidateVersionedWithMList
140+ -> MList (MapSnd (AllVersions versioned))
142+ -> ParseResult (JsonRepr (Head (MapSnd (AllVersions versioned))))
143+decodeAndValidateVersionedWithMList _ mlist bs = case decode bs of
144+ Nothing -> DecodingError "malformed json"
145+ Just x -> parseAndValidateWithMList mlist x