packages feed

servant-hateoas 0.2.1 → 0.2.2

raw patch · 7 files changed

+18/−23 lines, 7 filesdep +constrained-somePVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependencies added: constrained-some

API changes (from Hackage documentation)

- Servant.Hateoas.Some: [SomeToJSON] :: ToJSON a => a -> SomeToJSON f
- Servant.Hateoas.Some: data SomeToJSON f
- Servant.Hateoas.Some: instance forall k (f :: k). Data.Aeson.Types.ToJSON.ToJSON (Servant.Hateoas.Some.SomeToJSON f)
- Servant.Hateoas.ContentType.HAL: HALResource :: a -> [(String, Link)] -> [(String, SomeToJSON HALResource)] -> HALResource a
+ Servant.Hateoas.ContentType.HAL: HALResource :: a -> [(String, Link)] -> [(String, SomeF HALResource ToJSON)] -> HALResource a
- Servant.Hateoas.ContentType.HAL: [embedded] :: HALResource a -> [(String, SomeToJSON HALResource)]
+ Servant.Hateoas.ContentType.HAL: [embedded] :: HALResource a -> [(String, SomeF HALResource ToJSON)]
- Servant.Hateoas.Resource: embed :: (EmbeddingResource res, ToJSON b) => (String, b) -> res a -> res a
+ Servant.Hateoas.Resource: embed :: (EmbeddingResource res, ToJSON e) => (String, e) -> res a -> res a

Files

CHANGELOG.md view
@@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [PVP versioning](https://pvp.haskell.org/). +## v0.2.2 _(2024-12-01)_++### Changed+- Removed `SomeToJSON` and replaced it with `SomeF f ToJSON` from `constrained-some`+ ## v0.2.1 _(2024-10-25)_  ### Changed
README.md view
@@ -66,13 +66,14 @@  ## Goals - [x] Deriving simple links for self and relations-- [ ] Deriving links for paging, ...+- [ ] Deriving more complex links...? - [ ] Type-level rewriting of APIs like `CompleteAPI` to make API HATEOAS-compliant  ## Media-Types - [x] `application/hal+json` - [x] `application/collection+json`-- [ ] Others: Easily extensible+- [ ] `application/hal-forms+json` soon+- [ ] Others: Maybe  Client usage with `MimeUnrender` is not yet supported. 
servant-hateoas.cabal view
@@ -1,10 +1,10 @@ cabal-version:           3.0 name:                    servant-hateoas-version:                 0.2.1+version:                 0.2.2 synopsis:                HATEOAS extension for servant description:             Create Resource-Representations for your types and make your API HATEOAS-compliant.-  Resource construction is generic where possible and manually adjustable where required.-  Currently HAL+JSON is the only supported Content-Type, work for more is in progress.+  Automatically derive hypermedia-links where possible.+  Currently HAL+JSON and Collection+JSON are the only supported Content-Types.   The ultimate goal is to generate an entirely HATEOAS-compliant API generically. homepage:                https://github.com/bruderj15/servant-hateoas bug-reports:             https://github.com/bruderj15/servant-hateoas/issues@@ -20,6 +20,7 @@ tested-with:             GHC == 9.4.8                        , GHC == 9.6.4                        , GHC == 9.8.2+                       , GHC == 9.10.1  common warnings     ghc-options:        -Wall@@ -28,7 +29,6 @@     import:              warnings      exposed-modules:     Servant.Hateoas-                       , Servant.Hateoas.Some                        , Servant.Hateoas.Resource                        , Servant.Hateoas.ContentType.HAL                        , Servant.Hateoas.ContentType.Collection@@ -40,6 +40,7 @@                        , http-media                    >= 0.8.1  && < 0.9                        , servant                       >= 0.20.2 && < 0.21                        , servant-server                >= 0.20.2 && < 0.21+                       , constrained-some              >= 0.1.0  && < 0.2     hs-source-dirs:      src     default-language:    GHC2021     default-extensions:  DataKinds, TypeFamilies
src/Servant/Hateoas.hs view
@@ -2,10 +2,8 @@ ( module Servant.Hateoas.ContentType.Collection , module Servant.Hateoas.ContentType.HAL , module Servant.Hateoas.Resource-, module Servant.Hateoas.Some ) where  import Servant.Hateoas.ContentType.Collection (Collection, CollectionResource) import Servant.Hateoas.ContentType.HAL (HAL, HALResource) import Servant.Hateoas.Resource-import Servant.Hateoas.Some
src/Servant/Hateoas/ContentType/HAL.hs view
@@ -9,11 +9,11 @@ where  import Servant.Hateoas.Resource-import Servant.Hateoas.Some import Servant.API.ContentTypes import qualified Network.HTTP.Media as M import Servant.Links import qualified Data.Foldable as Foldable+import Data.Some.Constraint import Data.Kind import Data.Proxy import Data.Aeson@@ -32,7 +32,7 @@ data HALResource a = HALResource   { resource :: a                                       -- ^ Wrapped resource   , links    :: [(String, Link)]                        -- ^ Pairs @(rel, link)@ for relations-  , embedded :: [(String, SomeToJSON HALResource)]      -- ^ Pairs @(rel, resource)@ for embedded resources+  , embedded :: [(String, SomeF HALResource ToJSON)]    -- ^ Pairs @(rel, resource)@ for embedded resources   } deriving (Generic)  instance Resource HALResource where@@ -50,7 +50,7 @@     v -> v     where       ls' = object [fromString rel .= object ["href" .= linkURI href] | (rel, href) <- ls]-      es' = object [fromString name .= toJSON e | (name, e) <- es]+      es' = object [fromString name .= toJSON e | (name, (Some1 e)) <- es]  instance {-# OVERLAPPING #-} (ToJSON a, Related a, KnownSymbol (CollectionName a)) => ToJSON [HALResource a] where   toJSON xs = object ["_links" .= (mempty :: Object), "_embedded" .= es]@@ -61,7 +61,7 @@         ]  instance EmbeddingResource HALResource where-  embed e (HALResource r ls es) = HALResource r ls $ fmap SomeToJSON e : es+  embed e (HALResource r ls es) = HALResource r ls $ fmap (\res -> Some1 $ HALResource res [] []) e : es  instance {-# OVERLAPPABLE #-}   ( Related a, HasField (IdSelName a) a id, IsElem (GetOneApi a) api
src/Servant/Hateoas/Resource.hs view
@@ -38,7 +38,7 @@ -- | Class for 'Resource's that can embed other resources. class Resource res => EmbeddingResource res where   -- | Embed a resource @b@ with its relation @rel@ as tuple @(rel, b)@.-  embed :: ToJSON b => (String, b) -> res a -> res a+  embed :: ToJSON e => (String, e) -> res a -> res a  -- | Class for 'Resource's that can collect multiple resources. class Resource res => CollectingResource res where
− src/Servant/Hateoas/Some.hs
@@ -1,10 +0,0 @@-module Servant.Hateoas.Some where--import Data.Aeson---- | Existential for types that can be converted 'ToJSON'.-data SomeToJSON f where-  SomeToJSON :: ToJSON a => a -> SomeToJSON f--instance ToJSON (SomeToJSON f) where-  toJSON (SomeToJSON x) = toJSON x