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_ I 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 |        (maybeValAt "runsOn" f v)
25 |   |]
26 |
27 | local : File Abs -> TomlValue -> Either TOMLErr (Package_ f c)
28 | local f v =
29 |   [| Local
30 |        (valAt "path" f v)
31 |        (valAt "ipkg" f v)
32 |        (optValAt "packagePath" f False v)
33 |        (maybeValAt "test" f v)
34 |   |]
35 |
36 | package : FromTOML c => File Abs -> TomlValue -> Either TOMLErr (Package_ I c)
37 | package f v = valAt {a = String} "type" f v >>=
38 |   \case
39 |     "git"    => git f v
40 |     "github" => git f v -- for compatibility
41 |     "local"  => local f v
42 |     _        => Left $ WrongType ["type"] "Package Type"
43 |
44 | gitM : FromTOML c => File Abs -> TomlValue -> Either TOMLErr (Package_ Maybe c)
45 | gitM f v =
46 |   [| Git
47 |        (maybeValAt "url" f v)
48 |        (maybeValAt "commit" f v)
49 |        (maybeValAt "ipkg" f v)
50 |        (maybeValAt "packagePath" f v)
51 |        (maybeValAt "test" f v)
52 |        (maybeValAt "notice" f v)
53 |        (maybeValAt "runsOn" f v)
54 |   |]
55 |
56 | packageM : FromTOML c => File Abs -> TomlValue -> Either TOMLErr (Package_ Maybe c)
57 | packageM f v = optValAt {a = String} "type" f "git" v >>=
58 |   \case
59 |     "git"    => gitM f v
60 |     "github" => gitM f v -- for compatibility
61 |     "local"  => local f v
62 |     _        => Left $ WrongType ["type"] "Package Type"
63 |
64 | export %inline
65 | FromTOML c => FromTOML (Package_ I c) where fromTOML = package
66 |
67 | export %inline
68 | FromTOML c => FromTOML (Package_ Maybe c) where fromTOML = packageM
69 |
70 | ||| URL of the Idris repository
71 | export
72 | idrisRepo : URL
73 | idrisRepo = "https://github.com/idris-lang/Idris2.git"
74 |
75 | v0 : PkgVersion
76 | v0 = MkPkgVersion (0:::[0,0])
77 |
78 | export
79 | FromTOML MetaDB where
80 |   fromTOML f v =
81 |     [| MkDB
82 |          (optValAt "idris2.url" f idrisRepo v)
83 |          (valAt "idris2.commit" f v)
84 |          (pure v0)
85 |          (optValAt "db" f empty v)
86 |     |]
87 |