packages feed

rest-gen 0.9.0.7 → 0.10

raw patch · 5 files changed

+55/−28 lines, 5 filesdep ~rest-corePVP ok

version bump matches the API change (PVP)

Dependency ranges changed: rest-core

API changes (from Hackage documentation)

+ Rest.Gen.Base.ActionInfo: DeleteMany :: ActionType
+ Rest.Gen.Base.ActionInfo: multiRemoveActionInfo :: Monad m => Id sid -> String -> Handler m -> Maybe ActionInfo

Files

+ CHANGELOG.md view
@@ -0,0 +1,8 @@+# Changelog++## 0.10++* Generate documentation, Javascript and Haskell code for multi-delete+  handlers. The name of the generated functions is `removeMany` or+  `removeManyBy<id>`.+* Escape reserved names in Haskell code generation.
rest-gen.cabal view
@@ -1,19 +1,20 @@-Name:             rest-gen-Version:          0.9.0.7-Description:      Documentation and client generation from rest definition.-Synopsis:         Documentation and client generation from rest definition.-Maintainer:       code@silk.co-Category:         Web-Build-Type:       Simple-Cabal-Version:    >= 1.8-License:          BSD3-License-File:     LICENSE-Data-Dir:         files-Data-Files:       Docs/*.st-                  Docs/*.js-                  Docs/*.css-                  Javascript/base.js-                  Ruby/base.rb+Name:               rest-gen+Version:            0.10+Description:        Documentation and client generation from rest definition.+Synopsis:           Documentation and client generation from rest definition.+Maintainer:         code@silk.co+Category:           Web+Build-Type:         Simple+Cabal-Version:      >= 1.8+License:            BSD3+License-File:       LICENSE+Data-Dir:           files+Data-Files:         Docs/*.st+                    Docs/*.js+                    Docs/*.css+                    Javascript/base.js+                    Ruby/base.rb+Extra-Source-Files: CHANGELOG.md  Library   GHC-Options:     -Wall@@ -43,7 +44,7 @@     , pretty                    >= 1.0     &&  < 1.2     , process                   >= 1.0     &&  < 1.3     , regular                   == 0.3.*-    , rest-core                 == 0.28.*+    , rest-core                 == 0.29.*     , rest-types                == 1.9.*     , safe                      >= 0.2     &&  < 0.4     , split                     >= 0.1     &&  < 0.3@@ -75,7 +76,7 @@ Test-suite rest-gen-tests   build-depends:       base                 >= 4.5    && < 4.8                      , HUnit                == 1.2.*-                     , rest-core            == 0.28.*+                     , rest-core            == 0.29.*                      , rest-gen                      , test-framework       == 0.8.*                      , test-framework-hunit == 0.3.*
src/Rest/Gen/Base/ActionInfo.hs view
@@ -22,7 +22,7 @@ import qualified Rest.Gen.Base.XML  as X  import Rest.Dictionary (Param (..), Input (..), Output (..), Error (..))-import Rest.Driver.Routing (mkListHandler, mkMultiPutHandler)+import Rest.Driver.Routing (mkListHandler, mkMultiHandler) import Rest.Handler import Rest.Resource import Rest.Schema@@ -39,7 +39,7 @@ -- | Intermediate data representation of Rest structure data RequestMethod = GET | POST | PUT | DELETE deriving (Show, Eq) -data ActionType = Retrieve | Create | Delete | List | Update | UpdateMany | Modify+data ActionType = Retrieve | Create | Delete | DeleteMany | List | Update | UpdateMany | Modify   deriving (Show, Eq)  data ActionTarget = Self | Any deriving (Show, Eq)@@ -135,6 +135,7 @@    = foldMap (return . getActionInfo         mId pth) (Rest.get     r)   ++ foldMap (return . updateActionInfo      mId pth) (Rest.update  r)   ++ maybeToList (join $ multiUpdateActionInfo <$> mId <*> pure pth <*> Rest.update r)+  ++ maybeToList (join $ multiRemoveActionInfo <$> mId <*> pure pth <*> Rest.remove r)  -------------------- -- * Smart constructors for ActionInfo.@@ -147,11 +148,15 @@  multiUpdateActionInfo :: Monad m => Id sid -> String -> Handler m -> Maybe ActionInfo multiUpdateActionInfo id_ pth h =  handlerActionInfo Nothing False UpdateMany Any pth PUT-                               <$> mkMultiPutHandler id_ (const id) h+                               <$> mkMultiHandler id_ (const id) h  removeActionInfo :: Handler m -> ActionInfo removeActionInfo = handlerActionInfo Nothing True Delete Self "" DELETE +multiRemoveActionInfo :: Monad m => Id sid -> String -> Handler m -> Maybe ActionInfo+multiRemoveActionInfo id_ pth h =  handlerActionInfo Nothing False DeleteMany Any pth DELETE+                               <$> mkMultiHandler id_ (const id) h+ listActionInfo :: Monad m => Maybe (Id mid) -> String -> ListHandler m -> Maybe ActionInfo listActionInfo mId pth h = handlerActionInfo mId False List Self pth GET <$> mkListHandler h @@ -335,6 +340,7 @@       Retrieve   -> "Retrieve " ++ targetS ++ " data"       Create     -> "Create " ++ targetS       Delete     -> "Delete " ++ targetS+      DeleteMany -> "Delete many " ++ targetS       List       -> "List " ++ targetS ++ "s"       Update     -> "Update " ++ targetS       UpdateMany -> "Update many " ++ targetS
src/Rest/Gen/Base/ApiTree.hs view
@@ -122,6 +122,7 @@                 Create     -> ["create"]     ++ by ++ target                 -- Should be delete, but delete is a JS keyword and causes problems in collect.                 Delete     -> ["remove"]     ++ by ++ target+                DeleteMany -> ["removeMany"] ++ by ++ target                 List       -> ["list"]       ++ by ++ target                 Update     -> ["save"]       ++ by ++ target                 UpdateMany -> ["saveMany"]   ++ by ++ target@@ -130,7 +131,8 @@       target = if resDir ai == ""                then [] else [resDir ai]       by     = if null target                ||    isNothing (ident ai)-                  && actionType ai /= UpdateMany then [] else ["by"]+                  && actionType ai /= UpdateMany+                  && actionType ai /= DeleteMany then [] else ["by"]       get    = if isAccessor ai                  then [] else ["get"]  cleanName :: String -> [String]
src/Rest/Gen/Haskell/Generate.hs view
@@ -1,4 +1,7 @@-{-# LANGUAGE DoAndIfThenElse, TemplateHaskell #-}+{-# LANGUAGE+    DoAndIfThenElse+  , TemplateHaskell+  #-} module Rest.Gen.Haskell.Generate where  import Control.Applicative@@ -8,7 +11,7 @@ import Data.Label (mkLabels, modify, set) import Data.List import Data.Maybe-import Prelude hiding ((.), id)+import Prelude hiding (id, (.)) import Safe import System.Directory import System.FilePath@@ -17,14 +20,14 @@ import qualified Distribution.Package                        as Cabal import qualified Distribution.PackageDescription             as Cabal import qualified Distribution.PackageDescription.Parse       as Cabal-import qualified Distribution.Verbosity                      as Cabal-import qualified Distribution.Version                        as Cabal import qualified Distribution.PackageDescription.PrettyPrint as Cabal import qualified Distribution.Simple.Utils                   as Cabal+import qualified Distribution.Verbosity                      as Cabal+import qualified Distribution.Version                        as Cabal  import Code.Build import Code.Build.Haskell-import Rest.Api (Version, Router)+import Rest.Api (Router, Version)  import Rest.Gen.Base import Rest.Gen.Utils@@ -214,6 +217,7 @@                 Create     -> ["create"] ++ by ++ target                 -- Should be delete, but delete is a JS keyword and causes problems in collect.                 Delete     -> ["remove"] ++ by ++ target+                DeleteMany -> ["removeMany"] ++ by ++ target                 List       -> ["list"]   ++ by ++ target                 Update     -> ["save"]   ++ by ++ target                 UpdateMany -> ["saveMany"] ++ by ++ target@@ -229,7 +233,13 @@  hsName :: [String] -> String hsName []       = ""-hsName (x : xs) = downFirst x ++ concatMap upFirst xs+hsName (x : xs) = clean $ downFirst x ++ concatMap upFirst xs+  where+    clean s = if s `elem` reservedNames then s ++ "_" else s+    reservedNames =+      ["as","case","class","data","instance","default","deriving","do"+      ,"foreign","if","then","else","import","infix","infixl","infixr","let"+      ,"in","module","newtype","of","qualified","type","where"]  qualModName :: ResourceId -> String qualModName = intercalate "." . map modName