keiro-dsl-0.18.0.0: test/conformance-bare-containers/Generated/BareContainers/BareJobs/Queue.hs
-- @generated by keiro-dsl 0.18.0.0 (language keiro-dsl 6) from workqueue bare_jobs; do not edit.
module Generated.BareContainers.BareJobs.Queue
( BareJob (..)
, encodeBareJob
, parseBareJob
, encodeMaybeTextMapped
, decodeMaybeTextMapped
, encodeTextListMapped
, decodeTextListMapped
, queuePhysical, queueDlq, queueTable
) where
import Data.Aeson (Value (..), object, parseJSON, toJSON, withObject, (.=))
import Data.Aeson.Types (Parser, JSONPathElement (..), (<?>), explicitParseField, parseEither)
import Data.Text (Text)
import qualified Data.Text as T
import Keiro.Codec.Structural (bindingFromShape, bindingToShape)
import Conformance.BareContainers.Bindings qualified as Bindings
import Conformance.BareContainers.Domain (MaybeText, TextList)
import Generated.BareContainers.Structural.Shape.MaybeText qualified as ShapeMaybeText
import Generated.BareContainers.Structural.Shape.TextList qualified as ShapeTextList
queuePhysical, queueDlq, queueTable :: Text
queuePhysical = "bare_jobs"
queueDlq = "bare_jobs_dlq"
queueTable = "pgmq.q_bare_jobs"
data BareJob = BareJob
{ optionalLabel :: !MaybeText
, labels :: !TextList
}
deriving stock (Eq, Show)
encodeMaybeTextMapped :: MaybeText -> Value
encodeMaybeTextMapped = encodeMaybeTextShape . bindingToShape Bindings.maybeTextBinding
parseMaybeTextMapped :: Value -> Parser MaybeText
parseMaybeTextMapped value = bindingFromShape Bindings.maybeTextBinding <$> parseMaybeTextShape value
decodeMaybeTextMapped :: Value -> Either Text MaybeText
decodeMaybeTextMapped = mapLeftText . parseEither parseMaybeTextMapped
encodeMaybeTextShape :: ShapeMaybeText.MaybeTextShape -> Value
encodeMaybeTextShape value = maybe Null (\item0 -> toJSON (item0)) (value)
parseMaybeTextShape :: Value -> Parser ShapeMaybeText.MaybeTextShape
parseMaybeTextShape = \value0 -> case value0 of Null -> pure Nothing; other0 -> Just <$> (parseJSON) other0
encodeTextListMapped :: TextList -> Value
encodeTextListMapped = encodeTextListShape . bindingToShape Bindings.textListBinding
parseTextListMapped :: Value -> Parser TextList
parseTextListMapped value = bindingFromShape Bindings.textListBinding <$> parseTextListShape value
decodeTextListMapped :: Value -> Either Text TextList
decodeTextListMapped = mapLeftText . parseEither parseTextListMapped
encodeTextListShape :: ShapeTextList.TextListShape -> Value
encodeTextListShape value = toJSON (map (\item0 -> toJSON (item0)) (value))
parseTextListShape :: Value -> Parser ShapeTextList.TextListShape
parseTextListShape = \value0 -> do items0 <- (parseJSON value0 :: Parser [Value]); traverse (\(index0, item0) -> (parseJSON) item0 <?> Index index0) (zip [0..] items0)
encodeBareJob :: BareJob -> Value
encodeBareJob payload =
object
[ "optional_label" .= encodeMaybeTextMapped payload.optionalLabel
, "labels" .= encodeTextListMapped payload.labels
]
parseBareJob :: Value -> Either Text BareJob
parseBareJob = mapLeftText . parseEither (withObject "BareJob" go)
where
go objectValue = BareJob <$> explicitParseField (parseMaybeTextMapped) objectValue "optional_label" <*> explicitParseField (parseTextListMapped) objectValue "labels"
mapLeftText :: Either String b -> Either Text b
mapLeftText = either (Left . T.pack) Right