1{-# OPTIONS -fprint-explicit-kinds #-}
2{-# LANGUAGE AllowAmbiguousTypes #-}
5 ( module Data.Schematic.Schema
6 , module Data.Schematic.Lens
7 , module Data.Schematic.Migration
8 , module Data.Schematic.Utils
9 , decodeAndValidateJson
10 , parseAndValidateJson
11 , parseAndValidateJsonBy
12 , parseAndValidateVersionedJson
13 , parseAndValidateTopVersionJson
14 , decodeAndValidateVersionedJson
15 , parseAndValidateWithMList
16 , decodeAndValidateVersionedWithMList
24import Control.Monad.Validation
26import Data.Aeson.Types as J
27import Data.ByteString.Lazy as BL
28import Data.Functor.Identity
29import Data.Schematic.Lens
30import Data.Schematic.Migration
31import Data.Schematic.Schema
32import Data.Schematic.Utils
33import Data.Schematic.Validation
34import Data.Singletons.Prelude
40 . (J.FromJSON (JsonRepr schema), TopLevel schema, SingI schema)
42 -> ParseResult (JsonRepr schema)
43parseAndValidateJson v =
44 case parseEither parseJSON v of
45 Left s -> DecodingError $ T.pack s
48 validate = validateJsonRepr (sing :: Sing schema) [] jsonRepr
49 res = runIdentity . runValidationTEither $ validate
51 Left em -> ValidationError em
52 Right () -> Valid jsonRepr
55 :: (J.FromJSON (JsonRepr schema), TopLevel schema, SingI schema)
58 -> ParseResult (JsonRepr schema)
59parseAndValidateJsonBy _ = parseAndValidateJson
61parseAndValidateTopVersionJson
62 :: forall proxy (v :: Versioned)
63 . (SingI (TopVersion (AllVersions v)))
66 -> ParseResult (JsonRepr (TopVersion (AllVersions v)))
67parseAndValidateTopVersionJson _ v =
68 case parseEither parseJSON v of
69 Left s -> DecodingError $ T.pack s
73 validateJsonRepr (sing :: Sing (TopVersion (AllVersions v))) [] jsonRepr
74 res = runIdentity . runValidationTEither $ validate
76 Left em -> ValidationError em
77 Right () -> Valid jsonRepr
79class Migratable (revisions :: [(Revision, Schema)]) where
83 -> ParseResult (JsonRepr (Snd (Head revisions)))
87 ( TopLevel (Snd rev), SingI (Snd rev) )
88 => Migratable '[rev] where
89 mparse _ = parseAndValidateJson
91instance {-# OVERLAPPABLE #-}
92 ( Migratable (Tail revisions)
93 , MigrateSchema (Snd (Head (Tail revisions))) (Snd (Head revisions))
94 , SingI (Snd (Head revisions)))
95 => Migratable revisions where
96 mparse s v = case parseEither parseJSON v of
98 migrate <$> (mparse (sTail s) v :: ParseResult (JsonRepr (Snd (Head (Tail revisions)))))
101parseAndValidateVersionedJson
102 :: forall proxy v. (SingI (AllVersions v), Migratable (AllVersions v))
105 -> ParseResult (JsonRepr (Snd (Head (AllVersions v))))
106parseAndValidateVersionedJson _ v = mparse (sing :: Sing (AllVersions v)) v
108parseAndValidateWithMList
111 -> ParseResult (JsonRepr (Head revisions))
112parseAndValidateWithMList MNil v = parseAndValidateJson v
113parseAndValidateWithMList ((:&&) p f tl) v = case parseAndValidateJsonBy p v of
115 DecodingError _ -> f <$> parseAndValidateWithMList tl v
116 ValidationError _ -> f <$> parseAndValidateWithMList tl v
120 . (J.FromJSON (JsonRepr schema), TopLevel schema, SingI schema)
122 -> ParseResult (JsonRepr schema)
123decodeAndValidateJson bs = case decode bs of
124 Nothing -> DecodingError "malformed json"
125 Just x -> parseAndValidateJson x
127decodeAndValidateVersionedJson
128 :: (Migratable (AllVersions versioned), SingI (AllVersions versioned))
131 -> ParseResult (JsonRepr (Snd (Head (AllVersions versioned))))
132decodeAndValidateVersionedJson vp bs = case decode bs of
133 Nothing -> DecodingError "malformed json"
134 Just x -> parseAndValidateVersionedJson vp x
136type family MapSnd (l :: [(a,k)]) = (r :: [k]) where
138 MapSnd ( '(a, b) ': tl) = b ': MapSnd tl
140decodeAndValidateVersionedWithMList
142 -> MList (MapSnd (AllVersions versioned))
144 -> ParseResult (JsonRepr (Head (MapSnd (AllVersions versioned))))
145decodeAndValidateVersionedWithMList _ mlist bs = case decode bs of
146 Nothing -> DecodingError "malformed json"
147 Just x -> parseAndValidateWithMList mlist x
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list