jamesrweb/elm-cqrs/5.0.2

NOTE: the latest version is 5.0.3

Cqrs.Command

{ headers : List Header
, timeout : Maybe Float
, tracker : Maybe String
, risky : Bool
}

Configuration for requests resulting in a Cmd

{ headers : List Header
, timeout : Maybe Float
, risky : Bool
}

Configuration for requests resulting in a Task

type alias RequestSettings error msg =
{ body : Value
, defaultError : error
, toError : Decoder error
, toMsg : CommandResponse error -> msg
, url : String
}

Configuration settings for a Cqrs.Command.request

type alias RequestWithConfigurationSettings error msg =
{ body : Value
, config : StandardRequestConfiguration
, defaultError : error
, toError : Decoder error
, toMsg : CommandResponse error -> msg
, url : String
}

Configuration settings for a Cqrs.Command.requestWithConfig

type alias RequestTaskSettings error =
{ body : Value
, defaultError : error
, toError : Decoder error
, url : String
}

Configuration settings for a Cqrs.Command.requestTask

{ body : Value
, config : TaskRequestConfiguration
, defaultError : error
, toError : Decoder error
, url : String
}

Configuration settings for a Cqrs.Command.requestTaskWithConfig

type CommandRequest error msg
= Request (RequestSettings error msg)
| RequestWithConfig (RequestWithConfigurationSettings error msg)
| Task (RequestTaskSettings error)
| TaskWithConfig (RequestTaskWithConfigurationSettings error)

Represents the possible types of query which can be executed depending on your needs.

type CommandResponse error

Represents the possible states of a command.

HTTP

request : RequestSettings error msg -> Cmd msg

Sends a command to the given URL with the provided body and returns a parsed Cqrs.Command.CommandResponse error in turn.

requestWithConfiguration : RequestWithConfigurationSettings error msg -> Cmd msg

Similar to request but a StandardRequestConfig can be passed in for cases where customisation of the request headers, etc are desired.

requestTask : RequestTaskSettings error -> Task () (CommandResponse error)

Sends a command to the given URL and returns a Task containing the parsed Cqrs.Command.CommandResponse error. The value contained within the Cqrs.Command.CommandResponse error, will be the value parsed via the provided decoder.

RequestTaskWithConfigurationSettings error
-> Task () (CommandResponse error)

Similar to requestTask but a TaskRequestConfig can be passed in for cases where customisation of the request headers, etc are desired.

Constructors

Constructs the Succeeded variant of a Cqrs.Command.CommandResponse error.

This is useful for testing how your UI will respond to the happy path, without actually sending a command.

fail : error -> CommandResponse error

Constructs the Failed variant of a Cqrs.Command.CommandResponse error.

This is useful for testing how your UI will respond to the sad path, without actually sending a command.

fromResult : Result error data -> CommandResponse error

Converts a Result error data to a Cqrs.Command.CommandResponse error

fromRemoteData : error -> WebData (CommandResponse error) -> CommandResponse error

Converts a given WebData (CommandResponse error) into a Cqrs.Command.CommandResponse error.

State

reason : CommandResponse error -> Maybe error

If a given Cqrs.Command.CommandResponse error was unsuccessful, the reason for the failure will be returned.

reason Succeeded --> Nothing


reason (Failed "reason") --> Just "reason"

Mappers

(error -> nextError)
-> CommandResponse error
-> CommandResponse nextError

Maps the Failed variant of a given Cqrs.Command.CommandResponse error.

unwrap : value -> (() -> value) -> CommandResponse error -> value

Convert a CommandResponse error to a value by applying a function if the CommandResponse error is a Succeeded variant or using the provided default value if it is an Failed variant.

unpack : (error -> value) -> (() -> value) -> CommandResponse error -> value

Convert a CommandResponse error to a value by applying either the first function if the CommandResponse error is an Failed variant or the second function if the CommandResponse error is a Succeeded variant.

partition : List (CommandResponse error) -> ( List (), List error )

Partitions a series of CommandResponse error instances into a tuple of successful and unsuccessful responses.

toResult : CommandResponse error -> Result error ()

Converts a Cqrs.Command.CommandResponse error to a Result error data

toMaybe : CommandResponse error -> Maybe ()

Converts a Cqrs.Command.CommandResponse error to a Maybe ()

Helpers

succeeded : CommandResponse error -> Bool

Checks if a given Cqrs.Command.CommandResponse error is a Succeeded variant.

succeeded Succeeded --> True


succeeded (Failed "reason") --> False
failed : CommandResponse error -> Bool

Checks if a given Cqrs.Command.CommandResponse error is a Failed variant.

failed Succeeded --> False


failed (Failed "reason") --> True

Codec

decoder : Decoder error -> Decoder (CommandResponse error)

Decodes a given payload into a Cqrs.Command.CommandResponse error.