| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Mu.Schema.Interpretation.Schemaless
Description
In the edges of your application it's useful to consider terms for which a type-level schema has not yet been applied. Think of receiving a JSON document: you can parse it but checking the schema is an additional step.
Synopsis
- data Term where
- data Field where
- Field :: Text -> FieldValue -> Field
- data FieldValue where
- FNull :: FieldValue
- FPrimitive :: (Typeable t, Eq t, Ord t, Show t) => t -> FieldValue
- FSchematic :: Term -> FieldValue
- FOption :: Maybe FieldValue -> FieldValue
- FList :: [FieldValue] -> FieldValue
- FMap :: Map FieldValue FieldValue -> FieldValue
- checkSchema :: forall tn fn (s :: Schema tn fn) (t :: tn). CheckSchema s (s :/: t) => Proxy t -> Term -> Maybe (Term s (s :/: t))
- fromSchemalessTerm :: forall sch t sty. (FromSchema sch sty t, CheckSchema sch (sch :/: sty)) => Term -> Maybe t
- class ToSchemalessTerm t where
- toSchemalessTerm :: t -> Term
- class ToSchemalessValue t where
- toSchemalessValue :: t -> FieldValue
- class CheckSchema (s :: Schema tn fn) (t :: TypeDef tn fn)
Terms without an associated schema
Interpretation of a type in a schema.
Constructors
| TRecord :: [Field] -> Term | A record given by the value of its fields. |
| TEnum :: Int -> Term | An enumeration given by one choice. |
| TSimple :: FieldValue -> Term | A primitive value. |
Interpretation of a field.
Constructors
| Field :: Text -> FieldValue -> Field | A single field given by its name and its value. |
data FieldValue where Source #
Interpretation of a field type, by giving a value of that type.
Constructors
| FNull :: FieldValue | |
| FPrimitive :: (Typeable t, Eq t, Ord t, Show t) => t -> FieldValue | |
| FSchematic :: Term -> FieldValue | |
| FOption :: Maybe FieldValue -> FieldValue | |
| FList :: [FieldValue] -> FieldValue | |
| FMap :: Map FieldValue FieldValue -> FieldValue |
Instances
| Eq FieldValue Source # | |
Defined in Mu.Schema.Interpretation.Schemaless | |
| Ord FieldValue Source # | |
Defined in Mu.Schema.Interpretation.Schemaless Methods compare :: FieldValue -> FieldValue -> Ordering # (<) :: FieldValue -> FieldValue -> Bool # (<=) :: FieldValue -> FieldValue -> Bool # (>) :: FieldValue -> FieldValue -> Bool # (>=) :: FieldValue -> FieldValue -> Bool # max :: FieldValue -> FieldValue -> FieldValue # min :: FieldValue -> FieldValue -> FieldValue # | |
| Show FieldValue Source # | |
Defined in Mu.Schema.Interpretation.Schemaless Methods showsPrec :: Int -> FieldValue -> ShowS # show :: FieldValue -> String # showList :: [FieldValue] -> ShowS # | |
Checking and conversion against a schema
checkSchema :: forall tn fn (s :: Schema tn fn) (t :: tn). CheckSchema s (s :/: t) => Proxy t -> Term -> Maybe (Term s (s :/: t)) Source #
fromSchemalessTerm :: forall sch t sty. (FromSchema sch sty t, CheckSchema sch (sch :/: sty)) => Term -> Maybe t Source #
Converts a schemaless term to a Haskell type by going through the corresponding schema type.
For deserialization to schemaless terms
class ToSchemalessTerm t where Source #
Deserialization to schemaless terms.
Methods
toSchemalessTerm :: t -> Term Source #
Turns a document (such as JSON) into a schemaless term. This function should handle the "compound" types in that format, such as records and enumerations.
Instances
| ToSchemalessTerm Value Source # | |
Defined in Mu.Adapter.Json Methods toSchemalessTerm :: Value -> Term Source # | |
class ToSchemalessValue t where Source #
Deserialization to schemaless values.
Methods
toSchemalessValue :: t -> FieldValue Source #
Turns a document (such as JSON) into a schemaless term. This function should handle the "primitive" types in that format.
Instances
| ToSchemalessValue Value Source # | |
Defined in Mu.Adapter.Json Methods toSchemalessValue :: Value -> FieldValue Source # | |
For implementors
class CheckSchema (s :: Schema tn fn) (t :: TypeDef tn fn) Source #
Type class used to define the generic checkSchema.
Exposed for usage in other modules,
in particular Registry.
Minimal complete definition
checkSchema'
Instances
| CheckSchemaValue s f => CheckSchema (s :: Schema typeName fn) ('DSimple f :: TypeDefB Type typeName fn) Source # | |
Defined in Mu.Schema.Interpretation.Schemaless Methods checkSchema' :: Term -> Maybe (Term s ('DSimple f)) | |
| CheckSchemaFields s fields => CheckSchema (s :: Schema typeName fieldName) ('DRecord nm fields :: TypeDefB Type typeName fieldName) Source # | |
Defined in Mu.Schema.Interpretation.Schemaless Methods checkSchema' :: Term -> Maybe (Term s ('DRecord nm fields)) | |
| CheckSchemaEnum choices => CheckSchema (s :: Schema tn fn) ('DEnum nm choices :: TypeDefB Type tn fn) Source # | |
Defined in Mu.Schema.Interpretation.Schemaless Methods checkSchema' :: Term -> Maybe (Term s ('DEnum nm choices)) | |