Commit afcab72f authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[simple-json] lots of rewrites for Simple.JSON

Also, spago build used now.
parent 8d5bcec1
......@@ -3587,7 +3587,7 @@
"newtype"
],
"repo": "https://github.com/hdgarrood/purescript-sequences.git",
"version": "v2.1.0"
"version": "v3.0.2"
},
"server-sent-events": {
"dependencies": [
......@@ -3662,6 +3662,13 @@
"repo": "https://github.com/justinwoo/purescript-simple-json.git",
"version": "v8.0.0"
},
"simple-json-generics": {
"dependencies": [
"simple-json"
],
"repo": "https://github.com/justinwoo/purescript-simple-json-generics",
"version": "v0.1.0"
},
"simple-jwt": {
"dependencies": [
"crypto",
......@@ -4159,8 +4166,8 @@
"typelevel",
"unsafe-coerce"
],
"repo": "https://github.com/athanclark/purescript-tuples-native",
"version": "v2.0.1"
"repo": "https://github.com/poorscript/purescript-tuples-native",
"version": "v2.2.0"
},
"turf": {
"dependencies": [
......
......@@ -508,7 +508,7 @@ referring to both the `Read` and `Write` classes:
```purescript
class (Read box val, Write box val) <= ReadWrite box val | box -> val
instance readWrite :: (Read box val, Write box val) => ReadWrite box val
instance (Read box val, Write box val) => ReadWrite box val
```
When you don't care about the current value, you can use `write`, the
......
......@@ -822,11 +822,29 @@
};
"sequences" = {
name = "sequences";
version = "v2.1.0";
version = "v3.0.2";
src = pkgs.fetchgit {
url = "https://github.com/hdgarrood/purescript-sequences.git";
rev = "v2.1.0";
sha256 = "10fkkmmb7qh4p5gmgb6xpxh9g8hy06ddy8cyfrs3py8a5b8h46hw";
rev = "v3.0.2";
sha256 = "0mc0jjs1119c2nyd08yhdmliq3s47lhrdknhziga3lnbzja889k4";
};
};
"simple-json" = {
name = "simple-json";
version = "v8.0.0";
src = pkgs.fetchgit {
url = "https://github.com/justinwoo/purescript-simple-json.git";
rev = "v8.0.0";
sha256 = "0q5hb324m1r5njnxq9wxgy99i0x8sd9mj2drq72i64xxr1k0m8qc";
};
};
"simple-json-generics" = {
name = "simple-json-generics";
version = "v0.1.0";
src = pkgs.fetchgit {
url = "https://github.com/justinwoo/purescript-simple-json-generics";
rev = "v0.1.0";
sha256 = "1izbrh9614yi0lzpnqbn9q7hbllhvvhrgyziganj7rzgphwn3ywx";
};
};
"simplecrypto" = {
......@@ -966,11 +984,11 @@
};
"tuples-native" = {
name = "tuples-native";
version = "v2.0.1";
version = "v2.2.0";
src = pkgs.fetchgit {
url = "https://github.com/athanclark/purescript-tuples-native";
rev = "v2.0.1";
sha256 = "1c8065krignnphiwnws9d5ingfx8k83wqnmd1zadyjlakfdg2b4h";
url = "https://github.com/poorscript/purescript-tuples-native";
rev = "v2.2.0";
sha256 = "0hplpqc2sbcjin084jqzhzqhprlc1achbqmsn9czpnf6ylgkqhaz";
};
};
"type-equality" = {
......@@ -1063,6 +1081,15 @@
sha256 = "0yfb97nk7179hp0r2iylj74wl7rnl1y2x6dh5hlipxg1kpq9yydk";
};
};
"variant" = {
name = "variant";
version = "v7.0.2";
src = pkgs.fetchgit {
url = "https://github.com/natefaubion/purescript-variant.git";
rev = "v7.0.2";
sha256 = "0a555fa2d8kd6rzfv9w64aphr7n6x0cizfp7n71wh5jw07b7hn5y";
};
};
"versions" = {
name = "versions";
version = "v6.0.0";
......
......@@ -38,7 +38,7 @@ let additions =
, "newtype"
]
, repo = "https://github.com/hdgarrood/purescript-sequences.git"
, version = "v2.1.0"
, version = "v3.0.2"
}
, spec-discovery =
{ dependencies = [ "prelude", "effect", "arrays", "spec", "node-fs" ]
......@@ -115,10 +115,16 @@ let additions =
, repo = "https://github.com/irresponsible/purescript-reactix"
, version = "v0.4.11"
}
, simple-json-generics =
{ dependencies =
[ "simple-json" ]
, repo = "https://github.com/justinwoo/purescript-simple-json-generics"
, version = "v0.1.0"
}
, toestand =
{ dependencies = [ "effect", "reactix", "prelude", "record", "tuples", "typelevel-prelude", "typisch" ]
, repo = "https://github.com/poorscript/purescript-toestand"
, version = "v0.6.1"
, version = "v0.6.2"
}
, typisch =
{ dependencies = [ "prelude" ]
......@@ -128,8 +134,8 @@ let additions =
, tuples-native =
{ dependencies =
[ "prelude", "typelevel", "unsafe-coerce" ]
, repo = "https://github.com/athanclark/purescript-tuples-native"
, version = "v2.0.1"
, repo = "https://github.com/poorscript/purescript-tuples-native"
, version = "v2.2.0"
}
, uint =
{ dependencies = [ "maybe", "math" ]
......
This diff is collapsed.
......@@ -36,6 +36,7 @@
"routing",
"sequences",
"simple-json",
"simple-json-generics",
"simplecrypto",
"smolder",
"spec-discovery",
......
......@@ -16,9 +16,10 @@ let
set -e
echo "Compiling"
build-purs
#build-purs
echo "Bundling"
yarn pulp browserify --skip-compile -t dist/bundle.js --src-path output
#yarn pulp browserify --skip-compile -t dist/bundle.js --src-path output
yarn spago bundle-app --to dist/bundle.js
'';
repl = pkgs.writeShellScriptBin "repl" ''
......
{-
Welcome to a Spago project!
You can edit this file as you like.
Need help? See the following resources:
- Spago documentation: https://github.com/purescript/spago
- Dhall language tour: https://docs.dhall-lang.org/tutorials/Language-Tour.html
When creating a new Spago project, you can use
`spago init --no-comments` or `spago init -C`
to generate this file without the comments in this block.
-}
{ name = "gargantext"
, dependencies =
[ "aff-promise"
, "affjax"
, "argonaut"
, "console"
, "css"
, "datetime"
, "debug"
, "dom-filereader"
, "dom-simple"
, "effect"
, "foreign-generic"
, "foreign-object"
, "formula"
, "globals"
, "integers"
, "js-timers"
, "markdown-smolder"
, "math"
, "maybe"
, "milkis"
, "nonempty"
, "now"
, "numbers"
, "prelude"
, "psci-support"
, "random"
, "react"
, "reactix"
, "read"
, "record-extra"
, "routing"
, "sequences"
, "simple-json"
, "simple-json-generics"
, "simplecrypto"
, "smolder"
, "spec-discovery"
, "spec-quickcheck"
, "string-parsers"
, "strings"
, "stringutils"
, "toestand"
, "tuples-native"
, "typisch"
, "uint"
, "uri"
, "versions"
, "web-html"
]
, packages = ./packages.dhall
, sources = [ "src/**/*.purs", "test/**/*.purs" ]
}
......@@ -8,15 +8,17 @@ import Data.Map as Map
import Data.Maybe (Maybe(..), maybe, fromMaybe)
import DOM.Simple.Console (log2)
import Effect (Effect)
import Gargantext.Types as GT
import Gargantext.Utils as GU
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Toestand as T2
import Reactix as R
import Simple.JSON as JSON
import Toestand as T
import Web.Storage.Storage as WSS
import Gargantext.Types as GT
import Gargantext.Utils as GU
import Gargantext.Utils.JSON as GUJ
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Toestand as T2
localStorageKey :: String
localStorageKey = "garg-async-tasks"
......@@ -24,6 +26,8 @@ localStorageKey = "garg-async-tasks"
type TaskList = Array GT.AsyncTaskWithType
type Storage = Map.Map GT.NodeID TaskList
instance JSON.ReadForeign Storage where readImpl = GUJ.readMap
empty :: Storage
empty = Map.empty
......
......@@ -24,8 +24,8 @@ here :: R2.Here
here = R2.here "Gargantext.Components.Annotation.Menu"
data MenuType = NewNgram | SetTermListItem
derive instance genericMenuType :: Generic MenuType _
instance eqMenuType :: Eq MenuType where
derive instance Generic MenuType _
instance Eq MenuType where
eq = genericEq
type Props =
......
-- TODO: this module should be replaced by FacetsTable
module Gargantext.Components.Category where
import Gargantext.Prelude (discard, map, pure, void, ($), (-), (<), (<>), (==))
import Data.Argonaut (class EncodeJson, encodeJson, jsonEmptyObject, (:=), (~>))
import Data.Array as A
import Data.Generic.Rep (class Generic)
import Data.Map as Map
import Data.Maybe (Maybe(..))
import Effect.Aff (Aff, launchAff)
import Reactix as R
import Reactix.DOM.HTML as H
import Simple.JSON as JSON
import Gargantext.Prelude
import Gargantext.Components.Category.Types
( Category(..), Star(..), cat2score, categories, clickAgain, star2score, stars )
......@@ -56,12 +58,10 @@ newtype RatingQuery =
RatingQuery { nodeIds :: Array Int
, rating :: Star
}
instance encodeJsonRatingQuery :: EncodeJson RatingQuery where
encodeJson (RatingQuery post) =
"ntc_nodesId" := post.nodeIds
~> "ntc_category" := encodeJson post.rating
~> jsonEmptyObject
derive instance Generic RatingQuery _
instance JSON.WriteForeign RatingQuery where
writeImpl (RatingQuery post) = JSON.writeImpl { ntc_nodesId: post.nodeIds
, ntc_category: post.rating }
putRating :: Session -> Int -> RatingQuery -> Aff (Array Int)
putRating session nodeId = put session $ ratingRoute where
......@@ -139,12 +139,10 @@ newtype CategoryQuery = CategoryQuery {
nodeIds :: Array Int
, category :: Category
}
instance encodeJsonCategoryQuery :: EncodeJson CategoryQuery where
encodeJson (CategoryQuery post) =
"ntc_nodesId" := post.nodeIds
~> "ntc_category" := encodeJson post.category
~> jsonEmptyObject
derive instance Generic CategoryQuery _
instance JSON.WriteForeign CategoryQuery where
writeImpl (CategoryQuery post) = JSON.writeImpl { ntc_nodesId: post.nodeIds
, ntc_category: post.category }
categoryRoute :: Int -> SessionRoute
categoryRoute nodeId = NodeAPI Node (Just nodeId) "category"
......
module Gargantext.Components.Category.Types where
import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, encodeJson)
import Data.Generic.Rep (class Generic)
import Data.Eq.Generic (genericEq)
import Data.Show.Generic (genericShow)
import Simple.JSON as JSON
import Gargantext.Prelude
......@@ -13,18 +13,14 @@ data Star = Star_0 | Star_1 | Star_2 | Star_3 | Star_4
stars :: Array Star
stars = [Star_0, Star_1, Star_2, Star_3, Star_4]
derive instance genericStar :: Generic Star _
instance showStar :: Show Star where
show = genericShow
instance eqStar :: Eq Star where
eq = genericEq
instance decodeJsonStar :: DecodeJson Star where
decodeJson json = do
obj <- decodeJson json
pure $ decodeStar obj
instance encodeJsonStar :: EncodeJson Star where
encodeJson x = encodeJson (star2score x)
derive instance Generic Star _
instance Show Star where show = genericShow
instance Eq Star where eq = genericEq
instance JSON.ReadForeign Star where
readImpl f = do
inst <- JSON.readImpl f
pure $ decodeStar inst
instance JSON.WriteForeign Star where writeImpl = JSON.writeImpl <<< star2score
decodeStar :: Int -> Star
decodeStar 0 = Star_0
......@@ -53,17 +49,14 @@ data Category = Trash | UnRead | Checked | Topic | Favorite
categories :: Array Category
categories = [Trash, UnRead, Checked, Topic, Favorite]
derive instance genericFavorite :: Generic Category _
instance showCategory :: Show Category where
show = genericShow
instance eqCategory :: Eq Category where
eq = genericEq
instance decodeJsonCategory :: DecodeJson Category where
decodeJson json = do
obj <- decodeJson json
pure $ decodeCategory obj
instance encodeJsonCategory :: EncodeJson Category where
encodeJson cat = encodeJson (cat2score cat)
derive instance Generic Category _
instance Show Category where show = genericShow
instance Eq Category where eq = genericEq
instance JSON.ReadForeign Category where
readImpl f = do
inst <- JSON.readImpl f
pure $ decodeCategory inst
instance JSON.WriteForeign Category where writeImpl = JSON.writeImpl <<< cat2score
favCategory :: Category -> Category
favCategory Favorite = Topic
......
......@@ -2,8 +2,8 @@ module Gargantext.Components.Charts.Options.ECharts where
import Prelude
import CSS (italic)
import CSS.Common (normal)
import CSS.FontStyle (FontStyle(..))
import Gargantext.Components.Charts.Options.Color (transparent, violet, black)
import Gargantext.Components.Charts.Options.Data (DataLegend, dataSerie)
import Gargantext.Components.Charts.Options.Font (IconOptions(..), Shape(..), TextStyle, chartFontStyle, chartFontWeight, icon, mkTooltip, Tooltip, mkToolBox)
......@@ -183,7 +183,7 @@ opts (Options { mainTitle
data Zoom = Slider | Inside
instance showZoom :: Show Zoom where
instance Show Zoom where
show Slider = "slider"
show Inside = "inside"
......@@ -211,7 +211,7 @@ seriesPie = seriesPieD1
textStyle2 :: TextStyle
textStyle2 =
{ color: black
, fontStyle: chartFontStyle italic
, fontStyle: chartFontStyle Italic
, fontWeight: chartFontWeight normal
, fontFamily: "sans-serif"
, fontSize: 11
......
......@@ -31,7 +31,8 @@ import Prelude (Unit, ($), (<<<), (<>))
import Data.Generic.Rep
import Data.Show.Generic (genericShow)
import CSS (FontStyle(..), FontWeight(..), Prefixed(..), Value(..))
import CSS (FontWeight(..), Prefixed(..), Value(..))
import CSS.FontStyle (FontStyle(..))
import Data.String (toLower)
import Gargantext.Components.Charts.Options.Color (Color)
import Gargantext.Components.Charts.Options.Position (LeftRelativePosition, Position, TopRelativePosition)
......@@ -62,8 +63,8 @@ type TextStyle =
newtype ChartFontStyle = ChartFontStyle String
chartFontStyle :: FontStyle -> ChartFontStyle
chartFontStyle (FontStyle (Value (Plain "italic"))) = ChartFontStyle "italic"
chartFontStyle (FontStyle (Value (Plain "oblique"))) = ChartFontStyle "oblique"
chartFontStyle Italic = ChartFontStyle "italic"
chartFontStyle (Oblique _) = ChartFontStyle "oblique"
chartFontStyle _ = ChartFontStyle "normal"
......@@ -81,7 +82,7 @@ newtype Icon = Icon String
newtype ImageURL = ImageURL String
data Shape = Circle | Rect | RoundRect | Triangle | Diamond | Pin | Arrow
derive instance genericShape :: Generic Shape _
derive instance Generic Shape _
data IconOptions = Shape Shape | Image ImageURL
......
......@@ -21,7 +21,7 @@ import Unsafe.Coerce (unsafeCoerce)
newtype LegendType = LegendType String
data PlainOrScroll = Plain | Scroll
instance showPlainOrScroll :: Show PlainOrScroll where
instance Show PlainOrScroll where
show (Plain) = "plain"
show (Scroll) = "scroll"
......@@ -32,7 +32,7 @@ legendType = LegendType <<< toLower <<< show
newtype Orient = Orient String
data Orientation = Horizontal | Vertical
derive instance genericOrientation :: Generic Orientation _
derive instance Generic Orientation _
orient :: Orientation -> Orient
orient = Orient <<< toLower <<< genericShow
......@@ -41,7 +41,7 @@ orient = Orient <<< toLower <<< genericShow
foreign import data SelectedMode :: Type
data LegendMode = Bool Boolean | Single | Multiple
derive instance genericLegendMode :: Generic LegendMode _
derive instance Generic LegendMode _
selectedMode :: LegendMode -> SelectedMode
selectedMode (Bool b) = unsafeCoerce b
......
......@@ -34,13 +34,13 @@ relativePosition (Relative r) = unsafeCoerce $ show r
data Align p = Auto | Relative p
data TopRelativePosition = Top | Middle | Bottom
instance showTopRelativePosition :: Show TopRelativePosition
instance Show TopRelativePosition
where show (Top) = "top"
show (Middle) = "middle"
show (Bottom) = "bottom"
data LeftRelativePosition = LeftPos | Center | RightPos
instance showLeftRelativePosition :: Show LeftRelativePosition
instance Show LeftRelativePosition
where show (LeftPos) = "left"
show (Center) = "center"
show (RightPos) = "right"
......@@ -39,7 +39,7 @@ data Chart = Line
| ThemeRiver
-- Trees
instance showChart :: Show Chart where
instance Show Chart where
show Bar = "bar"
show EffectScatter = "effectScatter" -- ^ https://ecomfe.github.io/echarts-examples/public/editor.html?c=scatter-effect
show Funnel = "funnel"
......@@ -131,7 +131,7 @@ seriesSankey o = unsafeSeries ((unsafeCoerce o) { "type" = seriesType Sankey })
-- Tree types
data Trees = TreeLine | TreeRadial | TreeMap
instance showTrees :: Show Trees where
instance Show Trees where
show TreeLine = "tree" -- ^ https://ecomfe.github.io/echarts-examples/public/editor.html?c=tree-radial
show TreeRadial = "tree" -- ^ https://ecomfe.github.io/echarts-examples/public/editor.html?c=scatter-simple
show TreeMap = "treemap" -- ^ https://ecomfe.github.io/echarts-examples/public/editor.html?c=treemap-simple
......@@ -192,17 +192,17 @@ data TreeNode = TreeNode {
, value :: Int
}
derive instance genericTreeNode :: Generic TreeNode _
instance eqTreeNode :: Eq TreeNode where
derive instance Generic TreeNode _
instance Eq TreeNode where
eq (TreeNode n1) (TreeNode n2) = eq n1 n2
instance decodeTreeNode :: DecodeJson TreeNode where
instance DecodeJson TreeNode where
decodeJson json = do
obj <- decodeJson json
children <- obj .: "children"
name <- obj .: "label"
value <- obj .: "value"
pure $ TreeNode { children, name, value }
instance encodeTreeNode :: EncodeJson TreeNode where
instance EncodeJson TreeNode where
encodeJson (TreeNode { children, name, value }) =
"children" := encodeJson children
~> "label" := encodeJson name
......
......@@ -36,17 +36,17 @@ type ElRef = R.Ref (Nullable Element)
data CodeType = Haskell | JSON | Markdown | Python
derive instance genericCodeType :: Generic CodeType _
instance eqCodeType :: Eq CodeType where
derive instance Generic CodeType _
instance Eq CodeType where
eq = genericEq
instance showCodeType :: Show CodeType where
instance Show CodeType where
show = genericShow
data ViewType = Code | Preview | Both
derive instance genericViewType :: Generic ViewType _
instance eqViewType :: Eq ViewType where
derive instance Generic ViewType _
instance Eq ViewType where
eq = genericEq
instance showViewType :: Show ViewType where
instance Show ViewType where
show = genericShow
type Props =
......
......@@ -507,7 +507,7 @@ newtype SearchQuery = SearchQuery {
}
instance encodeJsonSQuery :: EncodeJson SearchQuery where
instance EncodeJson SearchQuery where
encodeJson (SearchQuery {query, parent_id})
= "query" := query
~> "parent_id" := parent_id
......
module Gargantext.Components.DocsTable.Types where
import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, jsonEmptyObject, (.:), (:=), (~>))
import Data.Generic.Rep (class Generic)
import Data.Eq.Generic (genericEq)
import Data.Map (Map)
import Data.Map as Map
import Data.Maybe (Maybe(..))
import Data.Tuple (Tuple(..))
import Simple.JSON as JSON
import Gargantext.Prelude
......@@ -15,92 +15,94 @@ import Gargantext.Components.Category.Types (Category(..), decodeCategory, Star(
data Action
= MarkCategory Int Category
type DocumentsViewT =
( category :: Star
, date :: Int
, ngramCount :: Maybe Int
, score :: Maybe Int
, source :: String
, title :: String
, url :: String
)
newtype DocumentsView
= DocumentsView
{ _id :: Int
, category :: Star
, date :: Int
, ngramCount :: Maybe Int
, score :: Maybe Int
, source :: String
, title :: String
, url :: String
| DocumentsViewT
}
derive instance genericDocumentsView :: Generic DocumentsView _
instance eqDocumentsView :: Eq DocumentsView where
derive instance Generic DocumentsView _
instance Eq DocumentsView where
eq = genericEq
{-
derive instance genericDocumentsView :: Generic DocumentsView _
instance showDocumentsView :: Show DocumentsView where
derive instance Generic DocumentsView _
instance Show DocumentsView where
show = genericShow
instance decodeJsonSearchType :: Argonaut.DecodeJson SearchType where
instance Argonaut.DecodeJson SearchType where
decodeJson = genericSumDecodeJson
instance encodeJsonSearchType :: Argonaut.EncodeJson SearchType where
instance Argonaut.EncodeJson SearchType where
encodeJson = genericSumEncodeJson
-}
instance decodeDocumentsView :: DecodeJson DocumentsView where
decodeJson json = do
obj <- decodeJson json
_id <- obj .: "id"
category <- obj .: "category"
date <- obj .: "date"
ngramCount <- obj .: "ngramCount"
score <- obj .: "score"
source <- obj .: "source"
title <- obj .: "title"
url <- obj .: "url"
pure $ DocumentsView { _id, category, date, ngramCount, score, source, title, url }
instance encodeDocumentsView :: EncodeJson DocumentsView where
encodeJson (DocumentsView dv) =
"id" := dv._id
~> "category" := dv.category
~> "date" := dv.date
~> "ngramCount" := dv.ngramCount
~> "score" := dv.score
~> "source" := dv.source
~> "title" := dv.title
~> "url" := dv.url
~> jsonEmptyObject
instance JSON.ReadForeign DocumentsView where
readImpl f = do
{ id, category, date, ngramCount, score, source, title, url } :: { id :: Int | DocumentsViewT } <- JSON.readImpl f
pure $ DocumentsView { _id: id
, category
, date
, ngramCount
, score
, source
, title
, url }
instance JSON.WriteForeign DocumentsView where
writeImpl (DocumentsView { _id, category, date, ngramCount, score, source, title, url }) =
JSON.writeImpl { id: _id
, category
, date
, ngramCount
, score
, source
, title
, url }
type ResponseT =
( hyperdata :: Hyperdata
, ngramCount :: Maybe Int
, score :: Maybe Int
, title :: String )
newtype Response = Response
{ cid :: Int
, hyperdata :: Hyperdata
, category :: Star
, ngramCount :: Maybe Int
, score :: Maybe Int
, title :: String
, category :: Star
| ResponseT
}
instance JSON.ReadForeign Response where
readImpl f = do
{ category, id, hyperdata, ngramCount, score, title } :: { category :: Int, id :: Int | ResponseT } <- JSON.readImpl f
--pure $ Response { category: decodeCategory category, cid, hyperdata, ngramCount, score, title }
pure $ Response { category: decodeStar category
, cid: id
, hyperdata
, ngramCount
, score
, title }
type HyperdataT =
( title :: String
, source :: String )
newtype Hyperdata = Hyperdata
{ title :: String
, source :: String
, pub_year :: Int
{ pub_year :: Int
| HyperdataT
}
instance decodeHyperdata :: DecodeJson Hyperdata where
decodeJson json = do
obj <- decodeJson json
pub_year <- obj .: "publication_year"
source <- obj .: "source"
title <- obj .: "title"
pure $ Hyperdata { title,source, pub_year}
instance decodeResponse :: DecodeJson Response where
decodeJson json = do
obj <- decodeJson json
category <- obj .: "category"