core-data 0.3.8.0 → 0.3.9.0
raw patch · 8 files changed
+233/−164 lines, 8 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Core.Encoding.External: instance Core.Encoding.External.Externalize GHC.Int.Int16
+ Core.Encoding.External: instance Core.Encoding.External.Externalize GHC.Int.Int8
+ Core.Encoding.External: instance Core.Encoding.External.Externalize GHC.Word.Word16
+ Core.Encoding.External: instance Core.Encoding.External.Externalize GHC.Word.Word32
+ Core.Encoding.External: instance Core.Encoding.External.Externalize GHC.Word.Word64
+ Core.Encoding.External: instance Core.Encoding.External.Externalize GHC.Word.Word8
Files
- core-data.cabal +2/−2
- lib/Core/Data.hs +10/−10
- lib/Core/Data/Clock.hs +35/−35
- lib/Core/Data/Format.hs +5/−5
- lib/Core/Data/Structures.hs +25/−25
- lib/Core/Encoding.hs +4/−5
- lib/Core/Encoding/External.hs +77/−9
- lib/Core/Encoding/Json.hs +75/−73
core-data.cabal view
@@ -1,11 +1,11 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.35.0.+-- This file has been generated from package.yaml by hpack version 0.35.1. -- -- see: https://github.com/sol/hpack name: core-data-version: 0.3.8.0+version: 0.3.9.0 synopsis: Convenience wrappers around common data structures and encodings description: Wrappers around common data structures and encodings. .
lib/Core/Data.hs view
@@ -12,17 +12,17 @@ as this module re-exports all of its various components. -}-module Core.Data (- -- * Wrappers+module Core.Data+ ( -- * Wrappers - -- |- -- Exposes 'Map', a wrapper around a dictionary type, and 'Set', for- -- collections of elements.- module Core.Data.Structures,- -- |- -- Facilities for making timestamps and for converting between different representations of instants of time.- module Core.Data.Clock,-) where+ -- |+ -- Exposes 'Map', a wrapper around a dictionary type, and 'Set', for+ -- collections of elements.+ module Core.Data.Structures+ -- |+ -- Facilities for making timestamps and for converting between different representations of instants of time.+ , module Core.Data.Clock+ ) where import Core.Data.Clock import Core.Data.Structures
lib/Core/Data/Clock.hs view
@@ -32,18 +32,18 @@ use the 'fromTime' and 'intoTime' methods of the 'Instant' typeclass to convert from one to another if you need to. -}-module Core.Data.Clock (- -- * Time type- Time,- getCurrentTimeNanoseconds,+module Core.Data.Clock+ ( -- * Time type+ Time+ , getCurrentTimeNanoseconds - -- * Conversions- Instant (fromTime, intoTime),+ -- * Conversions+ , Instant (fromTime, intoTime) - -- * Internals- unTime,- epochTime,-) where+ -- * Internals+ , unTime+ , epochTime+ ) where import Control.Applicative ((<|>)) import Core.Data.Format@@ -51,31 +51,31 @@ import Data.Aeson qualified as Aeson (FromJSON (..), ToJSON (..), Value (..)) import Data.Aeson.Encoding qualified as Aeson (string) import Data.Aeson.Types qualified as Aeson (typeMismatch)-import Data.Hourglass qualified as H (- DateTime (..),- Elapsed (..),- ElapsedP (..),- ISO8601_Date (..),- ISO8601_DateAndTime (..),- NanoSeconds (..),- Seconds (..),- Timeable (timeGetElapsedP),- timeParse,- timePrint,- )+import Data.Hourglass qualified as H+ ( DateTime (..)+ , Elapsed (..)+ , ElapsedP (..)+ , ISO8601_Date (..)+ , ISO8601_DateAndTime (..)+ , NanoSeconds (..)+ , Seconds (..)+ , Timeable (timeGetElapsedP)+ , timeParse+ , timePrint+ ) import Data.Int (Int64) import Data.Maybe (maybeToList) import Data.Time.Calendar (Day) import Data.Time.Clock (UTCTime (UTCTime, utctDay, utctDayTime))-import Data.Time.Clock.POSIX (- POSIXTime,- posixSecondsToUTCTime,- utcTimeToPOSIXSeconds,- )+import Data.Time.Clock.POSIX+ ( POSIXTime+ , posixSecondsToUTCTime+ , utcTimeToPOSIXSeconds+ ) import GHC.Generics-import Time.System qualified as H (- timeCurrentP,- )+import Time.System qualified as H+ ( timeCurrentP+ ) {- | Number of nanoseconds since the Unix epoch.@@ -195,7 +195,7 @@ convertFromPosix = let nano :: POSIXTime -> Int64 nano = floor . (* 1000000000) . toRational- in Time . fromIntegral . nano+ in Time . fromIntegral . nano convertToPosix :: Time -> POSIXTime convertToPosix = fromRational . (/ 1e9) . fromIntegral . unTime@@ -213,12 +213,12 @@ convertFromElapsed (H.ElapsedP (H.Elapsed (H.Seconds seconds)) (H.NanoSeconds nanoseconds)) = let s = fromIntegral seconds :: Int64 ns = fromIntegral nanoseconds- in Time $! (s * 1000000000) + ns+ in Time $! (s * 1000000000) + ns convertToElapsed :: Time -> H.ElapsedP convertToElapsed (Time ticks) = let (s, ns) = divMod ticks 1000000000- in H.ElapsedP (H.Elapsed (H.Seconds (s))) (H.NanoSeconds (ns))+ in H.ElapsedP (H.Elapsed (H.Seconds (s))) (H.NanoSeconds (ns)) {- | This instance may be useful if you need to work with calendar dates with@@ -230,7 +230,7 @@ -} instance Instant Day where fromTime = utctDay . fromTime- intoTime x = intoTime (UTCTime{utctDay = x, utctDayTime = 0})+ intoTime x = intoTime (UTCTime {utctDay = x, utctDayTime = 0}) instance Aeson.ToJSON Time where toEncoding = Aeson.string . H.timePrint ISO8601_Precise . convertToElapsed@@ -239,7 +239,7 @@ parseJSON (Aeson.String value) = let str = (fromRope (intoRope value)) result = parseInput str- in case result of+ in case result of Just t -> pure t Nothing -> fail "Unable to parse input as a TimeStamp" parseJSON (invalid) = Aeson.typeMismatch "TimeStamp" invalid
lib/Core/Data/Format.hs view
@@ -4,11 +4,11 @@ module Core.Data.Format where -import Data.Hourglass qualified as H (- TimeFormat (..),- TimeFormatElem (..),- TimeFormatString (..),- )+import Data.Hourglass qualified as H+ ( TimeFormat (..)+ , TimeFormatElem (..)+ , TimeFormatString (..)+ ) {- | Format string describing full (nanosecond) precision ISO8601 time,
lib/Core/Data/Structures.hs view
@@ -9,35 +9,35 @@ facilitating conversion between them and various map and set types in common use in the Haskell ecosystem. -}-module Core.Data.Structures (- -- * Map type- Map,- emptyMap,- singletonMap,- insertKeyValue,- containsKey,- lookupKeyValue,- removeKeyValue,+module Core.Data.Structures+ ( -- * Map type+ Map+ , emptyMap+ , singletonMap+ , insertKeyValue+ , containsKey+ , lookupKeyValue+ , removeKeyValue - -- * Conversions- Dictionary (K, V, fromMap, intoMap),+ -- * Conversions+ , Dictionary (K, V, fromMap, intoMap) - -- * Set type- Set,- emptySet,- singletonSet,- insertElement,- containsElement,- removeElement,+ -- * Set type+ , Set+ , emptySet+ , singletonSet+ , insertElement+ , containsElement+ , removeElement - -- * Conversions- Collection (E, fromSet, intoSet),+ -- * Conversions+ , Collection (E, fromSet, intoSet) - -- * Internals- Key,- unMap,- unSet,-) where+ -- * Internals+ , Key+ , unMap+ , unSet+ ) where import Control.Concurrent qualified as Base (ThreadId) import Core.Text.Bytes (Bytes)
lib/Core/Encoding.hs view
@@ -16,11 +16,10 @@ providing for ease of use and interoperability across the various tools in this package. -}-module Core.Encoding (- module Core.Encoding.Json,-- module Core.Encoding.External,-) where+module Core.Encoding+ ( module Core.Encoding.Json+ , module Core.Encoding.External+ ) where import Core.Encoding.External import Core.Encoding.Json
lib/Core/Encoding/External.hs view
@@ -11,7 +11,7 @@ changing implemetations on the program side. Note that /externalizing/ is not quite the same as /serializing/. If you have-more complex (ie rich types or nested) data structures then a simple text+more complex data structures (ie rich types or nesting) then a simple text string will probably not be sufficient to convey sufficient information to represent it accurately. Serializing is focused on both performance encoding and decoding, and efficiency of the representation when transmitted over the@@ -24,9 +24,10 @@ machinery in this module comes in. If you have read this far and think we are describing something similar to-'Show' or @toString@ you are correct, but at the level of primative and simple-types we are providing the ability to marshall them to a clean UTF-8-representation and to unmarshall them back into Haskell values again.+Haskell's 'Show', Python's @repr()@ or Java's @toString()@ you would be+correct, but at the level of primative and simple types we are providing the+ability to marshall them to a clean UTF-8 representation and to unmarshall+them back into Haskell values again. The other major use case for this module is as a helper to read user input; see 'Core.Program.Execute.queryOptionValue'' for an example that makes use of@@ -44,19 +45,20 @@ See the discussion of creating 'Core.Data.Clock.Time' types from varying inputs for an example. -}-module Core.Encoding.External (- -- * Conversions- Externalize (formatExternal, parseExternal),-) where+module Core.Encoding.External+ ( Externalize (formatExternal, parseExternal)+ )+where import Core.Data.Clock import Core.Text.Rope import Data.ByteString.Builder qualified as Builder-import Data.Int (Int32, Int64)+import Data.Int (Int16, Int32, Int64, Int8) import Data.Scientific (FPFormat (Exponent), Scientific, formatScientific) import Data.Time.Calendar qualified as Base (Day) import Data.Time.Format.ISO8601 qualified as Base (formatParseM, formatShow, iso8601Format) import Data.UUID qualified as Uuid (UUID, fromText, toText)+import Data.Word (Word16, Word32, Word64, Word8) import Text.Read (readMaybe) {- |@@ -133,6 +135,28 @@ 42 @ -}+instance Externalize Int8 where+ formatExternal = intoRope . Builder.toLazyByteString . Builder.int8Dec+ parseExternal = readMaybe . fromRope++{- |+Integers are represented in decimal:++@+42+@+-}+instance Externalize Int16 where+ formatExternal = intoRope . Builder.toLazyByteString . Builder.int16Dec+ parseExternal = readMaybe . fromRope++{- |+Integers are represented in decimal:++@+42+@+-} instance Externalize Int32 where formatExternal = intoRope . Builder.toLazyByteString . Builder.int32Dec parseExternal = readMaybe . fromRope@@ -146,6 +170,50 @@ -} instance Externalize Int64 where formatExternal = intoRope . Builder.toLazyByteString . Builder.int64Dec+ parseExternal = readMaybe . fromRope++{- |+Words are likewise represented in decimal:++@+255+@+-}+instance Externalize Word8 where+ formatExternal = intoRope . Builder.toLazyByteString . Builder.word8Dec+ parseExternal = readMaybe . fromRope++{- |+Words are likewise represented in decimal:++@+65535+@+-}+instance Externalize Word16 where+ formatExternal = intoRope . Builder.toLazyByteString . Builder.word16Dec+ parseExternal = readMaybe . fromRope++{- |+Words are likewise represented in decimal:++@+4294967295+@+-}+instance Externalize Word32 where+ formatExternal = intoRope . Builder.toLazyByteString . Builder.word32Dec+ parseExternal = readMaybe . fromRope++{- |+Words are likewise represented in decimal:++@+18446744073709551615+@+-}+instance Externalize Word64 where+ formatExternal = intoRope . Builder.toLazyByteString . Builder.word64Dec parseExternal = readMaybe . fromRope {- |
lib/Core/Encoding/Json.hs view
@@ -51,21 +51,21 @@ certainly welcome to use the constructors if you find it makes for more readable code or if you need the type annotations. -}-module Core.Encoding.Json (- -- * Encoding and Decoding- encodeToUTF8,- encodeToRope,- decodeFromUTF8,- decodeFromRope,- JsonValue (..),- JsonKey (..),+module Core.Encoding.Json+ ( -- * Encoding and Decoding+ encodeToUTF8+ , encodeToRope+ , decodeFromUTF8+ , decodeFromRope+ , JsonValue (..)+ , JsonKey (..) - -- * Syntax highlighting- JsonToken (..),- colourizeJson,- prettyKey,- prettyValue,-) where+ -- * Syntax highlighting+ , JsonToken (..)+ , colourizeJson+ , prettyKey+ , prettyValue+ ) where #if MIN_VERSION_aeson(2,0,1) import qualified Data.Aeson.Key as Aeson@@ -76,68 +76,68 @@ import Core.Data.Structures (Key, Map, fromMap, intoMap) import Core.Text.Bytes (Bytes, fromBytes, intoBytes)-import Core.Text.Colour (- AnsiColour,- brightBlue,- brightGrey,- brightMagenta,- dullBlue,- dullCyan,- dullGreen,- dullYellow,- pureGrey,- )-import Core.Text.Rope (- Rope,- Textual,- fromRope,- intoRope,- singletonRope,- unconsRope,- )-import Core.Text.Utilities (- Render (Token, colourize, highlight),- breakRope,- )+import Core.Text.Colour+ ( AnsiColour+ , brightBlue+ , brightGrey+ , brightMagenta+ , dullBlue+ , dullCyan+ , dullGreen+ , dullYellow+ , pureGrey+ )+import Core.Text.Rope+ ( Rope+ , Textual+ , fromRope+ , intoRope+ , singletonRope+ , unconsRope+ )+import Core.Text.Utilities+ ( Render (Token, colourize, highlight)+ , breakRope+ ) import Data.Aeson (FromJSON, Value (String)) import qualified Data.Aeson as Aeson import Data.Char (intToDigit) import Data.Coerce import Data.Hashable (Hashable) import qualified Data.List as List-import Data.Scientific (- FPFormat (..),- Scientific,- formatScientific,- isFloating,- )+import Data.Scientific+ ( FPFormat (..)+ , Scientific+ , formatScientific+ , isFloating+ ) import Data.String (IsString (..)) import qualified Data.Text as T import qualified Data.Vector as V import GHC.Generics-import Prettyprinter (- Doc,- Pretty (..),- annotate,- comma,- dquote,- group,- hcat,- indent,- lbrace,- lbracket,- line,- line',- nest,- punctuate,- rbrace,- rbracket,- sep,- unAnnotate,- viaShow,- vsep,- (<+>),- )+import Prettyprinter+ ( Doc+ , Pretty (..)+ , annotate+ , comma+ , dquote+ , group+ , hcat+ , indent+ , lbrace+ , lbracket+ , line+ , line'+ , nest+ , punctuate+ , rbrace+ , rbracket+ , sep+ , unAnnotate+ , viaShow+ , vsep+ , (<+>)+ ) {- | Given a JSON value, encode it to UTF-8 bytes@@ -157,7 +157,7 @@ JsonObject xm -> let kvs = fromMap xm members = fmap (\((JsonKey k), v) -> doublequote <> escapeString k <> doublequote <> colonspace <> encodeToRope v) kvs- in openbrace <> mconcat (List.intersperse commaspace members) <> closebrace+ in openbrace <> mconcat (List.intersperse commaspace members) <> closebrace JsonArray xs -> openbracket <> mconcat (List.intersperse commaspace (fmap encodeToRope xs)) <> closebracket JsonString x ->@@ -184,7 +184,7 @@ escapeString :: Rope -> Rope escapeString text = let (before, after) = breakRope needsEscaping text- in case unconsRope after of+ in case unconsRope after of Nothing -> text Just (c, after') ->@@ -215,7 +215,7 @@ decodeFromUTF8 b = let x :: Maybe Aeson.Value x = Aeson.decodeStrict' (fromBytes b)- in fmap fromAeson x+ in fmap fromAeson x {- | Given an string that is full of a bunch of JSON, attempt to decode@@ -225,7 +225,7 @@ decodeFromRope text = let x :: Maybe Aeson.Value x = Aeson.decodeStrict' (fromRope text)- in fmap fromAeson x+ in fmap fromAeson x {- | A JSON value.@@ -277,6 +277,7 @@ fromRope t = coerce t intoRope x = coerce x +{- FOURMOLU_DISABLE -} fromAeson :: Aeson.Value -> JsonValue fromAeson value = case value of #if MIN_VERSION_aeson(2,0,1)@@ -314,6 +315,7 @@ Aeson.Number n -> JsonNumber n Aeson.Bool x -> JsonBool x Aeson.Null -> JsonNull+{- FOURMOLU_ENABLE -} -- -- Pretty printing@@ -405,12 +407,12 @@ (JsonObject _) -> line <> doc (JsonArray _) -> group doc _ -> doc- in if length entries == 0+ in if length entries == 0 then annotate SymbolToken (lbrace <> rbrace) else annotate SymbolToken lbrace <> line <> indent 4 (vsep (punctuate (annotate SymbolToken comma) entries)) <> line <> annotate SymbolToken rbrace JsonArray xs -> let entries = fmap prettyValue xs- in line'+ in line' <> nest 4 ( annotate SymbolToken lbracket@@ -435,7 +437,7 @@ let t = fromRope text :: T.Text ts = T.split (== '"') t ds = fmap pretty ts- in hcat (punctuate (annotate EscapeToken "\\\"") ds)+ in hcat (punctuate (annotate EscapeToken "\\\"") ds) {-# INLINEABLE escapeText #-} --