@@ -7,7 +7,6 @@ module Data.Schematic
77 , module Data.Schematic.Lens
88 , module Data.Schematic.Migration
99 , module Data.Schematic.Schema
10− , module Data.Schematic.Utils
1110 , decodeAndValidateJson
1211 , parseAndValidateJson
1312 , parseAndValidateJsonBy
@@ -28,23 +27,15 @@ import Data.Aeson as J
2827import Data.Aeson.Types as J
2928import Data.ByteString.Lazy as BL
3029import Data.Functor.Identity as F
31−import Data.Kind
30+import Data.Schematic.DSL
3231import Data.Schematic.Helpers
3332import Data.Schematic.JsonSchema
3433import Data.Schematic.Lens
3534import Data.Schematic.Migration
3635import Data.Schematic.Schema
37−import Data.Schematic.Utils
3836import Data.Schematic.Validation
39−import Data.Scientific
4037import Data.Singletons.Prelude hiding ((:.))
41−import Data.Singletons.TypeLits
42−import Data.Tagged
4338import Data.Text as T
44−import Data.Union
45−import qualified Data.Vector as V
46−import Data.Vinyl as V
47−import Data.Vinyl.Functor
4839
4940
5041parseAndValidateJson
@@ -135,56 +126,3 @@ decodeAndValidateVersionedWithPureMList
135126 -> ParseResult (JsonRepr (Head (MapSnd (AllVersions versioned))))
136127decodeAndValidateVersionedWithPureMList a b c =
137128 runIdentity $ decodeAndValidateVersionedWithMList a b c
138−
139−-- convenience helpers
140−
141−type Constructor a
142− = forall b. FSubset (FieldsOf a) b (FImage (FieldsOf a) b)
143− => Rec (Tagged (FieldsOf a) :. FieldRepr) b
144− -> JsonRepr ('SchemaObject (FieldsOf a))
145−
146−withRepr :: Constructor a
147−withRepr = ReprObject . rmap (unTagged . getCompose) . fcast
148−
149−class Representable s where
150− type Repr s :: Type
151− construct :: Sing fn -> Proxy s -> Repr s -> FieldRepr '(fn, s)
152−
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
156−
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
160−
161−instance SingI cs => Representable ('SchemaText cs) where
162− type Repr ('SchemaText cs) = Text
163− construct sfn _ t = withKnownSymbol sfn $ FieldRepr $ ReprText t
164−
165−instance SingI cs => Representable ('SchemaNumber cs) where
166− type Repr ('SchemaNumber cs) = Scientific
167− construct sfn _ n = withKnownSymbol sfn $ FieldRepr $ ReprNumber n
168−
169−instance Representable 'SchemaBoolean where
170− type Repr 'SchemaBoolean = Bool
171− construct sfn _ b = withKnownSymbol sfn $ FieldRepr $ ReprBoolean b
172−
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
176−
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
180−
181−type family FieldsOf (s :: Schema) :: [(Symbol, Schema)] where
182− FieldsOf ('SchemaObject fs) = fs
183−
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)))
188−
189−field :: forall fn. KnownSymbol fn => FieldConstructor fn
190−field = Compose . Tagged . construct (sing :: Sing fn) Proxy