@@ -70,7 +70,10 @@ class Migratable (revisions :: [(Revision, Schema)]) where
7070 -> J.Value
7171 -> ParseResult (JsonRepr (Snd (Head revisions)))
7272
73−instance {-# OVERLAPPING #-} (TopLevel (Snd rev), SingI (Snd rev)) => Migratable '[rev] where
73+instance
74+ {-# OVERLAPPING #-}
75+ ( TopLevel (Snd rev), SingI (Snd rev) )
76+ => Migratable '[rev] where
7477 mparse _ = parseAndValidateJson
7578
7679instance {-# OVERLAPPABLE #-}
@@ -79,41 +82,16 @@ instance {-# OVERLAPPABLE #-}
7982 , SingI (Snd (Head revisions)))
8083 => Migratable revisions where
8184 mparse s v = case parseEither parseJSON v of
82− Left _ -> migrate <$> mparse (sTail s) v
85+ Left _ ->
86+ migrate <$> (mparse (sTail s) v :: ParseResult (JsonRepr (Snd (Head (Tail revisions)))))
8387 Right x -> Valid x
84−-- type family Migratable (revisions :: [(Revision, Schema)]) = (cs :: Constraint) where
85−-- Migratable '[rev] = (TopLevel (Snd rev), SingI (Snd rev))
86−-- Migratable revisions =
87−-- ( Migratable (Tail revisions)
88−-- , MigrateSchema (Snd (Head (Tail revisions))) (Snd (Head revisions))
89−-- , SingI (Snd (Head revisions)))
90−
91−-- mparseBySing
92−-- :: Sing schema
93−-- -> J.Value
94−-- -> ParseResult (JsonRepr (Snd (Head revisions)))
95−-- mparseBySing s v = undefined
96−
97−-- mparse
98−-- :: Migratable revisions
99−-- => Sing revisions
100−-- -> J.Value
101−-- -> ParseResult (JsonRepr (Snd (Head revisions)))
102−-- mparse s v =
103−-- let
104−-- st = sTail s
105−-- sth = sSnd $ sHead st
106−-- SCons x SNil -> parseAndValidateJson v
107−-- SCons sch _ -> case parseEither parseJSON v of
108−-- Left _ -> migrate <$> mparse (sTail s) v
109−-- Right x -> Valid x
11088
11189parseAndValidateVersionedJson
112− :: forall proxy v. (SingI (AllVersions v), Migratable (AllVersions v))
90+ :: forall proxy v. (SingI (Reverse (AllVersions v)), Migratable (Reverse (AllVersions v)))
11391 => proxy v
11492 -> J.Value
115− -> ParseResult (JsonRepr (Snd (Head (AllVersions v))))
116−parseAndValidateVersionedJson _ v = mparse (sing :: Sing (AllVersions v)) v
93+ -> ParseResult (JsonRepr (Snd (Head (Reverse (AllVersions v)))))
94+parseAndValidateVersionedJson _ v = mparse (sing :: Sing (Reverse (AllVersions v))) v
11795
11896decodeAndValidateJson
11997 :: forall schema
@@ -125,10 +103,10 @@ decodeAndValidateJson bs = case decode bs of
125103 Just x -> parseAndValidateJson x
126104
127105decodeAndValidateVersionedJson
128− :: (Migratable (AllVersions versioned), SingI (AllVersions versioned))
106+ :: (Migratable (Reverse (AllVersions versioned)), SingI (Reverse (AllVersions versioned)))
129107 => proxy versioned
130108 -> BL.ByteString
131− -> ParseResult (JsonRepr (Snd (Head (AllVersions versioned))))
109+ -> ParseResult (JsonRepr (Snd (Head (Reverse (AllVersions versioned)))))
132110decodeAndValidateVersionedJson vp bs = case decode bs of
133111 Nothing -> DecodingError "malformed json"
134112 Just x -> parseAndValidateVersionedJson vp x