Permalink
Browse files

-n

Move api-tools to subdirectory, add .cabal and related files
  • Loading branch information...
0 parents commit 86f71a969375e37f63e7819d1c426d190a387391 @adamgundry adamgundry committed Jan 21, 2014
30 LICENSE
@@ -0,0 +1,30 @@
+Copyright (c) 2013-2014, Iris Connect
+
+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 Iris Connect 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.
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
@@ -0,0 +1,173 @@
+Name: api-tools
+Version: 0.1
+Synopsis: DSL for generating API boilerplate and docs
+Description: api-tools provides a compact DSL for describing an API.
+ It uses Template Haskell to generate the
+ corresponding data types and assorted tools for
+ working with it, including Aeson and QuickCheck
+ instances for converting between JSON and the
+ generated types and writing unit tests.
+Homepage: http://github.com/iconnect/api-tools
+License: BSD3
+License-file: LICENSE
+Author: Chris Dornan
+Maintainer: chrisd@irisconnect.co.uk
+Copyright: (c) Iris Connect 2013-2014
+Category: Network, Web, Cloud, Distributed Computing
+Build-type: Simple
+
+Cabal-version: >=1.10
+
+Source-repository head
+ type: git
+ location: https://github.com/iconnect/api-tools.git
+
+Library
+ Hs-Source-Dirs: src
+
+ Exposed-modules:
+ Data.API.API
+ Data.API.API.DSL
+ Data.API.API.Gen
+ Data.API.Changes
+ Data.API.Doc.Call
+ Data.API.Doc.Dir
+ Data.API.Doc.Subst
+ Data.API.Doc.Types
+ Data.API.JSON
+ Data.API.Markdown
+ Data.API.Parse
+ Data.API.Tools
+ Data.API.Tools.Combinators
+ Data.API.Tools.Datatypes
+ Data.API.Tools.Enum
+ Data.API.Tools.Example
+ Data.API.Tools.JSON
+ Data.API.Tools.JSONTests
+ Data.API.Tools.Lens
+ Data.API.Tools.QuickCheck
+ Data.API.Tools.SafeCopy
+ Data.API.Types
+
+ Other-modules:
+ Data.API.Scan
+ Data.API.TH
+
+ Build-depends:
+ Cabal >= 1.9.2 ,
+ QuickCheck >= 2.5.1,
+ aeson >= 0.6.2,
+ aeson-pretty <= 0.7 ,
+ array >= 0.4,
+ attoparsec >= 0.10.4,
+ base == 4.*,
+ base64-bytestring == 1.0.*,
+ bytestring >= 0.9 && < 0.11,
+ case-insensitive >= 1.0,
+ containers >= 0.4,
+ lens >= 3.8.7,
+ old-locale >= 1.0.0.4,
+ regex-compat >= 0.95 ,
+ safe >= 0.3.3,
+ safecopy >= 0.8.1,
+ time >= 1.4,
+ template-haskell >= 2.7,
+ text >= 0.11,
+ unordered-containers >= 0.2.3.0 ,
+ vector >= 0.10.0.1
+
+ Build-tools:
+ alex,
+ happy
+
+ GHC-Options:
+ -Wall
+ -fwarn-tabs
+
+ Default-Language: Haskell2010
+
+
+Executable migration-tool
+ Hs-Source-Dirs: main
+
+ Main-is: Data/API/MigrationTool.hs
+
+ Build-depends:
+ api-tools >= 0.1,
+ Cabal >= 1.9.2 ,
+ QuickCheck >= 2.5.1,
+ aeson >= 0.6.2,
+ aeson-pretty <= 0.7 ,
+ array >= 0.4,
+ attoparsec >= 0.10.4,
+ base == 4.*,
+ base64-bytestring == 1.0.*,
+ bytestring >= 0.9 && < 0.11,
+ case-insensitive >= 1.0,
+ containers >= 0.4,
+ lens >= 3.8.7,
+ old-locale >= 1.0.0.4,
+ regex-compat >= 0.95 ,
+ safe >= 0.3.3,
+ safecopy >= 0.8.1,
+ time >= 1.4,
+ template-haskell >= 2.7,
+ text >= 0.11,
+ unordered-containers >= 0.2.3.0 ,
+ vector >= 0.10.0.1
+
+ GHC-Options:
+ -main-is Data.API.MigrationTool
+ -Wall
+ -fwarn-tabs
+
+ Default-Language: Haskell2010
+
+
+Test-Suite test-api-tools
+ Hs-Source-Dirs: tests
+
+ Type: exitcode-stdio-1.0
+
+ Main-is: Data/API/Test/Main.hs
+
+ Other-modules:
+ Data.API.Test.DSL
+ Data.API.Test.Gen
+ Data.API.Test.JSON
+ Data.API.Test.Migration
+ Data.API.Test.MigrationData
+
+ Build-depends:
+ api-tools >= 0.1,
+ Cabal >= 1.9.2 ,
+ QuickCheck >= 2.5.1,
+ aeson >= 0.6.2,
+ aeson-pretty <= 0.7 ,
+ array >= 0.4,
+ attoparsec >= 0.10.4,
+ base == 4.*,
+ base64-bytestring == 1.0.*,
+ bytestring >= 0.9 && < 0.11,
+ case-insensitive >= 1.0,
+ containers >= 0.4,
+ lens >= 3.8.7,
+ old-locale >= 1.0.0.4,
+ regex-compat >= 0.95 ,
+ safe >= 0.3.3,
+ safecopy >= 0.8.1,
+ tasty >= 0.3 ,
+ tasty-hunit >= 0.2 ,
+ tasty-quickcheck >= 0.3 ,
+ time >= 1.4,
+ template-haskell >= 2.7,
+ text >= 0.11,
+ unordered-containers >= 0.2.3.0 ,
+ vector >= 0.10.0.1
+
+ GHC-Options:
+ -main-is Data.API.Test.Main
+ -Wall
+ -fwarn-tabs
+
+ Default-Language: Haskell2010
@@ -0,0 +1,95 @@
+module Data.API.MigrationTool
+ ( main
+ ) where
+
+import Data.API.Changes
+import Data.API.JSON
+import Data.API.Parse
+import Data.API.Types
+
+import qualified Data.Aeson as JS
+import qualified Data.Aeson.Encode.Pretty as JS
+import qualified Data.ByteString.Lazy as BS
+import System.Environment
+import System.Exit
+import System.IO
+
+
+----------------------------
+-- Main, prototype testing
+
+main :: IO ()
+main = do
+ args <- getArgs
+ case args of
+ ["migrate", startApiFile, endApiFile, inDataFile, outDataFile] ->
+ migrate startApiFile endApiFile inDataFile outDataFile
+
+ ["compare", file1, file2] ->
+ compareJSON file1 file2
+
+ ["reformat", file1, file2] ->
+ reformatJSON file1 file2
+
+ ["changes", file] ->
+ changes file
+
+ _ -> putStrLn "--migrate start.api end.api start.json end.json" >> return ()
+
+migrate :: FilePath -> FilePath -> FilePath -> FilePath -> IO ()
+migrate startApiFile endApiFile
+ inDataFile outDataFile = do
+
+ (startApi, startChangelog) <- readApiFile startApiFile
+ (endApi, endChangelog) <- readApiFile endApiFile
+ inData <- readJsonFile inDataFile
+ let startApiVer = changelogVersion startChangelog
+ endApiVer = changelogVersion endChangelog
+ case migrateDataDump (startApi, startApiVer) (endApi, endApiVer)
+ endChangelog customMigrations root CheckAll inData of
+ Left err -> do
+ hPutStrLn stderr (prettyMigrateFailure err)
+ exitFailure
+ Right (outData, warnings) -> do
+ putStrLn . unlines . map show $ warnings
+ writeJsonFile outDataFile outData
+
+root :: TypeName
+root = TypeName "DatabaseSnapshot"
+
+readJsonFile :: FromJSONWithErrs b => FilePath -> IO b
+readJsonFile file = either (fail . prettyJSONErrorPositions) return
+ . decodeWithErrs =<< BS.readFile file
+
+writeJsonFile :: JS.ToJSON a => FilePath -> a -> IO ()
+writeJsonFile file = BS.writeFile file . JS.encodePretty
+
+readApiFile :: FilePath -> IO APIWithChangelog
+readApiFile file = fmap parseAPIWithChangelog (readFile file)
+
+data ChangeTag = None
+ deriving (Read, Show)
+
+customMigrations :: CustomMigrations ChangeTag ChangeTag ChangeTag
+customMigrations = CustomMigrations nope (\ _ _ -> Nothing)
+ nope (\ _ _ -> Nothing)
+ nofld
+ where
+ nope _ v = Left (CustomMigrationError "No custom migrations defined" (JS.Object v))
+ nofld _ v = Left (CustomMigrationError "No field custom migrations defined" v)
+
+compareJSON :: FilePath -> FilePath -> IO ()
+compareJSON file1 file2 = do
+ js1 <- readJsonFile file1
+ js2 <- readJsonFile file2
+ print (js1 == (js2 :: JS.Value))
+
+reformatJSON :: FilePath -> FilePath -> IO ()
+reformatJSON file1 file2 = do
+ js <- readJsonFile file1
+ writeJsonFile file2 (js :: JS.Value)
+
+changes :: FilePath -> IO ()
+changes file = do
+ s <- readFile file
+ print (parseAPI s)
Oops, something went wrong.

0 comments on commit 86f71a9

Please sign in to comment.