From 07ea48d957cc7b791fdab7b5fbb17241378ce0ed Mon Sep 17 00:00:00 2001 From: Anton Kholomiov Date: Wed, 29 Nov 2023 10:05:22 +0300 Subject: [PATCH] Release v-2.1 --- docs/src/00-foreword.md | 2 +- docs/src/09-reference.md | 46 ++++++++++++++++++++++++++++++++++++- mig-client/mig-client.cabal | 4 ++-- mig-client/package.yaml | 4 ++-- mig-extra/mig-extra.cabal | 6 ++--- mig-extra/package.yaml | 6 ++--- mig-rio/LICENSE | 30 ++++++++++++++++++++++++ mig-rio/mig-rio.cabal | 3 ++- mig-rio/package.yaml | 7 ++---- mig-server/mig-server.cabal | 7 +++--- mig-server/package.yaml | 7 +++--- mig-wai/mig-wai.cabal | 4 ++-- mig-wai/package.yaml | 4 ++-- mig/mig.cabal | 2 +- mig/package.yaml | 2 +- 15 files changed, 104 insertions(+), 30 deletions(-) create mode 100644 mig-rio/LICENSE diff --git a/docs/src/00-foreword.md b/docs/src/00-foreword.md index b68c83d..002a2c0 100644 --- a/docs/src/00-foreword.md +++ b/docs/src/00-foreword.md @@ -10,7 +10,7 @@ The main features of the mig library are: * lightweight library * easy to use. It has simple design on purpose * expressive DSL to compose servers -* type-safe route handlers and conversions +* type-safe route handlers, URLs and conversions * handlers are encoded with generic Haskell functions * built on top of WAI and warp server libraries. * provides Swagger to your server with one-line of code diff --git a/docs/src/09-reference.md b/docs/src/09-reference.md index b936ea8..e679b8c 100644 --- a/docs/src/09-reference.md +++ b/docs/src/09-reference.md @@ -355,7 +355,6 @@ It turns types like: Query "a" Int -> Capture "b" Text -> Get Client (Resp Json Text) ``` - To types: ```haskell @@ -379,6 +378,37 @@ To unwrap `Resp` from response. ## Other utilities +### Type-safe URLs + +The type-level function `UrlOf` creates a type-safe `Url` for a given route handler type. +With class `ToUrl` we can generate the URLs for a collection of handlers. + +```haskell +class ToUrl a where + toUrl :: Server m -> a + mapUrl :: (Url -> Url) -> a -> a + urlArity :: Int +``` + +An example of usage. +URL's should be listed in the same order as they appear in the server + +```haskell +urls :: Urls +urls = Urls{..} + where + greeting + :| blogPost + :| listPosts + toUrl (server undefined) +``` + +We can render `Url` to `String`-like type with function: + +```haskell +renderUrl :: IsString a => Url -> a +``` + ### deriving helpers Sometimes we need to derive too many types at once @@ -418,3 +448,17 @@ deriving instance (ToSchema a) => ToSchema (Timed a) The data type `Timed` has an argument and we have to define the instance explicitly. +### HTML Links + +For usage with template engines that expect JSON as argument for template +there is the type `Link` in the module `Mig.Extra.Html` (also re-exported by all `Html`-related modules): + +```haskell +data Link = Link + { href :: Url + , name :: Text + } + deriving (Generic, ToJSON) +``` + +Also it has `ToMarkup` instance and rendered as `a`-element link. diff --git a/mig-client/mig-client.cabal b/mig-client/mig-client.cabal index afb58eb..4f6cf72 100644 --- a/mig-client/mig-client.cabal +++ b/mig-client/mig-client.cabal @@ -5,7 +5,7 @@ cabal-version: 1.12 -- see: https://github.com/sol/hpack name: mig-client -version: 0.1.0.1 +version: 0.1.1.0 synopsis: Build http-clients from API definition for mig servers description: With this library we can build client functions for HTTP-applications from the same code as server definition. @@ -50,7 +50,7 @@ library , http-client , http-media , http-types - , mig >=0.2.0.1 + , mig >=0.2.1.0 , mtl , text default-language: GHC2021 diff --git a/mig-client/package.yaml b/mig-client/package.yaml index 858751f..5cb2496 100644 --- a/mig-client/package.yaml +++ b/mig-client/package.yaml @@ -1,5 +1,5 @@ name: mig-client -version: 0.1.0.1 +version: 0.1.1.0 github: "anton-k/mig" license: BSD3 author: "Anton Kholomiov" @@ -28,7 +28,7 @@ dependencies: - bytestring - containers - http-api-data -- mig >= 0.2.0.1 +- mig >= 0.2.1.0 - http-client - http-media - mtl diff --git a/mig-extra/mig-extra.cabal b/mig-extra/mig-extra.cabal index 9590683..f76b382 100644 --- a/mig-extra/mig-extra.cabal +++ b/mig-extra/mig-extra.cabal @@ -5,7 +5,7 @@ cabal-version: 1.12 -- see: https://github.com/sol/hpack name: mig-extra -version: 0.1.0.1 +version: 0.1.1.0 synopsis: Extra utils for Mig core library description: Extra utils for mig server library category: Web @@ -62,8 +62,8 @@ library , http-api-data , http-media , http-types - , mig >=0.2.0.1 - , mig-client + , mig >=0.2.1.0 + , mig-client >=0.1.1.0 , openapi3 , template-haskell , text diff --git a/mig-extra/package.yaml b/mig-extra/package.yaml index 27aab74..beef683 100644 --- a/mig-extra/package.yaml +++ b/mig-extra/package.yaml @@ -1,5 +1,5 @@ name: mig-extra -version: 0.1.0.1 +version: 0.1.1.0 github: "anton-k/mig" license: BSD3 author: "Anton Kholomiov" @@ -33,7 +33,7 @@ default-extensions: dependencies: - base >= 4.7 && < 5 - data-default -- mig >= 0.2.0.1 +- mig >= 0.2.1.0 - http-api-data - blaze-html - http-types @@ -48,7 +48,7 @@ dependencies: - bytestring - extra - exceptions -- mig-client +- mig-client >= 0.1.1.0 - template-haskell - transformers diff --git a/mig-rio/LICENSE b/mig-rio/LICENSE new file mode 100644 index 0000000..4173eb7 --- /dev/null +++ b/mig-rio/LICENSE @@ -0,0 +1,30 @@ +Copyright Anton Kholomiov (c) 2023 + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * Neither the name of Author name here nor the names of other + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/mig-rio/mig-rio.cabal b/mig-rio/mig-rio.cabal index 4ac0462..ff954df 100644 --- a/mig-rio/mig-rio.cabal +++ b/mig-rio/mig-rio.cabal @@ -7,7 +7,7 @@ cabal-version: 1.12 name: mig-rio version: 0.1.0.1 synopsis: Utils to use RIO with mig library -description: Utils to use mig with rio library +description: Utils to use RIO with mig library. Provides instance for HasServer class. category: Web homepage: https://github.com/anton-k/mig#readme bug-reports: https://github.com/anton-k/mig/issues @@ -15,6 +15,7 @@ author: Anton Kholomiov maintainer: anton.kholomiov@gmail.com copyright: 2023 Anton Kholomiov license: BSD3 +license-file: LICENSE build-type: Simple extra-source-files: README.md diff --git a/mig-rio/package.yaml b/mig-rio/package.yaml index 42783c0..abacf0d 100644 --- a/mig-rio/package.yaml +++ b/mig-rio/package.yaml @@ -5,19 +5,16 @@ license: BSD3 author: "Anton Kholomiov" maintainer: "anton.kholomiov@gmail.com" copyright: "2023 Anton Kholomiov" +license-file: LICENSE extra-source-files: - README.md # Metadata used when publishing your package synopsis: Utils to use RIO with mig library +description: Utils to use RIO with mig library. Provides instance for HasServer class. category: Web -# To avoid duplicated efforts in documentation and dealing with the -# complications of embedding Haddock markup inside cabal files, it is -# common to point users to the README.md file. -description: Utils to use mig with rio library - language: GHC2021 default-extensions: diff --git a/mig-server/mig-server.cabal b/mig-server/mig-server.cabal index 6bd36b1..22908a4 100644 --- a/mig-server/mig-server.cabal +++ b/mig-server/mig-server.cabal @@ -5,7 +5,7 @@ cabal-version: 1.12 -- see: https://github.com/sol/hpack name: mig-server -version: 0.1.0.1 +version: 0.2.1.0 synopsis: Build lightweight and composable servers description: With library mig we can build lightweight and composable servers. There are only couple of combinators to assemble servers from parts. @@ -27,6 +27,7 @@ description: With library mig we can build lightweight and composable ser . Example of hello world server: . + > {-# Language OverloadedStrings #-} > import Mig.Json.IO > > -- | We can render the server and run it on port 8085. @@ -103,8 +104,8 @@ library , data-default , http-api-data , http-types - , mig >=0.2.0.1 - , mig-extra >=0.1.0.1 + , mig >=0.2.1.0 + , mig-extra >=0.1.1.0 , mig-swagger-ui >=0.1 , mig-wai >=0.1.0.1 , openapi3 diff --git a/mig-server/package.yaml b/mig-server/package.yaml index 0806d0d..0ee114b 100644 --- a/mig-server/package.yaml +++ b/mig-server/package.yaml @@ -1,5 +1,5 @@ name: mig-server -version: 0.1.0.1 +version: 0.2.1.0 github: "anton-k/mig" license: BSD3 author: "Anton Kholomiov" @@ -38,6 +38,7 @@ description: | . Example of hello world server: . + > {-# Language OverloadedStrings #-} > import Mig.Json.IO > > -- | We can render the server and run it on port 8085. @@ -84,8 +85,8 @@ default-extensions: dependencies: - aeson - base >= 4.7 && < 5 -- mig >= 0.2.0.1 -- mig-extra >= 0.1.0.1 +- mig >= 0.2.1.0 +- mig-extra >= 0.1.1.0 - mig-wai >= 0.1.0.1 - http-types - text diff --git a/mig-wai/mig-wai.cabal b/mig-wai/mig-wai.cabal index 785ec39..100cee5 100644 --- a/mig-wai/mig-wai.cabal +++ b/mig-wai/mig-wai.cabal @@ -5,7 +5,7 @@ cabal-version: 1.12 -- see: https://github.com/sol/hpack name: mig-wai -version: 0.1.0.1 +version: 0.1.1.0 synopsis: Render mig-servers as wai-applications description: Library to render mig-servers as WAI-applications. category: Web @@ -43,7 +43,7 @@ library , containers , data-default , exceptions - , mig >=0.2.0.1 + , mig >=0.2.1.0 , text , wai default-language: GHC2021 diff --git a/mig-wai/package.yaml b/mig-wai/package.yaml index 29739e7..c09c899 100644 --- a/mig-wai/package.yaml +++ b/mig-wai/package.yaml @@ -1,5 +1,5 @@ name: mig-wai -version: 0.1.0.1 +version: 0.1.1.0 github: "anton-k/mig" license: BSD3 author: "Anton Kholomiov" @@ -31,7 +31,7 @@ dependencies: - base >= 4.7 && < 5 - bytestring - containers -- mig >= 0.2.0.1 +- mig >= 0.2.1.0 - text - wai - exceptions diff --git a/mig/mig.cabal b/mig/mig.cabal index d2a4e62..0e2a294 100644 --- a/mig/mig.cabal +++ b/mig/mig.cabal @@ -5,7 +5,7 @@ cabal-version: 1.12 -- see: https://github.com/sol/hpack name: mig -version: 0.2.0.1 +version: 0.2.1.0 synopsis: Build lightweight and composable servers description: The Core for the mig server library. With library mig we can build lightweight and composable servers. diff --git a/mig/package.yaml b/mig/package.yaml index e2a5f06..65b8a8b 100644 --- a/mig/package.yaml +++ b/mig/package.yaml @@ -1,5 +1,5 @@ name: mig -version: 0.2.0.1 +version: 0.2.1.0 github: "anton-k/mig" license: BSD3 author: "Anton Kholomiov"