playground-common-0.1.0.0
Safe HaskellNone
LanguageHaskell2010

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

Documentation

class ToSchema a Source #

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

Instances details
ToSchema Bool Source # 
Instance details

Defined in Schema

ToSchema Int Source # 
Instance details

Defined in Schema

ToSchema Integer Source # 
Instance details

Defined in Schema

ToSchema () Source # 
Instance details

Defined in Schema

ToSchema String Source # 
Instance details

Defined in Schema

ToSchema Text Source # 
Instance details

Defined in Schema

ToSchema TxOutRef Source # 
Instance details

Defined in Schema

ToSchema Slot Source # 
Instance details

Defined in Schema

ToSchema AssetClass Source # 
Instance details

Defined in Schema

ToSchema POSIXTime Source # 
Instance details

Defined in Schema

ToSchema TxId Source # 
Instance details

Defined in Schema

ToSchema Value Source # 
Instance details

Defined in Schema

ToSchema Wallet Source # 
Instance details

Defined in Schema

ToSchema WalletId Source # 
Instance details

Defined in Schema

ToSchema ContractInstanceId Source # 
Instance details

Defined in Schema

ToSchema ThreadToken Source # 
Instance details

Defined in Schema

ToSchema PubKeyHash Source # 
Instance details

Defined in Schema

ToSchema PubKey Source # 
Instance details

Defined in Schema

ToSchema WalletNumber Source # 
Instance details

Defined in Schema

ToSchema StakePubKeyHash Source # 
Instance details

Defined in Schema

ToSchema StakePubKey Source # 
Instance details

Defined in Schema

ToSchema PaymentPubKeyHash Source # 
Instance details

Defined in Schema

ToSchema PaymentPubKey Source # 
Instance details

Defined in Schema

ToSchema POSIXTimeRange Source # 
Instance details

Defined in Schema

ToSchema RedeemerHash Source # 
Instance details

Defined in Schema

ToSchema DatumHash Source # 
Instance details

Defined in Schema

ToSchema ValidatorHash Source # 
Instance details

Defined in Schema

ToSchema TokenName Source # 
Instance details

Defined in Schema

ToSchema CurrencySymbol Source # 
Instance details

Defined in Schema

ToSchema Signature Source # 
Instance details

Defined in Schema

ToSchema Ada Source # 
Instance details

Defined in Schema

ToSchema LedgerBytes Source # 
Instance details

Defined in Schema

ToSchema BuiltinByteString Source # 
Instance details

Defined in Schema

ToSchema Rational Source # 
Instance details

Defined in Schema

ToSchema UUID Source # 
Instance details

Defined in Schema

ToSchema PayToWalletParams Source # 
Instance details

Defined in Playground.Types

ToSchema a => ToSchema [a] Source # 
Instance details

Defined in Schema

ToSchema a => ToSchema (Maybe a) Source # 
Instance details

Defined in Schema

ToSchema (Digest SHA256) Source # 
Instance details

Defined in Schema

ToSchema a => ToSchema (SecretArgument a) Source # 
Instance details

Defined in Schema

(ToSchema a, ToSchema b) => ToSchema (a, b) Source # 
Instance details

Defined in Schema

(ToSchema k, ToSchema v) => ToSchema (Map k v) Source # 
Instance details

Defined in Schema

ToSchema a => ToSchema (Proxy a) Source # 
Instance details

Defined in Schema

(ToSchema k, ToSchema v) => ToSchema (Map k v) Source # 
Instance details

Defined in Schema

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

Instances details
ToArgument Bool Source # 
Instance details

Defined in Schema

ToArgument Int Source # 
Instance details

Defined in Schema

ToArgument Integer Source # 
Instance details

Defined in Schema

ToArgument () Source # 
Instance details

Defined in Schema

ToArgument String Source # 
Instance details

Defined in Schema

ToArgument Text Source # 
Instance details

Defined in Schema

ToArgument Slot Source # 
Instance details

Defined in Schema

ToArgument Value Source # 
Instance details

Defined in Schema

ToArgument Wallet Source # 
Instance details

Defined in Schema

ToArgument WalletId Source # 
Instance details

Defined in Schema

ToArgument WalletNumber Source # 
Instance details

Defined in Schema

ToArgument Ada Source # 
Instance details

Defined in Schema

ToArgument Rational Source # 
Instance details

Defined in Schema

ToArgument PayToWalletParams Source # 
Instance details

Defined in Playground.Types

(ToSchema a, ToArgument a) => ToArgument [a] Source # 
Instance details

Defined in Schema

