robvandenbogaard / elm-terminusdb / TerminusDb.Schema

This library covers working with Terminus (XSD, OWL) data schemata, such as decoding json responses with schema prefix contexts into validated values.

Values


type Value
    = StringLiteral String
    | IntLiteral Basics.Int
    | TextLiteral TranslatedText
    | Reference Prefix String

Represents a literal or node reference value.


type alias TranslatedText =
Dict String String

A TranslatedText holds a dict with translations per language (keys should be language codes, values the translated text.)

Translated text helpers

translation : String -> String -> TranslatedText

Create a single translation from a language identifier string and text content.

translatedText : Json.Decode.Decoder TranslatedText

Decoder for building a dictionary of translations from the list of @language @value pairs in the value that is being decoded.

addTranslation : String -> String -> TranslatedText -> TranslatedText

Add a translation for a specified language to a translations dictionary.

Decoders

field : Prefix.Context -> Prefix -> String -> Json.Decode.Decoder a -> Json.Decode.Decoder a

Decoder for fields taking the schema prefix context into account.

literal : String -> Json.Decode.Decoder Basics.Bool

Decoder for translating a specific literal string into a boolean value.

value : Prefix.Context -> Prefix -> String -> a -> Json.Decode.Decoder a

Decoder for translating a specific literal string value into a specified instance of a (custom) data type.

Decoding helpers

prefixed : (Prefix.Context -> Json.Decode.Decoder value) -> Json.Decode.Decoder value

Decoder that first decodes the schema prefix context from a response and subsequently applies the provided context dependent decoder.

requireType : Prefix.Context -> Prefix -> String -> Json.Decode.Decoder a -> Json.Decode.Decoder a

Decoder that requires a certain data type to match the type specified in the value that is being decoded.

andMap : Json.Decode.Decoder a -> Json.Decode.Decoder (a -> value) -> Json.Decode.Decoder value

When a document has been partially decoded by a generic document decoder, andMap is used to decode the remaining fields needed to satisfy the specific document type, and apply them to the (partially applied) constructor, as seen in Schema.System.User.decode.