| License | Apache-2.0 |
|---|---|
| Safe Haskell | None |
| Language | GHC2021 |
Singular.Registry.PlainJson
Description
A payload is Plutus data. The detailed schema (datumFromJson) writes
any datum exactly and is how the previous release read every payload
file. The plain mapping lets a file hold ordinary JSON instead, mapped to
data by a table (#719):
- a whole number of at most
plainDigitLimitdigits is the integer; - a text is the byte string of its UTF-8;
trueandfalseare the constructors 1 and 0 without fields;- an array is the list of its items;
- an object is the map from each key, as a byte string of its UTF-8, to its value, entries in ascending order of the key bytes;
nulland a number with a fraction are refused.
plainFromData is the reading in the other direction: it returns the
JSON the table started from, and nothing for data the table could not
have produced. payloadView chooses what a command prints: the plain
JSON when there is one, else the detailed schema, with the schema named.
Nothing here reads a file or names a command. The one place that reads a
payload file for a command is Singular.CLI.Payload.
Synopsis
- data PayloadSchema
- schemaName :: PayloadSchema -> Text
- parseSchemaName :: Text -> Maybe PayloadSchema
- plainDigitLimit :: Int
- plainToData :: Value -> Either PlainRefusal Data
- plainFromData :: Data -> Maybe Value
- data PlainRefusal = PlainRefusal {}
- data PlainReason
- = HasFraction Scientific
- | TooLarge Scientific
- | IsNull
- data PathStep
- renderPlainRefusal :: PlainRefusal -> Text
- payloadFromJson :: PayloadSchema -> Value -> Either Text Data
- data PayloadView = PayloadView {
- viewSchema :: PayloadSchema
- viewJson :: Value
- payloadView :: Data -> PayloadView
The schema setting
data PayloadSchema Source #
Which form a payload file is written in.
Constructors
| PlainSchema | Plain JSON, mapped by the table |
| DetailedSchema | The detailed Plutus data schema |
Instances
| Show PayloadSchema Source # | |
Defined in Singular.Registry.PlainJson Methods showsPrec :: Int -> PayloadSchema -> ShowS Source # show :: PayloadSchema -> String Source # showList :: [PayloadSchema] -> ShowS Source # | |
| Eq PayloadSchema Source # | |
Defined in Singular.Registry.PlainJson Methods (==) :: PayloadSchema -> PayloadSchema -> Bool Source # (/=) :: PayloadSchema -> PayloadSchema -> Bool Source # | |
schemaName :: PayloadSchema -> Text Source #
The lower-case name of a schema, as the flag spells it.
parseSchemaName :: Text -> Maybe PayloadSchema Source #
The schema a flag value names: exactly the two names, in lower case.
The plain mapping and its reading
plainDigitLimit :: Int Source #
The most digits a stored whole number may have.
plainToData :: Value -> Either PlainRefusal Data Source #
The data a plain JSON document stands for, or the first value refused: objects are walked in ascending order of the key bytes and arrays in order, so the refusal is a function of the document.
plainFromData :: Data -> Maybe Value Source #
The plain JSON a datum stands for, when it has one: an integer of at
most plainDigitLimit digits, a byte string that is UTF-8, a list of
items that have one, a map whose keys are UTF-8 byte strings in strictly
ascending order of bytes and whose values have one, and the constructors 0
and 1 without fields.
Refusals
data PlainRefusal Source #
A value the plain mapping refuses, and where it is.
Constructors
| PlainRefusal | |
Fields
| |
Instances
| Show PlainRefusal Source # | |
Defined in Singular.Registry.PlainJson Methods showsPrec :: Int -> PlainRefusal -> ShowS Source # show :: PlainRefusal -> String Source # showList :: [PlainRefusal] -> ShowS Source # | |
| Eq PlainRefusal Source # | |
Defined in Singular.Registry.PlainJson Methods (==) :: PlainRefusal -> PlainRefusal -> Bool Source # (/=) :: PlainRefusal -> PlainRefusal -> Bool Source # | |
data PlainReason Source #
Why a value has no Plutus data counterpart.
Constructors
| HasFraction Scientific | A number with a fraction |
| TooLarge Scientific | A whole number with more digits than the limit |
| IsNull | null |
Instances
| Show PlainReason Source # | |
Defined in Singular.Registry.PlainJson Methods showsPrec :: Int -> PlainReason -> ShowS Source # show :: PlainReason -> String Source # showList :: [PlainReason] -> ShowS Source # | |
| Eq PlainReason Source # | |
Defined in Singular.Registry.PlainJson Methods (==) :: PlainReason -> PlainReason -> Bool Source # (/=) :: PlainReason -> PlainReason -> Bool Source # | |
One step from the document to the offending value.
Instances
| Show PathStep Source # | |
Defined in Singular.Registry.PlainJson | |
| Eq PathStep Source # | |
Defined in Singular.Registry.PlainJson | |
renderPlainRefusal :: PlainRefusal -> Text Source #
The sentence naming the value and its path, written as a path from
the document: $ is the whole document, .name an object key, [2] an
item.
A payload document under a schema
payloadFromJson :: PayloadSchema -> Value -> Either Text Data Source #
A payload document read under a schema. The detailed schema is the reader of the previous release, refusals unchanged. The plain schema refuses a whole document that the detailed schema accepts, with the instruction to say so, and only then maps.
What a command prints
data PayloadView Source #
What a command prints of a payload: the schema and the JSON in it.
Constructors
| PayloadView | |
Fields
| |
Instances
| Show PayloadView Source # | |
Defined in Singular.Registry.PlainJson Methods showsPrec :: Int -> PayloadView -> ShowS Source # show :: PayloadView -> String Source # showList :: [PayloadView] -> ShowS Source # | |
| Eq PayloadView Source # | |
Defined in Singular.Registry.PlainJson Methods (==) :: PayloadView -> PayloadView -> Bool Source # (/=) :: PayloadView -> PayloadView -> Bool Source # | |
payloadView :: Data -> PayloadView Source #
The plain reading when the data has one, else the detailed schema of
the data. Plain exactly when plainFromData returns the JSON.