Skip to content

Commit 7acaed7

Browse files
committed
Strip unnecessary prefixes in JSON repr
1 parent 4e346c9 commit 7acaed7

File tree

271 files changed

+2842
-2839
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

271 files changed

+2842
-2839
lines changed

ff-core/lib/FF/Types.hs

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# OPTIONS -Wwarn=orphans #-}
2+
{-# LANGUAGE BlockArguments #-}
23
{-# LANGUAGE DeriveAnyClass #-}
34
{-# LANGUAGE DeriveFunctor #-}
45
{-# LANGUAGE DeriveGeneric #-}
@@ -23,7 +24,13 @@ module FF.Types where
2324

2425
import Control.Monad.Except (throwError)
2526
import Data.Aeson qualified as JSON
26-
import Data.Aeson.Extra (ToJSON, singletonObjectSum, toJSON, (.=))
27+
import Data.Aeson.Extra (
28+
ToJSON,
29+
fieldLabelModifier,
30+
singletonObjectSum,
31+
toJSON,
32+
(.=),
33+
)
2734
import Data.Aeson.Key qualified as JSON.Key
2835
import Data.Aeson.KeyMap qualified as JSON.KeyMap
2936
import Data.Aeson.TH (defaultOptions, deriveToJSON)
@@ -56,11 +63,7 @@ import RON.Data.Time (Day)
5663
import RON.Error (Error (Error))
5764
import RON.Schema.TH (mkReplicated)
5865
import RON.Storage (Collection, DocId, collectionName, loadDocument)
59-
import RON.Storage.Backend (
60-
DocId (DocId),
61-
Document (Document),
62-
MonadStorage,
63-
)
66+
import RON.Storage.Backend (DocId (DocId), Document (Document), MonadStorage)
6467
import RON.Storage.Backend qualified
6568
import RON.Text.Serialize (serializeUuid)
6669
import RON.Types (Atom (AUuid), ObjectRef, UUID)
@@ -254,28 +257,33 @@ data instance View Note = NoteView
254257
}
255258
deriving (Eq, Show)
256259

257-
deriveToJSON defaultOptions ''LinkType
258-
deriveToJSON defaultOptions ''Status
259-
deriveToJSON singletonObjectSum ''NoteStatus
260-
deriveToJSON defaultOptions ''Tag
261-
deriveToJSON defaultOptions ''Track
262-
263-
$(fold <$> for [''Link, ''Note] (deriveToJSON defaultOptions))
260+
$( fold
261+
<$> for
262+
[ (''Note, defaultOptions{fieldLabelModifier = drop 5})
263+
, (''NoteStatus, singletonObjectSum)
264+
, (''Status, defaultOptions)
265+
, (''Tag, defaultOptions{fieldLabelModifier = drop 4})
266+
, (''Track, defaultOptions{fieldLabelModifier = drop 6})
267+
]
268+
\(name, options) -> deriveToJSON options name
269+
)
264270

265271
instance ToJSON (View Note) where
266272
toJSON NoteView{note, tags} =
267-
JSON.Object $ JSON.KeyMap.insert "note_tags" tags' noteObj
273+
modifyObject (JSON.KeyMap.insert "tags" tags') $ toJSON note
268274
where
269-
noteObj = case toJSON note of
270-
JSON.Object obj -> obj
271-
_ -> error "Note must be serialized to Object"
272275
tags' =
273276
JSON.Object
274277
. JSON.KeyMap.fromMap
275278
. Map.mapKeysMonotonic JSON.Key.fromText
276279
. fmap JSON.String
277280
$ tags
278281

282+
modifyObject :: (JSON.Object -> JSON.Object) -> JSON.Value -> JSON.Value
283+
modifyObject f val = case val of
284+
JSON.Object obj -> JSON.Object $ f obj
285+
_ -> error "Note must be serialized to Object"
286+
279287
type ModeMap = Map TaskMode
280288

281289
-- | Sub-status of an 'Active' task from the perspective of the user.

ff-core/lib/FF/Upgrade.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import RON.Types (
4646
import RON.UUID (pattern Zero)
4747
import qualified RON.UUID as UUID
4848

49-
import FF.Types (Note, Tag)
49+
import FF.Types (Note)
5050

5151
upgradeDatabase :: (MonadStorage m) => m ()
5252
upgradeDatabase = do
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
note_end: null
2-
note_links: []
3-
note_start: 2018-12-08
4-
note_status:
1+
end: null
2+
links: []
3+
start: 2018-12-08
4+
status:
55
TaskStatus: Archived
6-
note_tags: {}
7-
note_text: import from gmail
8-
note_track: null
6+
tags: {}
7+
text: import from gmail
8+
track: null
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
note_end: null
2-
note_links: []
3-
note_start: 2018-03-31
4-
note_status:
1+
end: null
2+
links: []
3+
start: 2018-03-31
4+
status:
55
TaskStatus: Archived
6-
note_tags: {}
7-
note_text: import from github issues
8-
note_track: null
6+
tags: {}
7+
text: import from github issues
8+
track: null
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
note_end: null
2-
note_links: []
3-
note_start: 2018-03-31
4-
note_status:
1+
end: null
2+
links: []
3+
start: 2018-03-31
4+
status:
55
TaskStatus: Archived
6-
note_tags: {}
7-
note_text: try to use Swarm/RON as the backend
8-
note_track: null
6+
tags: {}
7+
text: try to use Swarm/RON as the backend
8+
track: null
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
note_end: null
2-
note_links: []
3-
note_start: 2018-04-17
4-
note_status:
1+
end: null
2+
links: []
3+
start: 2018-04-17
4+
status:
55
TaskStatus: Archived
6-
note_tags: {}
7-
note_text: 'CLI: syntax coloring'
8-
note_track: null
6+
tags: {}
7+
text: 'CLI: syntax coloring'
8+
track: null
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
note_end: null
2-
note_links: []
3-
note_start: 2018-02-21
4-
note_status:
1+
end: null
2+
links: []
3+
start: 2018-02-21
4+
status:
55
TaskStatus: Archived
6-
note_tags: {}
7-
note_text: 'repeating tasks: `done` moves to future in fixed period; may be useful
8-
for utility payments, or for other regular routines'
9-
note_track: null
6+
tags: {}
7+
text: 'repeating tasks: `done` moves to future in fixed period; may be useful for
8+
utility payments, or for other regular routines'
9+
track: null
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
note_end: null
2-
note_links: []
3-
note_start: 2018-02-23
4-
note_status:
1+
end: null
2+
links: []
3+
start: 2018-02-23
4+
status:
55
TaskStatus: Archived
6-
note_tags: {}
7-
note_text: due in N days
8-
note_track: null
6+
tags: {}
7+
text: due in N days
8+
track: null
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
note_end: null
2-
note_links: []
3-
note_start: 2018-12-08
4-
note_status:
1+
end: null
2+
links: []
3+
start: 2018-12-08
4+
status:
55
TaskStatus: Archived
6-
note_tags: {}
7-
note_text: import from Google Keep
8-
note_track: null
6+
tags: {}
7+
text: import from Google Keep
8+
track: null
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
note_end: null
2-
note_links: []
3-
note_start: 2018-02-25
4-
note_status:
1+
end: null
2+
links: []
3+
start: 2018-02-25
4+
status:
55
TaskStatus: Archived
6-
note_tags: {}
7-
note_text: |-
6+
tags: {}
7+
text: |-
88
postponed N times
99
increment counter on `postpone` and `edit --start` or `edit --end`
10-
note_track: null
10+
track: null

0 commit comments

Comments
 (0)