blob: 3078a3449da70661d0804ed7b2f131f5ac0521e0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
module Store.Query.Field
( Field (..),
toString,
prefix,
)
where
import Data.Aeson qualified as J
import Data.Aeson.Key qualified as JK
import Data.Aeson.KeyMap qualified as JM
import Data.List (intercalate)
import Data.Text qualified as T
data Field
= Field Collection [T.Text]
deriving (Show)
toString :: Field -> String
toString (Field c ks) = intercalate "." (c : map T.unpack ks)
type Collection = FilePath
prefix :: Field -> J.Value -> J.Value
prefix (Field c ks) = prefix' (T.pack c : ks)
prefix' :: [T.Text] -> J.Value -> J.Value
prefix' ks v =
foldr ((J.Object .) . JM.singleton) v (map JK.fromText ks)
|