| Safe Haskell | None |
|---|
Data.SemVer
Contents
Description
An implementation of the Semantic Versioning specification located at http://semver.org.
A canonical Version type and functions representing behaviour as outlined
in the specification are defined alongside additional lenses, traversals,
common manipulations, and serialisation primitives.
- data Version
- version :: Int -> Int -> Int -> [Identifier] -> [Identifier] -> Version
- initial :: Version
- versionMajor :: Functor f => (Int -> f Int) -> Version -> f Version
- versionMinor :: Functor f => (Int -> f Int) -> Version -> f Version
- versionPatch :: Functor f => (Int -> f Int) -> Version -> f Version
- versionRelease :: Functor f => ([Identifier] -> f [Identifier]) -> Version -> f Version
- versionMeta :: Functor f => ([Identifier] -> f [Identifier]) -> Version -> f Version
- incrementMajor :: Version -> Version
- incrementMinor :: Version -> Version
- incrementPatch :: Version -> Version
- isDevelopment :: Version -> Bool
- isPublic :: Version -> Bool
- toString :: Version -> String
- toText :: Version -> Text
- toLazyText :: Version -> Text
- toBuilder :: Version -> Builder
- fromText :: Text -> Either String Version
- fromLazyText :: Text -> Either String Version
- parser :: Parser Version
- data Identifier
- numeric :: Int -> Identifier
- textual :: Text -> Maybe Identifier
- _Numeric :: Applicative f => (Int -> f Int) -> Identifier -> f Identifier
- _Textual :: Applicative f => (Text -> f Text) -> Identifier -> f Identifier
- data Delimiters
- delimiters :: Delimiters
- delimMinor :: Functor f => (Char -> f Char) -> Delimiters -> f Delimiters
- delimPatch :: Functor f => (Char -> f Char) -> Delimiters -> f Delimiters
- delimRelease :: Functor f => (Char -> f Char) -> Delimiters -> f Delimiters
- delimMeta :: Functor f => (Char -> f Char) -> Delimiters -> f Delimiters
- delimIdent :: Functor f => (Char -> f Char) -> Delimiters -> f Delimiters
- toDelimitedBuilder :: Delimiters -> Version -> Builder
- delimitedParser :: Delimiters -> Parser Version
Version
An opaque type representing a successfully decoded or constructed semantic version. See the related functions and lenses for modification and update.
Constructors
Arguments
| :: Int | Major version component. |
| -> Int | Minor version component. |
| -> Int | Patch version component. |
| -> [Identifier] | Release identifiers. |
| -> [Identifier] | Metadata identifiers. |
| -> Version |
Smart constructor fully specifying all available version components.
A default Version which can be used to signify initial development.
Note: Equivalent to 0.0.0
Lenses
versionMajor :: Functor f => (Int -> f Int) -> Version -> f VersionSource
Lens for the major version component.
versionMinor :: Functor f => (Int -> f Int) -> Version -> f VersionSource
Lens for minor version component.
versionPatch :: Functor f => (Int -> f Int) -> Version -> f VersionSource
Lens for the patch version component.
versionRelease :: Functor f => ([Identifier] -> f [Identifier]) -> Version -> f VersionSource
Lens for the list of release identifiers.
versionMeta :: Functor f => ([Identifier] -> f [Identifier]) -> Version -> f VersionSource
Lens for the list of metadata identifiers.
Incrementing
incrementMajor :: Version -> VersionSource
Increment the major component of a Version by 1, resetting the minor
and patch components.
- Major version X (X.y.z | X > 0) MUST be incremented if any backwards incompatible changes are introduced to the public API.
- It MAY include minor and patch level changes.
- Patch and minor version MUST be reset to 0 when major version is incremented.
incrementMinor :: Version -> VersionSource
Increment the minor component of a Version by 1, resetting the
patch component.
- Minor version Y (x.Y.z | x > 0) MUST be incremented if new, backwards compatible functionality is introduced to the public API.
- It MUST be incremented if any public API functionality is marked as deprecated.
- It MAY be incremented if substantial new functionality or improvements are introduced within the private code.
- It MAY include patch level changes.
- Patch version MUST be reset to 0 when minor version is incremented.
incrementPatch :: Version -> VersionSource
Increment the patch component of a Version by 1.
- Patch version Z (x.y.Z | x > 0) MUST be incremented if only backwards compatible bug fixes are introduced.
- A bug fix is defined as an internal change that fixes incorrect behavior.
Predicates
isDevelopment :: Version -> BoolSource
Check if the Version is considered unstable.
- Major version zero (0.y.z) is for initial development.
- Anything may change at any time.
- The public API should not be considered stable.
isPublic :: Version -> BoolSource
Check if the Version is considered stable.
Version 1.0.0 defines the public API. The way in which the version number is incremented after this release is dependent on this public API and how it changes.
Encoding
toLazyText :: Version -> TextSource
Convert a Version to a Text representation.
Note: This uses a lower Builder buffer size optimised for commonly
found version formats. If you have particuarly long version numbers
using toBuilder and toLazyTextWith to control the buffer size
is recommended.
Decoding
Identifiers
data Identifier Source
A type representing an individual identifier from the release
or metadata components of a Version.
- The
Ordinstance implements precedence according to the semantic version specification, with numeric identifiers being of lower precedence than textual identifiers, otherwise lexicographic ordering is used.
The functions numeric and textual can be used to construct an Identifier.
Instances
Constructors
numeric :: Int -> IdentifierSource
Safely construct a numeric identifier.
textual :: Text -> Maybe IdentifierSource
Prisms
_Numeric :: Applicative f => (Int -> f Int) -> Identifier -> f IdentifierSource
_Textual :: Applicative f => (Text -> f Text) -> Identifier -> f IdentifierSource
Delimiters
A set of delimiters is used to encode/decode a Version and specify
alternative serialisation strategies.
Lenses can be used to modify the default delimiter set, as in the following example - using alpha characters to encode the version as a valid DNS CNAME:
let Right v = fromText 1.2.3+40 let alpha = delimiters & delimMajor .= 'm' & delimPatch .= 'p' & delimRelease .= 'r' & delimMeta .= 'd' & delimIdent .= 'i' Data.Text.Lazy.Builder.toLazyText ("app01-" toDelimitedBuilder alpha v ".dmz.internal")
Would result in the following Text:
app01-1m2p3d40.dmz.internal
Using the same Delimiters set with delimitedParser would ensure
correct decoding behaviour.
data Delimiters Source
An opaque set representing the seperators used to delimit semantic version components.
Instances
Constructor
delimiters :: DelimitersSource
The default set of delimiters used in the semantic version specification.
Example: Given exhaustive version components would result in the following hypothetical version:
1.2.3-alpha.1+sha.exp.12ab3d9
Lenses
delimMinor :: Functor f => (Char -> f Char) -> Delimiters -> f DelimitersSource
Lens for the minor version delimiter. Default: .
delimPatch :: Functor f => (Char -> f Char) -> Delimiters -> f DelimitersSource
Lens for the patch version delimiter. Default: .
delimRelease :: Functor f => (Char -> f Char) -> Delimiters -> f DelimitersSource
Lens for the release component delimiter. Default: -
delimMeta :: Functor f => (Char -> f Char) -> Delimiters -> f DelimitersSource
Lens for the metadata component delimiter. Default: +
delimIdent :: Functor f => (Char -> f Char) -> Delimiters -> f DelimitersSource
Lens for the individual identifier delimiter. Default: .
Encoding
toDelimitedBuilder :: Delimiters -> Version -> BuilderSource
Convert a Version to a Builder using the specified Delimiters set.
Decoding
delimitedParser :: Delimiters -> Parser VersionSource
A greedy attoparsec Parser using the specified Delimiters set
which requires the entire Text input to match.