@@ -83,35 +83,30 @@ parseAndValidateTopVersionJson _ v =
84-- [("top version", schemaTopVersion), ("n-1 version", schemaNminusOneVersion), ...]
84-- [("top version", schemaTopVersion), ("n-1 version", schemaNminusOneVersion), ...]
86+-- type family Migratable (rs :: [(Revision, Schema)]) :: Constraint where
87+-- -- constraint duplication
88+-- Migratable ('(r,s) ': '(r', s') ': tl) =
89+-- (SingI s, MigrateSchema s s', TopLevel s, Migratable ('(r',s') ': tl))
90+-- Migratable ('(r,s) ': '[]) = (TopLevel s, SingI s)
91+-- -- Migratable '[] = ('True ~ 'False)
93+class Migratable (revisions :: [(Revision, Schema)]) where
94+ mparse :: Sing revisions -> J.Value -> Either String (JsonRepr (Snd (Head revisions)))
96+instance {-# OVERLAPPING #-} (Migratable (Tail revisions), MigrateSchema (Snd (Head (Tail revisions))) (Snd (Head revisions)), SingI (Snd (Head revisions))) => Migratable revisions where
97+ mparse s v = case parseEither parseJSON v of
98+ Left _ -> migrate <$> mparse (sTail s) v
101+instance {-# OVERLAPPABLE #-} (TopLevel (Snd rev), SingI (Snd rev)) => Migratable '[rev] where
102+ mparse _ = parseEither parseJSON
86parseAndValidateVersionedJson
104parseAndValidateVersionedJson
87− :: forall proxy rav av (v :: Versioned) rs tv
88− . ( SingI (AllVersions v)
89− , Migratable (AllVersions v)
105+ :: forall proxy v. (SingI (AllVersions v), Migratable (AllVersions v))
90− , SingI (TopVersion (AllVersions v))
91− , SingI (AllVersions v))
92 => proxy v
106 => proxy v
93 -> J.Value
107 -> J.Value
94− -> ParseResult (JsonRepr (TopVersion (AllVersions v)))
108+ -> Either String (JsonRepr (Snd (Head (AllVersions v))))
95−parseAndValidateVersionedJson _ v =
109+parseAndValidateVersionedJson s v = mparse (sing :: Sing (AllVersions v)) v
97− rss :: Sing (AllVersions v)
99− stv :: Sing (TopVersion (AllVersions v))
101− in parseAndValidateVersionedJsonByVersions stv rss v
103−parseAndValidateVersionedJsonByVersions
104− :: forall (rs :: [(Revision, Schema)]) tv proxy
106− => proxy (tv :: Schema)
109− -> ParseResult (JsonRepr tv)
110−parseAndValidateVersionedJsonByVersions stv srs value = case srs of
111− SNil -> DecodingError "blabla"
112− SCons (STuple2 r s) tl -> case parseAndValidateJsonBySing s value of
113− Valid a -> Valid $ migrate a
114− _ -> DecodingError "dummy plug"
116decodeAndValidateJson
111decodeAndValidateJson
117 :: forall schema
112 :: forall schema