refactored aeson instance in own package, this is now a multi-package project

This commit is contained in:
Dennis Frieberg 2020-09-22 12:11:10 +02:00
parent 41055a8521
commit c41d8aa43e
21 changed files with 192 additions and 1 deletions

2
tickLeiste-aeson/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
.stack-work/
*~

View file

@ -0,0 +1,3 @@
# Changelog for tickLeiste-aeson
## Unreleased changes

30
tickLeiste-aeson/LICENSE Normal file
View file

@ -0,0 +1,30 @@
Copyright Author name here (c) 2020
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 Author name here 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.

View file

@ -0,0 +1 @@
# tickLeiste-aeson

View file

@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain

View file

@ -0,0 +1,6 @@
module Main where
import Lib
main :: IO ()
main = someFunc

View file

@ -0,0 +1,52 @@
name: tickLeiste-aeson
version: 0.1.0.0
github: "githubuser/tickLeiste-aeson"
license: BSD3
author: "Author name here"
maintainer: "example@example.com"
copyright: "2020 Author name here"
extra-source-files:
- README.md
- ChangeLog.md
# Metadata used when publishing your package
# synopsis: Short description of your package
# category: Web
# To avoid duplicated efforts in documentation and dealing with the
# complications of embedding Haddock markup inside cabal files, it is
# common to point users to the README.md file.
description: Please see the README on GitHub at <https://github.com/githubuser/tickLeiste-aeson#readme>
dependencies:
- base >= 4.7 && < 5
- tickLeiste
- uuid
- aeson
- text
library:
source-dirs: src
executables:
tickLeiste-aeson-exe:
main: Main.hs
source-dirs: app
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- tickLeiste-aeson
tests:
tickLeiste-aeson-test:
main: Spec.hs
source-dirs: test
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- tickLeiste-aeson

View file

@ -0,0 +1,37 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
module Data.Aeson.TickLeiste
( JSONRequest (..),
JSONEvent (..),
)
where
import Data.Aeson
import Data.Aeson.TH
import qualified Data.Text as T
import Data.TickLeiste
import qualified Data.UUID as U
$(deriveJSON defaultOptions {sumEncoding = defaultTaggedObject {tagFieldName = "tickType", contentsFieldName = "tickValue"}} ''Tick)
data JSONRequest
= SetPlayerTickR {sptRplayerUUID :: U.UUID, sptRtick :: Tick}
| AddPlayerTickR {aptRplayerName :: T.Text, aptRtick :: Tick}
| InitializeTickLeisteR {itlRtickLeiste :: [(Tick, [T.Text])]}
| TickLeisteR
| ChangeNameR {cnaRplayerUUID :: U.UUID, cnaRplayerName :: T.Text}
| RemovePlayerR {rmpRplayerUUID :: U.UUID}
deriving (Show,Eq)
$(deriveJSON defaultOptions {sumEncoding = defaultTaggedObject {tagFieldName = "requestType"}, fieldLabelModifier = drop 4} ''JSONRequest)
data JSONEvent
= SetPlayerTickE {sptEplayerUUID :: U.UUID, sptEtick :: Tick}
| AddPlayerTickE {aptEplayerUUID :: U.UUID, aptEplayerName :: T.Text, aptEtick :: Tick}
| InitializeTickLeisteE {itlEtickLeiste :: [(Tick, [(U.UUID, T.Text)])]}
| ChangeNameE {cnaEplayerUUID :: U.UUID, cnaEplayerName :: T.Text}
| RemovePlayerE {rmpEplayerUUID :: U.UUID}
deriving (Show,Eq)
$(deriveJSON defaultOptions {sumEncoding = defaultTaggedObject {tagFieldName = "eventType"}, fieldLabelModifier = drop 4} ''JSONEvent)

View file

@ -0,0 +1,6 @@
module Lib
( someFunc
) where
someFunc :: IO ()
someFunc = putStrLn "someFunc"

View file

@ -0,0 +1,2 @@
main :: IO ()
main = putStrLn "Test suite not yet implemented"

View file

@ -0,0 +1,73 @@
cabal-version: 1.12
-- This file has been generated from package.yaml by hpack version 0.34.2.
--
-- see: https://github.com/sol/hpack
name: tickLeiste-aeson
version: 0.1.0.0
description: Please see the README on GitHub at <https://github.com/githubuser/tickLeiste-aeson#readme>
homepage: https://github.com/githubuser/tickLeiste-aeson#readme
bug-reports: https://github.com/githubuser/tickLeiste-aeson/issues
author: Author name here
maintainer: example@example.com
copyright: 2020 Author name here
license: BSD3
license-file: LICENSE
build-type: Simple
extra-source-files:
README.md
ChangeLog.md
source-repository head
type: git
location: https://github.com/githubuser/tickLeiste-aeson
library
exposed-modules:
Data.Aeson.TickLeiste
Lib
other-modules:
Paths_tickLeiste_aeson
hs-source-dirs:
src
build-depends:
aeson
, base >=4.7 && <5
, text
, tickLeiste
, uuid
default-language: Haskell2010
executable tickLeiste-aeson-exe
main-is: Main.hs
other-modules:
Paths_tickLeiste_aeson
hs-source-dirs:
app
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
aeson
, base >=4.7 && <5
, text
, tickLeiste
, tickLeiste-aeson
, uuid
default-language: Haskell2010
test-suite tickLeiste-aeson-test
type: exitcode-stdio-1.0
main-is: Spec.hs
other-modules:
Paths_tickLeiste_aeson
hs-source-dirs:
test
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
aeson
, base >=4.7 && <5
, text
, tickLeiste
, tickLeiste-aeson
, uuid
default-language: Haskell2010