0 | module Pack.Database.TOML
 1 |
 2 | import Data.SortedMap
 3 | import Idris.Package.Types
 4 | import Libraries.Utils.Path
 5 | import Text.TOML
 6 | import Pack.Core.TOML
 7 | import Pack.Core.Types
 8 | import Pack.Database.Types
 9 |
10 | %default total
11 |
12 | export
13 | FromTOML MetaCommit where fromTOML = tmap fromString
14 |
15 | git : FromTOML c => File Abs -> TomlValue -> Either TOMLErr (Package_ c)
16 | git f v =
17 |   [| Git
18 |        (valAt "url" f v)
19 |        (valAt "commit" f v)
20 |        (valAt "ipkg" f v)
21 |        (optValAt "packagePath" f False v)
22 |        (maybeValAt "test" f v)
23 |        (maybeValAt "notice" f v)
24 |   |]
25 |
26 | local : File Abs -> TomlValue -> Either TOMLErr (Package_ c)
27 | local f v =
28 |   [| Local
29 |        (valAt "path" f v)
30 |        (valAt "ipkg" f v)
31 |        (optValAt "packagePath" f False v)
32 |        (maybeValAt "test" f v)
33 |   |]
34 |
35 | package : FromTOML c => File Abs -> TomlValue -> Either TOMLErr (Package_ c)
36 | package f v = valAt {a = String} "type" f v >>=
37 |   \case
38 |     "git"    => git f v
39 |     "github" => git f v -- for compatibility
40 |     "local"  => local f v
41 |     _        => Left $ WrongType ["type"] "Package Type"
42 |
43 | export %inline
44 | FromTOML c => FromTOML (Package_ c) where fromTOML = package
45 |
46 | ||| URL of the Idris repository
47 | export
48 | idrisRepo : URL
49 | idrisRepo = "https://github.com/idris-lang/Idris2.git"
50 |
51 | v0 : PkgVersion
52 | v0 = MkPkgVersion (0:::[0,0])
53 |
54 | export
55 | FromTOML MetaDB where
56 |   fromTOML f v =
57 |     [| MkDB
58 |          (optValAt "idris2.url" f idrisRepo v)
59 |          (valAt "idris2.commit" f v)
60 |          (pure v0)
61 |          (optValAt "db" f empty v)
62 |     |]
63 |