summaryrefslogtreecommitdiff
path: root/src/luarocks/type/manifest.lua
blob: 043366eac14a4a593da9eb52e96d887307d2dec8 (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
local type_manifest = {}

local type_check = require("luarocks.type_check")

local manifest_formats = type_check.declare_schemas({
   ["3.0"] = {
      repository = {
         _mandatory = true,
         -- packages
         _any = {
            -- versions
            _any = {
               -- items
               _any = {
                  arch = { _type = "string", _mandatory = true },
                  modules = { _any = { _type = "string" } },
                  commands = { _any = { _type = "string" } },
                  dependencies = { _any = { _type = "string" } },
                  -- TODO: to be extended with more metadata.
               }
            }
         }
      },
      modules = {
         _mandatory = true,
         -- modules
         _any = {
            -- providers
            _any = { _type = "string" }
         }
      },
      commands = {
         _mandatory = true,
         -- modules
         _any = {
            -- commands
            _any = { _type = "string" }
         }
      },
      dependencies = {
         -- each module
         _any = {
            -- each version
            _any = {
               -- each dependency
               _any = {
                  name = { _type = "string" },
                  namespace = { _type = "string" },
                  constraints = {
                     _any = {
                        no_upgrade = { _type = "boolean" },
                        op = { _type = "string" },
                        version = {
                           string = { _type = "string" },
                           _any = { _type = "number" },
                        }
                     }
                  }
               }
            }
         }
      }
   }
})

--- Type check a manifest table.
-- Verify the correctness of elements from a
-- manifest table, reporting on unknown fields and type
-- mismatches.
-- @return boolean or (nil, string): true if type checking
-- succeeded, or nil and an error message if it failed.
function type_manifest.check(manifest, globals)
   assert(type(manifest) == "table")
   local format = manifest_formats["3.0"]
   local ok, err = type_check.check_undeclared_globals(globals, format)
   if not ok then return nil, err end
   return type_check.type_check_table("3.0", manifest, format, "")
end

return type_manifest