module Data.API.Changes.Types
(
APIWithChangelog
, APIChangelog(..)
, APIChange(..)
, MigrationTag
, VersionExtra(..)
, showVersionExtra
, UpdateTypePos(..)
, UpdateDeclPos(..)
, APITableChange(..)
) where
import Data.API.PP
import Data.API.NormalForm
import Data.API.Types
import Data.Map ( Map )
import Data.Version
type APIWithChangelog = (API, APIChangelog)
data APIChangelog =
ChangesUpTo VersionExtra [APIChange] APIChangelog
| ChangesStart Version
deriving (Eq, Show)
data APIChange
= ChAddType TypeName NormTypeDecl
| ChDeleteType TypeName
| ChRenameType TypeName TypeName
| ChAddField TypeName FieldName APIType (Maybe DefaultValue)
| ChDeleteField TypeName FieldName
| ChRenameField TypeName FieldName FieldName
| ChChangeField TypeName FieldName APIType MigrationTag
| ChAddUnionAlt TypeName FieldName APIType
| ChDeleteUnionAlt TypeName FieldName
| ChRenameUnionAlt TypeName FieldName FieldName
| ChAddEnumVal TypeName FieldName
| ChDeleteEnumVal TypeName FieldName
| ChRenameEnumVal TypeName FieldName FieldName
| ChCustomType TypeName MigrationTag
| ChCustomAll MigrationTag
deriving (Eq, Show)
instance PPLines APIChange where
ppLines (ChAddType t d) = ("added " ++ pp t ++ " ") `inFrontOf` ppLines d
ppLines (ChDeleteType t) = ["removed " ++ pp t]
ppLines (ChRenameType t t') = ["renamed " ++ pp t ++ " to " ++ pp t']
ppLines (ChAddField t f ty mb_v) = [ "changed record " ++ pp t
, " field added " ++ pp f ++ " :: " ++ pp ty
++ maybe "" (\ v -> " default " ++ pp v) mb_v]
ppLines (ChDeleteField t f) = ["changed record " ++ pp t, " field removed " ++ pp f]
ppLines (ChRenameField t f f') = [ "changed record " ++ pp t
, " field renamed " ++ pp f ++ " to " ++ pp f']
ppLines (ChChangeField t f ty c) = [ "changed record " ++ pp t
, " field changed " ++ pp f ++ " :: " ++ pp ty
++ " migration " ++ pp c]
ppLines (ChAddUnionAlt t f ty) = [ "changed union " ++ pp t
, " alternative added " ++ pp f ++ " :: " ++ pp ty]
ppLines (ChDeleteUnionAlt t f) = [ "changed union " ++ pp t
, " alternative removed " ++ pp f]
ppLines (ChRenameUnionAlt t f f') = [ "changed union " ++ pp t
, " alternative renamed " ++ pp f ++ " to " ++ pp f']
ppLines (ChAddEnumVal t f) = [ "changed enum " ++ pp t
, " alternative added " ++ pp f]
ppLines (ChDeleteEnumVal t f) = [ "changed enum " ++ pp t
, " alternative removed " ++ pp f]
ppLines (ChRenameEnumVal t f f') = [ "changed enum " ++ pp t
, " alternative renamed " ++ pp f ++ " to " ++ pp f']
ppLines (ChCustomType t c) = ["migration record " ++ pp t ++ " " ++ pp c]
ppLines (ChCustomAll c) = ["migration " ++ pp c]
type MigrationTag = String
data VersionExtra = Release Version
| DevVersion
deriving (Eq, Ord, Show)
showVersionExtra :: VersionExtra -> String
showVersionExtra (Release v) = showVersion v
showVersionExtra DevVersion = "development"
instance PP VersionExtra where
pp = showVersionExtra
data UpdateDeclPos
= UpdateHere (Maybe UpdateDeclPos)
| UpdateRecord (Map FieldName (Maybe UpdateTypePos))
| UpdateUnion (Map FieldName (Maybe UpdateTypePos))
| UpdateType UpdateTypePos
deriving (Eq, Show)
data UpdateTypePos
= UpdateList UpdateTypePos
| UpdateMaybe UpdateTypePos
| UpdateNamed TypeName
deriving (Eq, Show)
data APITableChange
= APIChange NormAPI APIChange (Map TypeName UpdateDeclPos)
| ValidateData NormAPI
deriving (Eq, Show)
instance PPLines APITableChange where
ppLines (APIChange _ c _) = ppLines c
ppLines (ValidateData _) = []