@@ -46,11 +46,11 @@ data TextConstraint
46 deriving (Generic)
46 deriving (Generic)
48data instance Sing (tc :: TextConstraint) where
48data instance Sing (tc :: TextConstraint) where
49− STEq :: (KnownNat n) => Sing n -> Sing ('TEq n)
49+ STEq :: Sing n -> Sing ('TEq n)
50− STLe :: (KnownNat n) => Sing n -> Sing ('TLe n)
50+ STLe :: Sing n -> Sing ('TLe n)
51− STGt :: (KnownNat n) => Sing n -> Sing ('TGt n)
51+ STGt :: Sing n -> Sing ('TGt n)
52− STRegex :: (KnownSymbol s, SingI s) => Sing s -> Sing ('TRegex s)
52+ STRegex :: Sing s -> Sing ('TRegex s)
53− STEnum :: (All KnownSymbol ss, SingI ss) => Sing ss -> Sing ('TEnum ss)
53+ STEnum :: All KnownSymbol ss => Sing ss -> Sing ('TEnum ss)
55instance (KnownNat n) => SingI ('TEq n) where sing = STEq sing
55instance (KnownNat n) => SingI ('TEq n) where sing = STEq sing
56instance (KnownNat n) => SingI ('TGt n) where sing = STGt sing
56instance (KnownNat n) => SingI ('TGt n) where sing = STGt sing
@@ -71,9 +71,9 @@ data NumberConstraint
71 deriving (Generic)
71 deriving (Generic)
73data instance Sing (nc :: NumberConstraint) where
73data instance Sing (nc :: NumberConstraint) where
74− SNEq :: KnownNat n => Sing n -> Sing ('NEq n)
74+ SNEq :: Sing n -> Sing ('NEq n)
75− SNGt :: KnownNat n => Sing n -> Sing ('NGt n)
75+ SNGt :: Sing n -> Sing ('NGt n)
76− SNLe :: KnownNat n => Sing n -> Sing ('NLe n)
76+ SNLe :: Sing n -> Sing ('NLe n)
78instance KnownNat n => SingI ('NEq n) where sing = SNEq sing
78instance KnownNat n => SingI ('NEq n) where sing = SNEq sing
79instance KnownNat n => SingI ('NGt n) where sing = SNGt sing
79instance KnownNat n => SingI ('NGt n) where sing = SNGt sing
@@ -88,7 +88,7 @@ data ArrayConstraint
88 deriving (Generic)
88 deriving (Generic)
90data instance Sing (ac :: ArrayConstraint) where
90data instance Sing (ac :: ArrayConstraint) where
91− SAEq :: KnownNat n => Sing n -> Sing ('AEq n)
91+ SAEq :: Sing n -> Sing ('AEq n)
93instance KnownNat n => SingI ('AEq n) where sing = SAEq sing
93instance KnownNat n => SingI ('AEq n) where sing = SAEq sing
@@ -104,11 +104,11 @@ data Schema
104 deriving (Generic)
104 deriving (Generic)
106data instance Sing (schema :: Schema) where
106data instance Sing (schema :: Schema) where
107− SSchemaText :: SingI tcs => Sing tcs -> Sing ('SchemaText tcs)
107+ SSchemaText :: Sing tcs -> Sing ('SchemaText tcs)
108− SSchemaNumber :: SingI ncs => Sing ncs -> Sing ('SchemaNumber ncs)
108+ SSchemaNumber :: Sing ncs -> Sing ('SchemaNumber ncs)
109− SSchemaArray :: (SingI acs, SingI schema) => Sing acs -> Sing schema -> Sing ('SchemaArray acs schema)
109+ SSchemaArray :: Sing acs -> Sing schema -> Sing ('SchemaArray acs schema)
110− SSchemaObject :: SingI fields => Sing fields -> Sing ('SchemaObject fields)
110+ SSchemaObject :: Sing fields -> Sing ('SchemaObject fields)
111− SSchemaOptional :: SingI s => Sing s -> Sing ('SchemaOptional s)
111+ SSchemaOptional :: Sing s -> Sing ('SchemaOptional s)
112 SSchemaNull :: Sing 'SchemaNull
112 SSchemaNull :: Sing 'SchemaNull
114instance SingI sl => SingI ('SchemaText sl) where
114instance SingI sl => SingI ('SchemaText sl) where
@@ -238,37 +238,38 @@ fromOptional _ = parseJSON
239instance SingI schema => J.FromJSON (JsonRepr schema) where
239instance SingI schema => J.FromJSON (JsonRepr schema) where
240 parseJSON value = case sing :: Sing schema of
240 parseJSON value = case sing :: Sing schema of
241− SSchemaText _ -> withText "String" (pure . ReprText) value
241+ SSchemaText _ -> withText "String" (pure . ReprText) value
242− SSchemaNumber _ -> withScientific "Number" (pure . ReprNumber) value
242+ SSchemaNumber _ -> withScientific "Number" (pure . ReprNumber) value
243− SSchemaNull -> case value of
243+ SSchemaNull -> case value of
244 J.Null -> pure ReprNull
244 J.Null -> pure ReprNull
245 _ -> typeMismatch "Null" value
245 _ -> typeMismatch "Null" value
246− so@(SSchemaOptional _) -> ReprOptional <$> fromOptional so value
246+ so@(SSchemaOptional s) -> withSingI s $ ReprOptional <$> fromOptional so value
247+ SSchemaArray sa sb -> withSingI sa $ withSingI sb
247− SSchemaArray _ _ -> withArray "Array" (fmap ReprArray . traverse parseJSON) value
248+ $ withArray "Array" (fmap ReprArray . traverse parseJSON) value
248− SSchemaObject fs -> do
249+ SSchemaObject fs -> do
250 demoteFields :: SList s -> H.HashMap Text J.Value -> Parser (Rec FieldRepr s)
251 demoteFields :: SList s -> H.HashMap Text J.Value -> Parser (Rec FieldRepr s)
251 demoteFields SNil _ = pure RNil
252 demoteFields SNil _ = pure RNil
252 demoteFields (SCons (STuple2 (n :: Sing fn) s) tl) h = withKnownSymbol n $ do
253 demoteFields (SCons (STuple2 (n :: Sing fn) s) tl) h = withKnownSymbol n $ do
253 let fieldName = T.pack $ symbolVal (Proxy @fn)
254 let fieldName = T.pack $ symbolVal (Proxy @fn)
254 fieldRepr <- case s of
255 fieldRepr <- case s of
255− SSchemaText _ -> case H.lookup fieldName h of
256+ SSchemaText so -> case H.lookup fieldName h of
256− Just v -> FieldRepr <$> parseJSON v
257+ Just v -> withSingI so $ FieldRepr <$> parseJSON v
257 Nothing -> fail "schematext"
258 Nothing -> fail "schematext"
258− SSchemaNumber _ -> case H.lookup fieldName h of
259+ SSchemaNumber so -> case H.lookup fieldName h of
259− Just v -> FieldRepr <$> parseJSON v
260+ Just v -> withSingI so $ FieldRepr <$> parseJSON v
260 Nothing -> fail "schemanumber"
261 Nothing -> fail "schemanumber"
261 SSchemaNull -> case H.lookup fieldName h of
262 SSchemaNull -> case H.lookup fieldName h of
262 Just v -> FieldRepr <$> parseJSON v
263 Just v -> FieldRepr <$> parseJSON v
263 Nothing -> fail "schemanull"
264 Nothing -> fail "schemanull"
264− SSchemaArray _ _ -> case H.lookup fieldName h of
265+ SSchemaArray sa sb -> case H.lookup fieldName h of
265− Just v -> FieldRepr <$> parseJSON v
266+ Just v -> withSingI sa $ withSingI sb $ FieldRepr <$> parseJSON v
266 Nothing -> fail "schemaarray"
267 Nothing -> fail "schemaarray"
267− SSchemaObject _ -> case H.lookup fieldName h of
268+ SSchemaObject so -> case H.lookup fieldName h of
268− Just v -> FieldRepr <$> parseJSON v
269+ Just v -> withSingI so $ FieldRepr <$> parseJSON v
269 Nothing -> fail "schemaobject"
270 Nothing -> fail "schemaobject"
270− SSchemaOptional _ -> case H.lookup fieldName h of
271+ SSchemaOptional so -> case H.lookup fieldName h of
271− Just v -> FieldRepr <$> parseJSON v
272+ Just v -> withSingI so $ FieldRepr <$> parseJSON v
272 Nothing -> fail "schemaoptional"
273 Nothing -> fail "schemaoptional"
273 (fieldRepr :&) <$> demoteFields tl h
274 (fieldRepr :&) <$> demoteFields tl h
274 ReprObject <$> withObject "Object" (demoteFields fs) value
275 ReprObject <$> withObject "Object" (demoteFields fs) value