Complete documentation

json-extra
Bram 2024-01-22 18:09:08 +01:00
parent dd5f298fd3
commit acd13ac67a
9 changed files with 33 additions and 8 deletions

View File

@ -190,10 +190,9 @@ failures =
} }
{-| Objects contain multiple fields. These fields are here described, explaining
-- TODO what they do and what they are for.
-}
fields : fields :
{ context : { context :
{ accessToken : Desc { accessToken : Desc
@ -270,11 +269,17 @@ fields =
} }
{-| This message will be shown when a [Hashdict](Internal-Tools-Hashdict)
encounters a hash-value pair where the value does not hash to the provided hash.
-}
invalidHashInHashdict : String invalidHashInHashdict : String
invalidHashInHashdict = invalidHashInHashdict =
"Invalid hash function: not all elements hash to their JSON-stored hashes" "Invalid hash function: not all elements hash to their JSON-stored hashes"
{-| This message will be shown when a [Mashdict](Internal-Tools-Mashdict)
encounters a hash-value pair where the value does not hash to the provided hash.
-}
invalidHashInMashdict : String invalidHashInMashdict : String
invalidHashInMashdict = invalidHashInMashdict =
"Invalid hash function: not all elements hash to their JSON-stored hashes" "Invalid hash function: not all elements hash to their JSON-stored hashes"

View File

@ -81,6 +81,8 @@ type Hashdict a
} }
{-| Define how Hashdict can be encoded to and decoded from a JSON object.
-}
coder : (a -> String) -> Json.Coder a -> Json.Coder (Hashdict a) coder : (a -> String) -> Json.Coder a -> Json.Coder (Hashdict a)
coder f c1 = coder f c1 =
Json.andThen Json.andThen

View File

@ -1,12 +1,11 @@
module Internal.Tools.Json exposing module Internal.Tools.Json exposing
( Coder, string, bool, int, float, value ( Coder, string, bool, int, float, value
, Encoder, encode, Decoder, decode, Value , Encoder, encode, Decoder, decode, Value
, succeed, fail, andThen, lazy , succeed, fail, andThen, lazy, map
, Docs(..), RequiredField(..), toDocs , Docs(..), RequiredField(..), toDocs
, list, slowDict, fastDict, maybe , list, slowDict, fastDict, maybe
, Field, field , Field, field
, object2, object3, object4, object5, object6, object7, object8, object9, object10, object11 , object2, object3, object4, object5, object6, object7, object8, object9, object10, object11
, map
) )
{-| {-|
@ -40,7 +39,7 @@ module to build its encoders and decoders.
## Optional coding ## Optional coding
@docs succeed, fail, andThen, lazy @docs succeed, fail, andThen, lazy, map
## Documentation ## Documentation
@ -176,6 +175,8 @@ type RequiredField
| OptionalFieldWithDefault String | OptionalFieldWithDefault String
{-| Represents an arbitary JavaScript value.
-}
type alias Value = type alias Value =
E.Value E.Value
@ -424,6 +425,8 @@ int =
} }
{-| Define a lazy coder. This is useful when defining recursive structures.
-}
lazy : (() -> Coder value) -> Coder value lazy : (() -> Coder value) -> Coder value
lazy f = lazy f =
Coder Coder
@ -1144,6 +1147,9 @@ toEncodeField (Field data) =
( data.fieldName, data.toField >> data.encoder ) ( data.fieldName, data.toField >> data.encoder )
{-| Do not do anything useful with a JSON value, just bring it to Elm as a
JavaScript value.
-}
value : Coder Value value : Coder Value
value = value =
Coder Coder

View File

@ -93,6 +93,8 @@ type Mashdict a
} }
{-| Define how a Mashdict can be encoded to and decoded from a JSON object.
-}
coder : (a -> Maybe String) -> Json.Coder a -> Json.Coder (Mashdict a) coder : (a -> Maybe String) -> Json.Coder a -> Json.Coder (Mashdict a)
coder f c1 = coder f c1 =
Json.andThen Json.andThen

View File

@ -95,6 +95,8 @@ apiFormat context =
} }
{-| Define how a Context can be encoded to and decoded from a JSON object.
-}
coder : Json.Coder Context coder : Json.Coder Context
coder = coder =
Json.object7 Json.object7

View File

@ -4,7 +4,7 @@ module Internal.Values.Envelope exposing
, Settings, mapSettings, extractSettings , Settings, mapSettings, extractSettings
, mapContext , mapContext
, getContent, extract , getContent, extract
, encode, decoder , coder, encode, decoder
) )
{-| The Envelope module wraps existing data types with lots of values and {-| The Envelope module wraps existing data types with lots of values and
@ -68,6 +68,8 @@ type alias Settings =
Settings.Settings Settings.Settings
{-| Define how an Envelope can be encoded to and decoded from a JSON object.
-}
coder : Json.Coder a -> Json.Coder (Envelope a) coder : Json.Coder a -> Json.Coder (Envelope a)
coder c1 = coder c1 =
Json.object3 Json.object3

View File

@ -64,6 +64,8 @@ age event =
Maybe.andThen (\(UnsignedData data) -> data.age) event.unsigned Maybe.andThen (\(UnsignedData data) -> data.age) event.unsigned
{-| Define how an Event can be encoded to and decoded from a JSON object.
-}
coder : Json.Coder Event coder : Json.Coder Event
coder = coder =
Json.object8 Json.object8

View File

@ -39,6 +39,8 @@ type alias Settings =
} }
{-| Define how a Settings type can be encoded to and decoded from a JSON object.
-}
coder : Json.Coder Settings coder : Json.Coder Settings
coder = coder =
Json.object3 Json.object3

View File

@ -93,6 +93,8 @@ cleanKey key (StateManager manager) =
|> StateManager |> StateManager
{-| Define how a StateManager can be encoded to and decoded from a JSON object.
-}
coder : Json.Coder StateManager coder : Json.Coder StateManager
coder = coder =
Event.coder Event.coder