@@ -8,28 +8,11 @@ module Data.Schematic.Schema where
9import Data.Kind hiding (Type)
9import Data.Kind hiding (Type)
10import Data.Proxy
10import Data.Proxy
11+import Data.Schematic.Validation
11import Data.Text (Text)
12import Data.Text (Text)
12import GHC.TypeLits (KnownNat, natVal, KnownSymbol, symbolVal, Symbol, Nat)
13import GHC.TypeLits (KnownNat, natVal, KnownSymbol, symbolVal, Symbol, Nat)
23−type family Repr (ty :: JType) :: * where
24− Repr 'JText = String -- because of matchRegex
25− Repr 'JNumber = Double
27−type family CRepr (jty :: JType) :: * where
28− CRepr JText = TextConstraint
29− CRepr JNumber = NumberConstraint
30− CRepr JObject = (String, Schema)
31− CRepr JArray = ArrayConstraint
33class Constrained (ty :: JType) c where
16class Constrained (ty :: JType) c where
34 cRep :: Proxy ty -> Proxy c -> CRepr ty
17 cRep :: Proxy ty -> Proxy c -> CRepr ty
@@ -92,45 +75,17 @@ instance
92 fieldName = symbolVal (Proxy @field)
75 fieldName = symbolVal (Proxy @field)
93 fieldSchema = constructor (Proxy @jty) $ schema (Proxy @jty) (Proxy @cs)
76 fieldSchema = constructor (Proxy @jty) $ schema (Proxy @jty) (Proxy @cs)
101−data NumberConstraint
108− = LengthArrEq Integer
112− = SchemaText [TextConstraint]
113− | SchemaNumber [NumberConstraint]
114− | SchemaObject [(String, Schema)]
115− | SchemaArray [ArrayConstraint] Schema
118−-- | Apply constraint for each element of list
119−-- type family AllSatisfy (c :: k -> Constraint) (s :: [k]) :: Constraint where
120−-- AllSatisfy c '[] = ()
121−-- AllSatisfy c (a ': as) = (c a, AllSatisfy c as)
123class SchemaConstructor jty where
78class SchemaConstructor jty where
124 constructor :: Proxy jty -> [CRepr jty] -> Schema
79 constructor :: Proxy jty -> [CRepr jty] -> Schema
126instance SchemaConstructor 'JText where
81instance SchemaConstructor 'JText where
127− constructor _ = SchemaText
82+ constructor _ = SchemaText SJText
129instance SchemaConstructor 'JNumber where
84instance SchemaConstructor 'JNumber where
130− constructor _ = SchemaNumber
85+ constructor _ = SchemaNumber SJNumber
132instance SchemaConstructor 'JObject where
87instance SchemaConstructor 'JObject where
133− constructor _ = SchemaObject
88+ constructor _ = SchemaObject SJObject
135class Schematic ty where
90class Schematic ty where
136 type JT (ty :: k) :: JType
91 type JT (ty :: k) :: JType
@@ -174,6 +129,7 @@ instance
174 type JT (SArray cs s) = 'JArray
129 type JT (SArray cs s) = 'JArray
175 build _ =
130 build _ =
176 SchemaArray
131 SchemaArray
177 (schema (Proxy @'JArray) (Proxy @cs))
133 (schema (Proxy @'JArray) (Proxy @cs))
178 (build (Proxy @s))
134 (build (Proxy @s))