Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- class HasSchema a where
- schema :: TypedSchema a
- class Key a where
- theSchema :: forall a. HasSchema a => Schema
- validatorsFor :: forall a. HasSchema a => Validators
- encode :: HasSchema a => a -> Value
- encodeTo :: HasSchema a => Schema -> Maybe (a -> Value)
- finiteEncode :: forall a. HasSchema a => Natural -> a -> Value
- decode :: HasSchema a => Value -> Either [(Trace, DecodeError)] a
- decodeFrom :: HasSchema a => Schema -> Maybe (Value -> Either [(Trace, DecodeError)] a)
- coerce :: forall sub sup. (HasSchema sub, HasSchema sup) => Value -> Maybe Value
- field :: HasSchema a => Text -> (from -> a) -> RecordFields from a
- optField :: forall a from. HasSchema a => Text -> (from -> Maybe a) -> RecordFields from (Maybe a)
- optFieldEither :: forall a from e. HasSchema a => Text -> (from -> Either e a) -> e -> RecordFields from (Either e a)
- alt :: HasSchema a => Text -> Prism' from a -> UnionTag from
Documentation
class HasSchema a where Source #
schema :: TypedSchema a Source #
Instances
validatorsFor :: forall a. HasSchema a => Validators Source #
encodeTo :: HasSchema a => Schema -> Maybe (a -> Value) Source #
Attempt to encode to the target schema using the default schema.
First encodes using the default schema, then computes a coercion
applying isSubtypeOf
, and then applies the coercion to the encoded data.
finiteEncode :: forall a. HasSchema a => Natural -> a -> Value Source #
Encode a value into a finite representation by enforcing a max depth
decode :: HasSchema a => Value -> Either [(Trace, DecodeError)] a Source #
Decode using the default schema.
decodeFrom :: HasSchema a => Schema -> Maybe (Value -> Either [(Trace, DecodeError)] a) Source #
Apply isSubtypeOf
to construct a coercion from the source schema to the default schema,
apply the coercion to the data, and attempt to decode using the default schema.
coerce :: forall sub sup. (HasSchema sub, HasSchema sup) => Value -> Maybe Value Source #
Coerce from sub
to sup
Returns Nothing
if sub
is not a subtype of sup
field :: HasSchema a => Text -> (from -> a) -> RecordFields from a Source #
field name get
introduces a field with the default schema for the type
optField :: forall a from. HasSchema a => Text -> (from -> Maybe a) -> RecordFields from (Maybe a) Source #
optField name get
introduces an optional field with the default schema for the type
optFieldEither :: forall a from e. HasSchema a => Text -> (from -> Either e a) -> e -> RecordFields from (Either e a) Source #
optFieldEither name get
introduces an optional field with the default schema for the type