Safe Haskell | None |
---|---|
Language | Haskell2010 |
Avro Schema
s, represented here as values of type Schema
,
describe the serialization and de-serialization of values.
In Avro schemas are compose-able such that encoding data under a schema and
decoding with a variant, such as newer or older version of the original
schema, can be accomplished by using the Deconflict
module.
- type Schema = Type
- data Type
- data Field = Field {}
- data Order
- newtype TypeName = TN {}
- mkEnum :: TypeName -> [TypeName] -> Maybe Text -> Maybe Text -> [Text] -> Type
- mkUnion :: NonEmpty Type -> Type
- validateSchema :: Schema -> Parser ()
- typeName :: Type -> Text
- buildTypeEnvironment :: Applicative m => (TypeName -> m Type) -> Type -> TypeName -> m Type
- data Result a
Schema description types
An Avro schema is either * A "JSON object in the form `{"type":"typeName" ...` * A "JSON string, naming a defined type" (basic type wo free variablesnames) * A "JSON array, representing a union"
N.B. It is possible to create a Haskell value (of Schema type) that is
not a valid Avro schema by violating one of the above or one of the
conditions called out in validateSchema
.
Avro types are considered either primitive (string, int, etc) or complex/declared (structures, unions etc).
mkEnum :: TypeName -> [TypeName] -> Maybe Text -> Maybe Text -> [Text] -> Type Source #
mkEnum name aliases namespace docs syms
Constructs an Enum
schema using
the enumeration type's name, aliases (if any), namespace, documentation, and list of
symbols that inhabit the enumeration.
mkUnion :: NonEmpty Type -> Type Source #
mkUnion subTypes
Defines a union of the provided subTypes. N.B. it is
invalid Avro to include another union or to have more than one of the same
type as a direct member of the union. No check is done for this condition!
validateSchema :: Schema -> Parser () Source #
Placeholder NO-OP function!
Validates a schema to ensure:
- All types are defined
- Unions do not directly contain other unions
- Unions are not ambiguous (may not contain more than one schema with the same type except for named types of record, fixed and enum)
- Default values for unions can be cast as the type indicated by the first structure.
- Default values can be cast/de-serialize correctly.
- Named types are resolvable
Lower level utilities
typeName :: Type -> Text Source #
Get the name of the type. In the case of unions, get the name of the first value in the union schema.
buildTypeEnvironment :: Applicative m => (TypeName -> m Type) -> Type -> TypeName -> m Type Source #
buildTypeEnvironment schema
builds a function mapping type names to
the types declared in the traversed schema. Notice this function does not
currently handle namespaces in a correct manner, possibly allowing
for bad environment lookups when used on complex schemas.
Monad Result Source # | |
Functor Result Source # | |
MonadFail Result Source # | |
Applicative Result Source # | |
Foldable Result Source # | |
Traversable Result Source # | |
Alternative Result Source # | |
MonadPlus Result Source # | |
MonadError String Result Source # | |
Eq a => Eq (Result a) Source # | |
Ord a => Ord (Result a) Source # | |
Show a => Show (Result a) Source # | |
Monoid (Result a) Source # | |