{-# language DataKinds #-}
{-# language DefaultSignatures #-}
{-# language FlexibleContexts #-}
{-# language FlexibleInstances #-}
{-# language FunctionalDependencies #-}
{-# language GADTs #-}
{-# language PolyKinds #-}
{-# language QuantifiedConstraints #-}
{-# language RankNTypes #-}
{-# language ScopedTypeVariables #-}
{-# language TypeApplications #-}
{-# language TypeFamilies #-}
{-# language TypeOperators #-}
{-# language UndecidableInstances #-}
module Mu.Schema.Class (
WithSchema(..), unWithSchema
, FromSchema(..), fromSchema'
, ToSchema(..), toSchema'
, CustomFieldMapping(..)
, Mapping(..), Mappings, MappingRight, MappingLeft
, Underlying(..), UnderlyingConversion(..)
, GToSchemaRecord(..)
) where
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as BL
import Data.Kind
import Data.Map as M
import Data.Maybe (fromJust)
import Data.SOP
import qualified Data.Text as T
import qualified Data.UUID as U
import GHC.Generics
import GHC.TypeLits
import Mu.Schema.Definition
import Mu.Schema.Interpretation
newtype WithSchema (sch :: Schema tn fn) (sty :: tn) a where
WithSchema :: forall tn fn (sch :: Schema tn fn) (sty :: tn) a.
a -> WithSchema sch sty a
unWithSchema :: forall tn fn (sch :: Schema tn fn) (sty :: tn) a.
WithSchema sch sty a -> a
unWithSchema (WithSchema x) = x
class ToSchema (sch :: Schema typeName fieldName) (sty :: typeName) (t :: Type)
| sch t -> sty where
toSchema :: t -> Term sch (sch :/: sty)
default
toSchema :: (Generic t, GToSchemaTypeDef sch '[] (sch :/: sty) (Rep t))
=> t -> Term sch (sch :/: sty)
toSchema x = toSchemaTypeDef (Proxy @'[]) (from x)
class FromSchema (sch :: Schema typeName fieldName) (sty :: typeName) (t :: Type)
| sch t -> sty where
fromSchema :: Term sch (sch :/: sty) -> t
default
fromSchema :: (Generic t, GFromSchemaTypeDef sch '[] (sch :/: sty) (Rep t) )
=> Term sch (sch :/: sty) -> t
fromSchema x = to (fromSchemaTypeDef (Proxy @'[]) x)
instance (sch :/: sty ~ 'DRecord sty fields)
=> ToSchema sch sty (Term sch ('DRecord sty fields)) where
toSchema = id
instance (sch :/: sty ~ 'DEnum sty choices)
=> ToSchema sch sty (Term sch ('DEnum sty choices)) where
toSchema = id
instance (sch :/: sty ~ 'DRecord sty fields)
=> FromSchema sch sty (Term sch ('DRecord sty fields)) where
fromSchema = id
instance (sch :/: sty ~ 'DEnum sty choices)
=> FromSchema sch sty (Term sch ('DEnum sty choices)) where
fromSchema = id
toSchema' :: forall fn tn (sch :: Schema tn fn) t sty.
ToSchema sch sty t => t -> Term sch (sch :/: sty)
toSchema' = toSchema
fromSchema' :: forall fn tn (sch :: Schema tn fn) t sty.
FromSchema sch sty t => Term sch (sch :/: sty) -> t
fromSchema' = fromSchema
newtype CustomFieldMapping (sty :: typeName) (fmap :: [Mapping Symbol fieldName]) a
= CustomFieldMapping a
instance (Generic t, GToSchemaTypeDef sch fmap (sch :/: sty) (Rep t))
=> ToSchema sch sty (CustomFieldMapping sty fmap t) where
toSchema (CustomFieldMapping x) = toSchemaTypeDef (Proxy @fmap) (from x)
instance (Generic t, GFromSchemaTypeDef sch fmap (sch :/: sty) (Rep t))
=> FromSchema sch sty (CustomFieldMapping sty fmap t) where
fromSchema x = CustomFieldMapping $ to (fromSchemaTypeDef (Proxy @fmap) x)
newtype Underlying basic logical
= Underlying { unUnderlying :: logical }
deriving (Show, Eq)
class UnderlyingConversion basic logical where
toUnderlying :: logical -> basic
fromUnderlying :: basic -> logical
instance UnderlyingConversion String U.UUID where
toUnderlying = U.toString
fromUnderlying = fromJust . U.fromString
instance UnderlyingConversion T.Text U.UUID where
toUnderlying = U.toText
fromUnderlying = fromJust . U.fromText
instance UnderlyingConversion BL.ByteString U.UUID where
toUnderlying = U.toByteString
fromUnderlying = fromJust . U.fromByteString
instance UnderlyingConversion BS.ByteString U.UUID where
toUnderlying = BL.toStrict . U.toByteString
fromUnderlying = fromJust . U.fromByteString . BL.fromStrict
data Where = Here | HereLeft | HereRight | HereRightThenLeft | HereTwoRights | There Where
type family Find (xs :: [k]) (x :: k) :: Where where
Find '[] y = TypeError ('Text "Could not find " ':<>: 'ShowType y)
Find (y ': xs) y = 'Here
Find (x ': xs) y = 'There (Find xs y)
type family FindCon (xs :: * -> *) (x :: Symbol) :: Where where
FindCon (C1 ('MetaCons x p s) f) x = 'Here
FindCon (C1 ('MetaCons x p s) f :+: rest) x = 'Here
FindCon (other :+: rest) x = 'There (FindCon rest x)
FindCon nothing x = TypeError ('Text "Could not find constructor " ':<>: 'ShowType x)
type family FindSel (xs :: * -> *) (x :: Symbol) :: Where where
FindSel (S1 ('MetaSel ('Just x) u ss ds) f) x = 'Here
FindSel (S1 ('MetaSel ('Just x) u ss ds) f :*: rest) x = 'Here
FindSel ((S1 ('MetaSel ('Just x) u ss ds) f :*: other) :*: rest) x = 'HereLeft
FindSel ((other :*: S1 ('MetaSel ('Just x) u ss ds) f) :*: rest) x = 'HereRight
FindSel ((other1 :*: (S1 ('MetaSel ('Just x) u ss ds) f :*: other2)) :*: rest) x = 'HereRightThenLeft
FindSel ((other1 :*: (other2 :*: S1 ('MetaSel ('Just x) u ss ds) f)) :*: rest) x = 'HereTwoRights
FindSel (other :*: rest) x = 'There (FindSel rest x)
FindSel nothing x = TypeError ('Text "Could not find selector " ':<>: 'ShowType x)
type family FindEnumChoice (xs :: [ChoiceDef fs]) (x :: fs) :: Where where
FindEnumChoice '[] x = TypeError ('Text "Could not find enum choice " ':<>: 'ShowType x)
FindEnumChoice ('ChoiceDef name ': xs) name = 'Here
FindEnumChoice (other ': xs) name = 'There (FindEnumChoice xs name)
type family FindField (xs :: [FieldDef ts fs]) (x :: fs) :: Where where
FindField '[] x = TypeError ('Text "Could not find field " ':<>: 'ShowType x)
FindField ('FieldDef name t ': xs) name = 'Here
FindField (other ': xs) name = 'There (FindField xs name)
class GToSchemaTypeDef
(sch :: Schema ts fs) (fmap :: Mappings Symbol fs)
(t :: TypeDef ts fs) (f :: * -> *) where
toSchemaTypeDef :: Proxy fmap -> f a -> Term sch t
class GFromSchemaTypeDef
(sch :: Schema ts fs) (fmap :: Mappings Symbol fs)
(t :: TypeDef ts fs) (f :: * -> *) where
fromSchemaTypeDef :: Proxy fmap -> Term sch t -> f a
instance GToSchemaFieldTypeWrap sch t f
=> GToSchemaTypeDef sch fmap ('DSimple t) f where
toSchemaTypeDef _ x = TSimple (toSchemaFieldTypeW x)
instance GFromSchemaFieldTypeWrap sch t f
=> GFromSchemaTypeDef sch fmap ('DSimple t) f where
fromSchemaTypeDef _ (TSimple x) = fromSchemaFieldTypeW x
class GToSchemaFieldTypeWrap
(sch :: Schema ts fs) (t :: FieldType ts) (f :: * -> *) where
toSchemaFieldTypeW :: f a -> FieldValue sch t
class GFromSchemaFieldTypeWrap
(sch :: Schema ts fs) (t :: FieldType ts) (f :: * -> *) where
fromSchemaFieldTypeW :: FieldValue sch t -> f a
instance GToSchemaFieldType sch t f
=> GToSchemaFieldTypeWrap sch t (K1 i f) where
toSchemaFieldTypeW (K1 x) = toSchemaFieldType x
instance GFromSchemaFieldType sch t f
=> GFromSchemaFieldTypeWrap sch t (K1 i f) where
fromSchemaFieldTypeW x = K1 (fromSchemaFieldType x)
instance GToSchemaFieldTypeWrap sch t f
=> GToSchemaFieldTypeWrap sch t (M1 s m f) where
toSchemaFieldTypeW (M1 x) = toSchemaFieldTypeW x
instance GFromSchemaFieldTypeWrap sch t f
=> GFromSchemaFieldTypeWrap sch t (M1 s m f) where
fromSchemaFieldTypeW x = M1 (fromSchemaFieldTypeW x)
class GToSchemaFieldType
(sch :: Schema ts fs) (t :: FieldType ts) (f :: *) where
toSchemaFieldType :: f -> FieldValue sch t
class GFromSchemaFieldType
(sch :: Schema ts fs) (t :: FieldType ts) (f :: *) where
fromSchemaFieldType :: FieldValue sch t -> f
class GToSchemaFieldTypeUnion
(sch :: Schema ts fs) (t :: [FieldType ts]) (f :: * -> *) where
toSchemaFieldTypeUnion :: f a -> NS (FieldValue sch) t
class GFromSchemaFieldTypeUnion
(sch :: Schema ts fs) (t :: [FieldType ts]) (f :: * -> *) where
fromSchemaFieldTypeUnion :: NS (FieldValue sch) t -> f a
instance GToSchemaFieldType sch 'TNull () where
toSchemaFieldType _ = FNull
instance GFromSchemaFieldType sch 'TNull () where
fromSchemaFieldType _ = ()
instance (UnderlyingConversion t l)
=> GToSchemaFieldType sch ('TPrimitive t) (Underlying t l) where
toSchemaFieldType = FPrimitive . toUnderlying . unUnderlying
instance (UnderlyingConversion t l)
=> GFromSchemaFieldType sch ('TPrimitive t) (Underlying t l) where
fromSchemaFieldType (FPrimitive x) = Underlying (fromUnderlying x)
instance GToSchemaFieldType sch ('TPrimitive t) t where
toSchemaFieldType = FPrimitive
instance GFromSchemaFieldType sch ('TPrimitive t) t where
fromSchemaFieldType (FPrimitive x) = x
instance ToSchema sch t v
=> GToSchemaFieldType sch ('TSchematic t) v where
toSchemaFieldType x = FSchematic $ toSchema x
instance FromSchema sch t v
=> GFromSchemaFieldType sch ('TSchematic t) v where
fromSchemaFieldType (FSchematic x) = fromSchema x
instance GToSchemaFieldType sch t v
=> GToSchemaFieldType sch ('TOption t) (Maybe v) where
toSchemaFieldType x = FOption (toSchemaFieldType <$> x)
instance GFromSchemaFieldType sch t v
=> GFromSchemaFieldType sch ('TOption t) (Maybe v) where
fromSchemaFieldType (FOption x) = fromSchemaFieldType <$> x
instance GToSchemaFieldType sch t v
=> GToSchemaFieldType sch ('TList t) [v] where
toSchemaFieldType x = FList (toSchemaFieldType <$> x)
instance GFromSchemaFieldType sch t v
=> GFromSchemaFieldType sch ('TList t) [v] where
fromSchemaFieldType (FList x) = fromSchemaFieldType <$> x
instance (GToSchemaFieldType sch sk hk, GToSchemaFieldType sch sv hv,
Ord (FieldValue sch sk))
=> GToSchemaFieldType sch ('TMap sk sv) (M.Map hk hv) where
toSchemaFieldType x = FMap (M.mapKeys toSchemaFieldType (M.map toSchemaFieldType x))
instance (GFromSchemaFieldType sch sk hk, GFromSchemaFieldType sch sv hv, Ord hk)
=> GFromSchemaFieldType sch ('TMap sk sv) (M.Map hk hv) where
fromSchemaFieldType (FMap x) = M.mapKeys fromSchemaFieldType (M.map fromSchemaFieldType x)
instance {-# OVERLAPS #-}
AllZip (GToSchemaFieldType sch) ts vs
=> GToSchemaFieldType sch ('TUnion ts) (NS I vs) where
toSchemaFieldType t = FUnion (go t)
where go :: AllZip (GToSchemaFieldType sch) tss vss
=> NS I vss -> NS (FieldValue sch) tss
go (Z (I x)) = Z (toSchemaFieldType x)
go (S n) = S (go n)
instance {-# OVERLAPS #-}
AllZip (GFromSchemaFieldType sch) ts vs
=> GFromSchemaFieldType sch ('TUnion ts) (NS I vs) where
fromSchemaFieldType (FUnion t) = go t
where go :: AllZip (GFromSchemaFieldType sch) tss vss
=> NS (FieldValue sch) tss -> NS I vss
go (Z x) = Z (I (fromSchemaFieldType x))
go (S n) = S (go n)
instance {-# OVERLAPPABLE #-}
(Generic f, GToSchemaFieldTypeUnion sch ts (Rep f))
=> GToSchemaFieldType sch ('TUnion ts) f where
toSchemaFieldType x = FUnion (toSchemaFieldTypeUnion (from x))
instance {-# OVERLAPPABLE #-}
(Generic f, GFromSchemaFieldTypeUnion sch ts (Rep f))
=> GFromSchemaFieldType sch ('TUnion ts) f where
fromSchemaFieldType (FUnion x) = to (fromSchemaFieldTypeUnion x)
instance {-# OVERLAPS #-} GToSchemaFieldTypeUnion sch '[] U1 where
toSchemaFieldTypeUnion U1 = error "this should never happen"
instance {-# OVERLAPS #-} GFromSchemaFieldTypeUnion sch '[] U1 where
fromSchemaFieldTypeUnion _ = U1
instance {-# OVERLAPS #-} GToSchemaFieldTypeUnion sch '[] (M1 i t U1) where
toSchemaFieldTypeUnion (M1 U1) = error "this should never happen"
instance {-# OVERLAPS #-} GFromSchemaFieldTypeUnion sch '[] (M1 i t U1) where
fromSchemaFieldTypeUnion _ = M1 U1
instance {-# OVERLAPPABLE #-}
TypeError ('Text "the type does not match the union")
=> GToSchemaFieldTypeUnion sch '[] f where
toSchemaFieldTypeUnion = error "this should never happen"
instance {-# OVERLAPPABLE #-}
TypeError ('Text "the type does not match the union")
=> GFromSchemaFieldTypeUnion sch '[] f where
fromSchemaFieldTypeUnion = error "this should never happen"
instance (GToSchemaFieldTypeWrap sch t v)
=> GToSchemaFieldTypeUnion sch '[t] v where
toSchemaFieldTypeUnion x = Z (toSchemaFieldTypeW x)
instance (GFromSchemaFieldTypeWrap sch t v)
=> GFromSchemaFieldTypeUnion sch '[t] v where
fromSchemaFieldTypeUnion (Z x) = fromSchemaFieldTypeW x
fromSchemaFieldTypeUnion (S _) = error "this should never happen"
instance {-# OVERLAPS #-} (GToSchemaFieldTypeUnion sch (a ': b ': rest) v)
=> GToSchemaFieldTypeUnion sch (a ': b ': rest) (M1 i t v) where
toSchemaFieldTypeUnion (M1 x) = toSchemaFieldTypeUnion x
instance {-# OVERLAPS #-} (GFromSchemaFieldTypeUnion sch (a ': b ': rest) v)
=> GFromSchemaFieldTypeUnion sch (a ': b ': rest) (M1 i t v) where
fromSchemaFieldTypeUnion x = M1 (fromSchemaFieldTypeUnion x)
instance (GToSchemaFieldTypeWrap sch t v, GToSchemaFieldTypeUnion sch ts vs)
=> GToSchemaFieldTypeUnion sch (t ': ts) (v :+: vs) where
toSchemaFieldTypeUnion (L1 x) = Z (toSchemaFieldTypeW x)
toSchemaFieldTypeUnion (R1 r) = S (toSchemaFieldTypeUnion r)
instance (GFromSchemaFieldTypeWrap sch t v, GFromSchemaFieldTypeUnion sch ts vs)
=> GFromSchemaFieldTypeUnion sch (t ': ts) (v :+: vs) where
fromSchemaFieldTypeUnion (Z x) = L1 (fromSchemaFieldTypeW x)
fromSchemaFieldTypeUnion (S r) = R1 (fromSchemaFieldTypeUnion r)
instance ( GToSchemaFieldTypeWrap sch t1 v1
, GToSchemaFieldTypeWrap sch t2 v2
, GToSchemaFieldTypeUnion sch ts vs )
=> GToSchemaFieldTypeUnion sch (t1 ': t2 ': ts) ((v1 :+: v2) :+: vs) where
toSchemaFieldTypeUnion (L1 (L1 x)) = Z (toSchemaFieldTypeW x)
toSchemaFieldTypeUnion (L1 (R1 x)) = S (Z (toSchemaFieldTypeW x))
toSchemaFieldTypeUnion (R1 r) = S (S (toSchemaFieldTypeUnion r))
instance ( GFromSchemaFieldTypeWrap sch t1 v1
, GFromSchemaFieldTypeWrap sch t2 v2
, GFromSchemaFieldTypeUnion sch ts vs )
=> GFromSchemaFieldTypeUnion sch (t1 ': t2 ': ts) ((v1 :+: v2) :+: vs) where
fromSchemaFieldTypeUnion (Z x) = L1 (L1 (fromSchemaFieldTypeW x))
fromSchemaFieldTypeUnion (S (Z x)) = L1 (R1 (fromSchemaFieldTypeW x))
fromSchemaFieldTypeUnion (S (S r)) = R1 (fromSchemaFieldTypeUnion r)
instance {-# OVERLAPPABLE #-}
(GToSchemaEnumDecompose fmap choices f)
=> GToSchemaTypeDef sch fmap ('DEnum name choices) f where
toSchemaTypeDef p x = TEnum (toSchemaEnumDecomp p x)
instance {-# OVERLAPPABLE #-}
(GFromSchemaEnumDecompose fmap choices f)
=> GFromSchemaTypeDef sch fmap ('DEnum name choices) f where
fromSchemaTypeDef p (TEnum x) = fromSchemaEnumDecomp p x
instance {-# OVERLAPS #-}
GToSchemaTypeDef sch fmap ('DEnum name choices) f
=> GToSchemaTypeDef sch fmap ('DEnum name choices) (D1 meta f) where
toSchemaTypeDef p (M1 x) = toSchemaTypeDef p x
instance {-# OVERLAPS #-}
GFromSchemaTypeDef sch fmap ('DEnum name choices) f
=> GFromSchemaTypeDef sch fmap ('DEnum name choices) (D1 meta f) where
fromSchemaTypeDef p x = M1 (fromSchemaTypeDef p x)
class GToSchemaEnumDecompose (fmap :: Mappings Symbol fs)
(choices :: [ChoiceDef fs]) (f :: * -> *) where
toSchemaEnumDecomp :: Proxy fmap -> f a -> NS Proxy choices
instance (GToSchemaEnumDecompose fmap choices oneway, GToSchemaEnumDecompose fmap choices oranother)
=> GToSchemaEnumDecompose fmap choices (oneway :+: oranother) where
toSchemaEnumDecomp p (L1 x) = toSchemaEnumDecomp p x
toSchemaEnumDecomp p (R1 x) = toSchemaEnumDecomp p x
instance GToSchemaEnumProxy choices (FindEnumChoice choices (MappingRight fmap c))
=> GToSchemaEnumDecompose fmap choices (C1 ('MetaCons c p s) f) where
toSchemaEnumDecomp _ _
= toSchemaEnumProxy (Proxy @choices) (Proxy @(FindEnumChoice choices (MappingRight fmap c)))
class GToSchemaEnumProxy (choices :: [k]) (w :: Where) where
toSchemaEnumProxy :: Proxy choices -> Proxy w -> NS Proxy choices
instance GToSchemaEnumProxy (c ': cs) 'Here where
toSchemaEnumProxy _ _ = Z Proxy
instance forall c cs w. GToSchemaEnumProxy cs w
=> GToSchemaEnumProxy (c ': cs) ('There w) where
toSchemaEnumProxy _ _ = S (toSchemaEnumProxy (Proxy @cs) (Proxy @w))
class GFromSchemaEnumDecompose (fmap :: Mappings Symbol fs) (choices :: [ChoiceDef fs]) (f :: * -> *) where
fromSchemaEnumDecomp :: Proxy fmap -> NS Proxy choices -> f a
instance GFromSchemaEnumDecompose fmap '[] f where
fromSchemaEnumDecomp _ _ = error "This should never happen"
instance (GFromSchemaEnumU1 f (FindCon f (MappingLeft fmap c)), GFromSchemaEnumDecompose fmap cs f)
=> GFromSchemaEnumDecompose fmap ('ChoiceDef c ': cs) f where
fromSchemaEnumDecomp _ (Z _) = fromSchemaEnumU1 (Proxy @f) (Proxy @(FindCon f (MappingLeft fmap c)))
fromSchemaEnumDecomp p (S x) = fromSchemaEnumDecomp p x
class GFromSchemaEnumU1 (f :: * -> *) (w :: Where) where
fromSchemaEnumU1 :: Proxy f -> Proxy w -> f a
instance GFromSchemaEnumU1 (C1 m U1 :+: rest) 'Here where
fromSchemaEnumU1 _ _ = L1 (M1 U1)
instance GFromSchemaEnumU1 (C1 m U1) 'Here where
fromSchemaEnumU1 _ _ = M1 U1
instance forall other rest w. GFromSchemaEnumU1 rest w
=> GFromSchemaEnumU1 (other :+: rest) ('There w) where
fromSchemaEnumU1 _ _ = R1 (fromSchemaEnumU1 (Proxy @rest) (Proxy @w))
instance {-# OVERLAPPABLE #-}
(GToSchemaRecord sch fmap args f)
=> GToSchemaTypeDef sch fmap ('DRecord name args) f where
toSchemaTypeDef p x = TRecord (toSchemaRecord p x)
instance {-# OVERLAPPABLE #-}
(GFromSchemaRecord sch fmap args f)
=> GFromSchemaTypeDef sch fmap ('DRecord name args) f where
fromSchemaTypeDef p (TRecord x) = fromSchemaRecord p x
instance {-# OVERLAPS #-}
GToSchemaTypeDef sch fmap ('DRecord name args) f
=> GToSchemaTypeDef sch fmap ('DRecord name args) (D1 meta f) where
toSchemaTypeDef p (M1 x) = toSchemaTypeDef p x
instance {-# OVERLAPS #-}
GFromSchemaTypeDef sch fmap ('DRecord name args) f
=> GFromSchemaTypeDef sch fmap ('DRecord name args) (D1 meta f) where
fromSchemaTypeDef p x = M1 (fromSchemaTypeDef p x)
instance {-# OVERLAPS #-}
GToSchemaTypeDef sch fmap ('DRecord name args) f
=> GToSchemaTypeDef sch fmap ('DRecord name args) (C1 meta f) where
toSchemaTypeDef p (M1 x) = toSchemaTypeDef p x
instance {-# OVERLAPS #-}
GFromSchemaTypeDef sch fmap ('DRecord name args) f
=> GFromSchemaTypeDef sch fmap ('DRecord name args) (C1 meta f) where
fromSchemaTypeDef p x = M1 (fromSchemaTypeDef p x)
class GToSchemaRecord (sch :: Schema ts fs) (fmap :: Mappings Symbol fs)
(args :: [FieldDef ts fs]) (f :: * -> *) where
toSchemaRecord :: Proxy fmap -> f a -> NP (Field sch) args
instance GToSchemaRecord sch fmap '[] f where
toSchemaRecord _ _ = Nil
instance ( GToSchemaRecord sch fmap cs f
, GToSchemaRecordSearch sch t f (FindSel f (MappingLeft fmap name)) )
=> GToSchemaRecord sch fmap ('FieldDef name t ': cs) f where
toSchemaRecord p x = this :* toSchemaRecord p x
where this = Field (toSchemaRecordSearch (Proxy @(FindSel f (MappingLeft fmap name))) x)
class GToSchemaRecordSearch (sch :: Schema ts fs)
(t :: FieldType ts) (f :: * -> *) (wh :: Where) where
toSchemaRecordSearch :: Proxy wh -> f a -> FieldValue sch t
instance GToSchemaFieldType sch t v
=> GToSchemaRecordSearch sch t (S1 m (K1 i v)) 'Here where
toSchemaRecordSearch _ (M1 (K1 x)) = toSchemaFieldType x
instance GToSchemaFieldType sch t v
=> GToSchemaRecordSearch sch t (S1 m (K1 i v) :*: rest) 'Here where
toSchemaRecordSearch _ (M1 (K1 x) :*: _) = toSchemaFieldType x
instance GToSchemaFieldType sch t v
=> GToSchemaRecordSearch sch t ((S1 m (K1 i v) :*: other) :*: rest) 'HereLeft where
toSchemaRecordSearch _ ((M1 (K1 x) :*: _) :*: _) = toSchemaFieldType x
instance GToSchemaFieldType sch t v
=> GToSchemaRecordSearch sch t ((other :*: S1 m (K1 i v)) :*: rest) 'HereRight where
toSchemaRecordSearch _ ((_ :*: M1 (K1 x)) :*: _) = toSchemaFieldType x
instance GToSchemaFieldType sch t v
=> GToSchemaRecordSearch sch t ((other1 :*: (S1 m (K1 i v) :*: other2)) :*: rest) 'HereRightThenLeft where
toSchemaRecordSearch _ ((_ :*: (M1 (K1 x) :*: _)) :*: _) = toSchemaFieldType x
instance GToSchemaFieldType sch t v
=> GToSchemaRecordSearch sch t ((other1 :*: (other2 :*: S1 m (K1 i v))) :*: rest) 'HereTwoRights where
toSchemaRecordSearch _ ((_ :*: (_ :*: M1 (K1 x))) :*: _) = toSchemaFieldType x
instance forall sch t other rest n.
GToSchemaRecordSearch sch t rest n
=> GToSchemaRecordSearch sch t (other :*: rest) ('There n) where
toSchemaRecordSearch _ (_ :*: xs) = toSchemaRecordSearch (Proxy @n) xs
class GFromSchemaRecord (sch :: Schema ts fs) (fmap :: Mappings Symbol fs)
(args :: [FieldDef ts fs]) (f :: * -> *) where
fromSchemaRecord :: Proxy fmap -> NP (Field sch) args -> f a
instance (GFromSchemaRecordSearch sch v args (FindField args (MappingRight fmap name)))
=> GFromSchemaRecord sch fmap args (S1 ('MetaSel ('Just name) u ss ds) (K1 i v)) where
fromSchemaRecord _ x
= M1 $ K1 $ fromSchemaRecordSearch (Proxy @(FindField args (MappingRight fmap name))) x
instance ( GFromSchemaRecord sch fmap args oneway
, GFromSchemaRecord sch fmap args oranother )
=> GFromSchemaRecord sch fmap args (oneway :*: oranother) where
fromSchemaRecord p x = fromSchemaRecord p x :*: fromSchemaRecord p x
instance GFromSchemaRecord sch fmap args U1 where
fromSchemaRecord _ _ = U1
class GFromSchemaRecordSearch (sch :: Schema ts fs)
(v :: *) (args :: [FieldDef ts fs]) (wh :: Where) where
fromSchemaRecordSearch :: Proxy wh -> NP (Field sch) args -> v
instance (GFromSchemaFieldType sch t v)
=> GFromSchemaRecordSearch sch v ('FieldDef name t ': rest) 'Here where
fromSchemaRecordSearch _ (Field x :* _) = fromSchemaFieldType x
instance forall sch v other rest n.
GFromSchemaRecordSearch sch v rest n
=> GFromSchemaRecordSearch sch v (other ': rest) ('There n) where
fromSchemaRecordSearch _ (_ :* xs) = fromSchemaRecordSearch (Proxy @n) xs