keiro-dsl-0.10.0.0: test/conformance-skeletons/SkelAggregate/Generated/MyService/Nominals/Internal.hs
-- @generated by keiro-dsl 0.9.0.0 (language keiro-dsl 4) from context my-service generated nominal ID internals; do not edit.
module SkelAggregate.Generated.MyService.Nominals.Internal
( ThingId
, parseThingId
, mkThingId
, thingIdText
, unsafeThingIdFromLegacyText
) where
import Data.Aeson (FromJSON (..), ToJSON (..), withText)
import Data.Text (Text)
import Data.Text qualified as T
import GHC.Generics (Generic)
import Keiro.Codec.IdDomain (typeIdV7Domain, validateIdDomainText)
newtype ThingId = ThingId Text
deriving stock (Generic, Eq, Ord, Show)
instance ToJSON ThingId where
toJSON = toJSON . thingIdText
instance FromJSON ThingId where
parseJSON = withText "ThingId" (either (fail . T.unpack) pure . parseThingId)
parseThingId :: Text -> Either Text ThingId
parseThingId input = case validateIdDomainText (typeIdV7Domain "thing") input of
Left reason -> Left (T.pack (show reason))
Right () -> Right (ThingId input)
mkThingId :: Text -> Either Text ThingId
mkThingId = parseThingId
thingIdText :: ThingId -> Text
thingIdText (ThingId value) = value
unsafeThingIdFromLegacyText :: Text -> ThingId
unsafeThingIdFromLegacyText = ThingId