ToArgument a => ToArgument (SecretArgument a) Source # 
Instance details

Defined in Schema

(ToArgument a, ToArgument b) => ToArgument (a, b) Source # 
Instance details

Defined in Schema

Methods

toArgument :: (a, b) -> Fix FormArgumentF Source #

data FormSchema Source #

Instances

Instances details
Eq FormSchema Source # 
Instance details

Defined in Schema

Show FormSchema Source # 
Instance details

Defined in Schema

Generic FormSchema Source # 
Instance details

Defined in Schema

Associated Types

type Rep FormSchema :: Type -> Type Source #

ToJSON FormSchema Source # 
Instance details

Defined in Schema

FromJSON FormSchema Source # 
Instance details

Defined in Schema

ToSchema FormSchema Source # 
Instance details

Defined in Schema

type Rep FormSchema Source # 
Instance details

Defined in Schema

type Rep FormSchema = D1 ('MetaData "FormSchema" "Schema" "playground-common-0.1.0.0-LHGPmcl6mK723R6a6rRgpE" 'False) (((C1 ('MetaCons "FormSchemaUnit" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "FormSchemaBool" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "FormSchemaInt" 'PrefixI 'False) (U1 :: Type -> Type))) :+: ((C1 ('MetaCons "FormSchemaInteger" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "FormSchemaString" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "FormSchemaHex" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "FormSchemaArray" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 FormSchema))))) :+: ((C1 ('MetaCons "FormSchemaMaybe" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 FormSchema)) :+: (C1 ('MetaCons "FormSchemaRadio" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [String])) :+: C1 ('MetaCons "FormSchemaTuple" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 FormSchema) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 FormSchema)))) :+: ((C1 ('MetaCons "FormSchemaObject" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [(String, FormSchema)])) :+: C1 ('MetaCons "FormSchemaValue" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "FormSchemaPOSIXTimeRange" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "FormSchemaUnsupported" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String))))))

data FormArgumentF a Source #

Instances

Instances details
Functor FormArgumentF Source # 
Instance details

Defined in Schema

Methods

fmap :: (a -> b) -> FormArgumentF a -> FormArgumentF b Source #

(<$) :: a -> FormArgumentF b -> FormArgumentF a Source #

Eq1 FormArgumentF Source # 
Instance details

Defined in Schema

Methods

liftEq :: (a -> b -> Bool) -> FormArgumentF a -> FormArgumentF b -> Bool Source #

Show1 FormArgumentF Source # 
Instance details

Defined in Schema

Methods

liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> FormArgumentF a -> ShowS Source #

liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [FormArgumentF a] -> ShowS Source #

Eq a => Eq (FormArgumentF a) Source # 
Instance details

Defined in Schema

Show a => Show (FormArgumentF a) Source # 
Instance details

Defined in Schema

Generic (FormArgumentF a) Source # 
Instance details

Defined in Schema

Associated Types

type Rep (FormArgumentF a) :: Type -> Type Source #

ToJSON (Fix FormArgumentF) Source # 
Instance details

Defined in Schema

ToJSON a => ToJSON (FormArgumentF a) Source # 
Instance details

Defined in Schema

FromJSON (Fix FormArgumentF) Source # 
Instance details

Defined in Schema

FromJSON a => FromJSON (FormArgumentF a) Source # 
Instance details

Defined in Schema

type Rep (FormArgumentF a) Source # 
Instance details

Defined in Schema

type Rep (FormArgumentF a) = D1 ('MetaData "FormArgumentF" "Schema" "playground-common-0.1.0.0-LHGPmcl6mK723R6a6rRgpE" 'False) (((C1 ('MetaCons "FormUnitF" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "FormBoolF" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool)) :+: C1 ('MetaCons "FormIntF" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Int))))) :+: ((C1 ('MetaCons "FormIntegerF" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Integer))) :+: C1 ('MetaCons "FormStringF" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe String)))) :+: (C1 ('MetaCons "FormHexF" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe String))) :+: C1 ('MetaCons "FormRadioF" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [String]) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe String)))))) :+: ((C1 ('MetaCons "FormArrayF" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 FormSchema) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [a])) :+: (C1 ('MetaCons "FormMaybeF" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 FormSchema) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe a))) :+: C1 ('MetaCons "FormTupleF" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)))) :+: ((C1 ('MetaCons "FormObjectF" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [(String, a)])) :+: C1 ('MetaCons "FormValueF" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Value))) :+: (C1 ('MetaCons "FormPOSIXTimeRangeF" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Interval POSIXTime))) :+: C1 ('MetaCons "FormUnsupportedF" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String))))))