| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Schema
Description
This module exists to take concrete types and convert them into something we can easily create generic UI forms for, based on their structure. As a secondary requirement, it also aims to be easy to serialize to a sensible JSON representation.
ToSchema turns a function signature into a FormSchema - a
description that can serialised as JSON and analysed in PureScript
land. In essence it's a simplified, specialised version of a
Generic representation.
The frontend then takes a FormSchema, generates a UI form, and
allows the user create a concrete value that follows that
schema. This is the FormArgument.
It's useful for the backend to make this instantiation too (because we want to give the user example filled-in forms), so we provide ToArgument.
Synopsis
- class ToSchema a
- toSchema :: ToSchema a => FormSchema
- class ToSchema a => ToArgument a
- toArgument :: ToArgument a => a -> Fix FormArgumentF
- data FormSchema
- = FormSchemaUnit
- | FormSchemaBool
- | FormSchemaInt
- | FormSchemaInteger
- | FormSchemaString
- | FormSchemaHex
- | FormSchemaArray FormSchema
- | FormSchemaMaybe FormSchema
- | FormSchemaRadio [String]
- | FormSchemaTuple FormSchema FormSchema
- | FormSchemaObject [(String, FormSchema)]
- | FormSchemaValue
- | FormSchemaPOSIXTimeRange
- | FormSchemaUnsupported String
- type FormArgument = Fix FormArgumentF
- data FormArgumentF a
- = FormUnitF
- | FormBoolF Bool
- | FormIntF (Maybe Int)
- | FormIntegerF (Maybe Integer)
- | FormStringF (Maybe String)
- | FormHexF (Maybe String)
- | FormRadioF [String] (Maybe String)
- | FormArrayF FormSchema [a]
- | FormMaybeF FormSchema (Maybe a)
- | FormTupleF a a
- | FormObjectF [(String, a)]
- | FormValueF Value
- | FormPOSIXTimeRangeF (Interval POSIXTime)
- | FormUnsupportedF String
- formArgumentToJson :: Fix FormArgumentF -> Maybe Value
Documentation
A description of a type, suitable for consumption by the Playground's website.
By calling toSchema on a type you get a description of its
structure. Semantically:
>>>toSchema @Int>>>-- returns, "this is an Int.">>>>>>toSchema @SomeRecord>>>-- returns, "this is a record, and it has>>>-- these named fields with these types".
The description you get back is the FormSchema type, which
describes all the obvious primitives, plus some Plutus types
deemed worthy of special treatment (eg. Value).
Internally it relies on Generics to extract the type
information, but the implementation jumps through some hoops
because generics is geared towards getting the type-description of
a specific value (eg. Left Foo or Right 5) rather than on the
type itself (eg. Either String Int).
Instances
toSchema :: ToSchema a => FormSchema Source #
class ToSchema a => ToArgument a Source #
The value-level equivalent of ToSchema. Where ToSchema takes
your type and returns a generic description of its structure,
ToArgument takes your value and returns an equivalent value with
a more generic structure. So semantially:
The description you get back is the FormArgument type, which
describes all the obvious primitives, plus some Plutus types
deemed worthy of special treatment (eg. Value).
>>>toSchema @User>>>-- returns, "this is a record with a 'name' field, which is a String.">>>>>>toArgument (User "Dave")>>>-- returns, "this is a record with a 'name' field, which is a the String 'Dave'."
Instances
toArgument :: ToArgument a => a -> Fix FormArgumentF Source #
data FormSchema Source #
Constructors
| FormSchemaUnit | |
| FormSchemaBool | |
| FormSchemaInt | |
| FormSchemaInteger | |
| FormSchemaString | |
| FormSchemaHex | A string that may only contain |
| FormSchemaArray FormSchema | |
| FormSchemaMaybe FormSchema | |
| FormSchemaRadio [String] | A radio button with a list of labels. |
| FormSchemaTuple FormSchema FormSchema | |
| FormSchemaObject [(String, FormSchema)] | |
| FormSchemaValue | |
| FormSchemaPOSIXTimeRange | |
| FormSchemaUnsupported String |
Instances
type FormArgument = Fix FormArgumentF Source #
data FormArgumentF a Source #
Constructors