@@ -7,7 +7,6 @@ module Data.Schematic
7 , module Data.Schematic.Lens
7 , module Data.Schematic.Lens
8 , module Data.Schematic.Migration
8 , module Data.Schematic.Migration
9 , module Data.Schematic.Schema
9 , module Data.Schematic.Schema
10− , module Data.Schematic.Utils
11 , decodeAndValidateJson
10 , decodeAndValidateJson
12 , parseAndValidateJson
11 , parseAndValidateJson
13 , parseAndValidateJsonBy
12 , parseAndValidateJsonBy
@@ -28,23 +27,15 @@ import Data.Aeson as J
28import Data.Aeson.Types as J
27import Data.Aeson.Types as J
29import Data.ByteString.Lazy as BL
28import Data.ByteString.Lazy as BL
30import Data.Functor.Identity as F
29import Data.Functor.Identity as F
31−import Data.Kind
30+import Data.Schematic.DSL
32import Data.Schematic.Helpers
31import Data.Schematic.Helpers
33import Data.Schematic.JsonSchema
32import Data.Schematic.JsonSchema
34import Data.Schematic.Lens
33import Data.Schematic.Lens
35import Data.Schematic.Migration
34import Data.Schematic.Migration
36import Data.Schematic.Schema
35import Data.Schematic.Schema
37−import Data.Schematic.Utils
38import Data.Schematic.Validation
36import Data.Schematic.Validation
39−import Data.Scientific
40import Data.Singletons.Prelude hiding ((:.))
37import Data.Singletons.Prelude hiding ((:.))
41−import Data.Singletons.TypeLits
43import Data.Text as T
38import Data.Text as T
45−import qualified Data.Vector as V
46−import Data.Vinyl as V
47−import Data.Vinyl.Functor
50parseAndValidateJson
41parseAndValidateJson
@@ -135,56 +126,3 @@ decodeAndValidateVersionedWithPureMList
135 -> ParseResult (JsonRepr (Head (MapSnd (AllVersions versioned))))
126 -> ParseResult (JsonRepr (Head (MapSnd (AllVersions versioned))))
136decodeAndValidateVersionedWithPureMList a b c =
127decodeAndValidateVersionedWithPureMList a b c =
137 runIdentity $ decodeAndValidateVersionedWithMList a b c
128 runIdentity $ decodeAndValidateVersionedWithMList a b c
139−-- convenience helpers
142− = forall b. FSubset (FieldsOf a) b (FImage (FieldsOf a) b)
143− => Rec (Tagged (FieldsOf a) :. FieldRepr) b
144− -> JsonRepr ('SchemaObject (FieldsOf a))
146−withRepr :: Constructor a
147−withRepr = ReprObject . rmap (unTagged . getCompose) . fcast
149−class Representable s where
151− construct :: Sing fn -> Proxy s -> Repr s -> FieldRepr '(fn, s)
153−instance SingI so => Representable ('SchemaObject so) where
154− type Repr ('SchemaObject so) = Rec FieldRepr so
155− construct sfn _ o = withKnownSymbol sfn $ FieldRepr $ ReprObject o
157−instance (SingI cs, SingI sa) => Representable ('SchemaArray cs sa) where
158− type Repr ('SchemaArray cs sa) = V.Vector (JsonRepr sa)
159− construct sfn _ a = withKnownSymbol sfn $ FieldRepr $ ReprArray a
161−instance SingI cs => Representable ('SchemaText cs) where
162− type Repr ('SchemaText cs) = Text
163− construct sfn _ t = withKnownSymbol sfn $ FieldRepr $ ReprText t
165−instance SingI cs => Representable ('SchemaNumber cs) where
166− type Repr ('SchemaNumber cs) = Scientific
167− construct sfn _ n = withKnownSymbol sfn $ FieldRepr $ ReprNumber n
169−instance Representable 'SchemaBoolean where
170− type Repr 'SchemaBoolean = Bool
171− construct sfn _ b = withKnownSymbol sfn $ FieldRepr $ ReprBoolean b
173−instance SingI so => Representable ('SchemaOptional so) where
174− type Repr ('SchemaOptional so) = Maybe (JsonRepr so)
175− construct sfn _ o = withKnownSymbol sfn $ FieldRepr $ ReprOptional o
177−instance SingI (h ': tl) => Representable ('SchemaUnion (h ': tl)) where
178− type Repr ('SchemaUnion (h ': tl)) = Union JsonRepr (h ': tl)
179− construct sfn _ u = withKnownSymbol sfn $ FieldRepr $ ReprUnion u
181−type family FieldsOf (s :: Schema) :: [(Symbol, Schema)] where
182− FieldsOf ('SchemaObject fs) = fs
184−type FieldConstructor fn =
185− forall fs. (Representable (ByField fn fs (FIndex fn fs)))
186− => Repr (ByField fn fs (FIndex fn fs))
187− -> (Tagged fs :. FieldRepr) '(fn, (ByField fn fs (FIndex fn fs)))
189−field :: forall fn. KnownSymbol fn => FieldConstructor fn
190−field = Compose . Tagged . construct (sing :: Sing fn) Proxy