| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Schemas.Internal
Synopsis
- data TypedSchemaFlex from a where
- TEnum :: NonEmpty (Text, a) -> (from -> Text) -> TypedSchemaFlex from a
- TArray :: TypedSchema b -> (Vector b -> a) -> (from -> Vector b) -> TypedSchemaFlex from a
- TMap :: TypedSchema b -> (HashMap Text b -> a) -> (from -> HashMap Text b) -> TypedSchemaFlex from a
- TAllOf :: NonEmpty (TypedSchemaFlex from a) -> TypedSchemaFlex from a
- TOneOf :: NonEmpty (TypedSchemaFlex from a) -> TypedSchemaFlex from a
- TEmpty :: a -> TypedSchemaFlex from a
- TPrim :: Text -> (Value -> Result a) -> (from -> Value) -> TypedSchemaFlex from a
- TTry :: TypedSchemaFlex a b -> (a' -> Maybe a) -> TypedSchemaFlex a' b
- RecordSchema :: RecordFields from a -> TypedSchemaFlex from a
- enum :: Eq a => (a -> Text) -> NonEmpty a -> TypedSchema a
- stringMap :: TypedSchema a -> TypedSchema (HashMap Text a)
- list :: IsList l => TypedSchema (Item l) -> TypedSchema l
- vector :: TypedSchema a -> TypedSchema (Vector a)
- viaJSON :: (FromJSON a, ToJSON a) => Text -> TypedSchema a
- viaIso :: Iso' a b -> TypedSchema a -> TypedSchema b
- string :: TypedSchema String
- readShow :: (Read a, Show a) => TypedSchema a
- type TypedSchema a = TypedSchemaFlex a a
- data RecordField from a where
- RequiredAp :: {..} -> RecordField from a
- OptionalAp :: {..} -> RecordField from a
- fieldNameL :: Lens' (RecordField from a) Text
- newtype RecordFields from a = RecordFields {
- getRecordFields :: Alt (RecordField from) a
- overFieldNames :: (Text -> Text) -> RecordFields from a -> RecordFields from a
- record :: RecordFields from a -> TypedSchemaFlex from a
- fieldWith :: TypedSchema a -> Text -> (from -> a) -> RecordFields from a
- fieldWith' :: TypedSchemaFlex from a -> Text -> RecordFields from a
- data TryFailed = TryFailed
- liftPrism :: Prism s t a b -> TypedSchemaFlex a b -> TypedSchemaFlex s t
- liftMaybe :: TypedSchemaFlex a b -> TypedSchemaFlex (Maybe a) (Maybe b)
- liftEither :: TypedSchemaFlex a b -> TypedSchemaFlex (Either c a) (Either c b)
- optFieldWith :: forall a from. TypedSchemaFlex from (Maybe a) -> Text -> RecordFields from (Maybe a)
- optFieldGeneral :: forall a from. TypedSchemaFlex from a -> Text -> a -> RecordFields from a
- optFieldEitherWith :: TypedSchemaFlex from (Either e a) -> Text -> e -> RecordFields from (Either e a)
- extractFields :: RecordFields from a -> [[(Text, Field)]]
- extractFieldsHelper :: (forall a. RecordField from a -> b) -> RecordFields from a -> [[b]]
- union :: NonEmpty (Text, TypedSchema a) -> TypedSchema a
- data UnionTag from where
- UnionTag :: Text -> Prism' from b -> TypedSchema b -> UnionTag from
- altWith :: TypedSchema a -> Text -> Prism' from a -> UnionTag from
- union' :: NonEmpty (UnionTag from) -> TypedSchema from
- extractSchema :: TypedSchemaFlex from a -> Schema
- extractValidators :: TypedSchemaFlex from a -> Validators
- encodeWith :: TypedSchemaFlex from a -> from -> Value
- encodeToWith :: TypedSchema a -> Schema -> Maybe (a -> Value)
- data DecodeError
- runSchema :: TypedSchemaFlex enc dec -> enc -> Either [DecodeError] dec
- decodeWith :: TypedSchemaFlex from a -> Value -> Either [(Trace, DecodeError)] a
- decodeFromWith :: TypedSchema a -> Schema -> Maybe (Value -> Either [(Trace, DecodeError)] a)
- runAlt_ :: (Alternative g, Monoid m) => (forall a. f a -> g m) -> Alt f b -> g m
- (<.>) :: Functor f => (b -> c) -> (a -> f b) -> a -> f c
Documentation
data TypedSchemaFlex from a where Source #
TypedSchemaFlex enc dec is a schema for encoding to enc and decoding to dec.
Usually we want enc and dec to be the same type but this flexibility comes in handy
when composing typed schemas.
Constructors
| TEnum :: NonEmpty (Text, a) -> (from -> Text) -> TypedSchemaFlex from a | |
| TArray :: TypedSchema b -> (Vector b -> a) -> (from -> Vector b) -> TypedSchemaFlex from a | |
| TMap :: TypedSchema b -> (HashMap Text b -> a) -> (from -> HashMap Text b) -> TypedSchemaFlex from a | |
| TAllOf :: NonEmpty (TypedSchemaFlex from a) -> TypedSchemaFlex from a | Encoding and decoding support all alternatives |
| TOneOf :: NonEmpty (TypedSchemaFlex from a) -> TypedSchemaFlex from a | Decoding from all alternatives, but encoding only to one |
| TEmpty :: a -> TypedSchemaFlex from a | |
| TPrim :: Text -> (Value -> Result a) -> (from -> Value) -> TypedSchemaFlex from a | |
| TTry :: TypedSchemaFlex a b -> (a' -> Maybe a) -> TypedSchemaFlex a' b | |
| RecordSchema :: RecordFields from a -> TypedSchemaFlex from a |
Instances
stringMap :: TypedSchema a -> TypedSchema (HashMap Text a) Source #
list :: IsList l => TypedSchema (Item l) -> TypedSchema l Source #
vector :: TypedSchema a -> TypedSchema (Vector a) Source #
viaIso :: Iso' a b -> TypedSchema a -> TypedSchema b Source #
type TypedSchema a = TypedSchemaFlex a a Source #
data RecordField from a where Source #
Constructors
| RequiredAp | |
Fields
| |
| OptionalAp | |
Fields
| |
Instances
| Profunctor RecordField Source # | |
Defined in Schemas.Internal Methods dimap :: (a -> b) -> (c -> d) -> RecordField b c -> RecordField a d # lmap :: (a -> b) -> RecordField b c -> RecordField a c # rmap :: (b -> c) -> RecordField a b -> RecordField a c # (#.) :: Coercible c b => q b c -> RecordField a b -> RecordField a c # (.#) :: Coercible b a => RecordField b c -> q a b -> RecordField a c # | |
fieldNameL :: Lens' (RecordField from a) Text Source #
newtype RecordFields from a Source #
Constructors
| RecordFields | |
Fields
| |
Instances
overFieldNames :: (Text -> Text) -> RecordFields from a -> RecordFields from a Source #
record :: RecordFields from a -> TypedSchemaFlex from a Source #
Define a record schema using applicative syntax
fieldWith :: TypedSchema a -> Text -> (from -> a) -> RecordFields from a Source #
fieldWith' :: TypedSchemaFlex from a -> Text -> RecordFields from a Source #
Constructors
| TryFailed |
Instances
| Show TryFailed Source # | |
| Exception TryFailed Source # | |
Defined in Schemas.Internal Methods toException :: TryFailed -> SomeException # fromException :: SomeException -> Maybe TryFailed # displayException :: TryFailed -> String # | |
liftPrism :: Prism s t a b -> TypedSchemaFlex a b -> TypedSchemaFlex s t Source #
Project a schema through a Prism. The resulting schema is empty if the Prism doesn't fit
liftMaybe :: TypedSchemaFlex a b -> TypedSchemaFlex (Maybe a) (Maybe b) Source #
Use this to build schemas for optFieldWith. The resulting schema is empty for the Nothing case
liftEither :: TypedSchemaFlex a b -> TypedSchemaFlex (Either c a) (Either c b) Source #
Use this to build schemas for optFieldEitherWith. The resulting schema is empty for the Left case
optFieldWith :: forall a from. TypedSchemaFlex from (Maybe a) -> Text -> RecordFields from (Maybe a) Source #
A generalized version of optField. Does not handle infinite/circular data.
optFieldGeneral :: forall a from. TypedSchemaFlex from a -> Text -> a -> RecordFields from a Source #
optFieldEitherWith :: TypedSchemaFlex from (Either e a) -> Text -> e -> RecordFields from (Either e a) Source #
A generalized version of optFieldEither. Does not handle infinite/circular data
extractFields :: RecordFields from a -> [[(Text, Field)]] Source #
Extract all the field groups (from alternatives) in the record
extractFieldsHelper :: (forall a. RecordField from a -> b) -> RecordFields from a -> [[b]] Source #
union :: NonEmpty (Text, TypedSchema a) -> TypedSchema a Source #
data UnionTag from where Source #
Constructors
| UnionTag :: Text -> Prism' from b -> TypedSchema b -> UnionTag from |
extractSchema :: TypedSchemaFlex from a -> Schema Source #
Extract an untyped schema that can be serialized
extractValidators :: TypedSchemaFlex from a -> Validators Source #
Returns all the primitive validators embedded in this typed schema
encodeWith :: TypedSchemaFlex from a -> from -> Value Source #
Given a value and its typed schema, produce a JSON record using the RecordFields
encodeToWith :: TypedSchema a -> Schema -> Maybe (a -> Value) Source #
data DecodeError Source #
Constructors
| VE Mismatch | |
| TriedAndFailed |
Instances
| Eq DecodeError Source # | |
Defined in Schemas.Internal | |
| Show DecodeError Source # | |
Defined in Schemas.Internal Methods showsPrec :: Int -> DecodeError -> ShowS # show :: DecodeError -> String # showList :: [DecodeError] -> ShowS # | |
runSchema :: TypedSchemaFlex enc dec -> enc -> Either [DecodeError] dec Source #
Runs a schema as a function enc -> dec. Loops for infinite/circular data
decodeWith :: TypedSchemaFlex from a -> Value -> Either [(Trace, DecodeError)] a Source #
Given a JSON Value and a typed schema, extract a Haskell value
decodeFromWith :: TypedSchema a -> Schema -> Maybe (Value -> Either [(Trace, DecodeError)] a) Source #