From e184a7a138ce887fffd96b27c8d9d445c11f9483 Mon Sep 17 00:00:00 2001 From: V1K1NGbg Date: Thu, 22 Aug 2024 17:48:58 -0300 Subject: Teal: convert luarocks.type.manifest --- src/luarocks/type/manifest.tl | 106 +++++++++++++++++++++++------------------- 1 file changed, 59 insertions(+), 47 deletions(-) (limited to 'src') diff --git a/src/luarocks/type/manifest.tl b/src/luarocks/type/manifest.tl index 043366ea..11bdc566 100644 --- a/src/luarocks/type/manifest.tl +++ b/src/luarocks/type/manifest.tl @@ -1,58 +1,71 @@ -local type_manifest = {} +local record type_manifest +end + +local type Manifest = require("luarocks.core.types.manifest").Manifest local type_check = require("luarocks.type_check") local manifest_formats = type_check.declare_schemas({ ["3.0"] = { - repository = { - _mandatory = true, - -- packages - _any = { - -- versions + fields = { + repository = { + _mandatory = true, + -- packages _any = { - -- items + -- versions _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. + -- items + _any = { + fields = { + 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 + }, + modules = { + _mandatory = true, + -- modules + _any = { + -- providers + _any = { _type = "string" } + } + }, + commands = { + _mandatory = true, + -- modules + _any = { + -- commands + _any = { _type = "string" } + } + }, + dependencies = { + -- each module _any = { - -- each dependency + -- each version _any = { - name = { _type = "string" }, - namespace = { _type = "string" }, - constraints = { - _any = { - no_upgrade = { _type = "boolean" }, - op = { _type = "string" }, - version = { - string = { _type = "string" }, - _any = { _type = "number" }, + -- each dependency + _any = { + fields = { + name = { _type = "string" }, + namespace = { _type = "string" }, + constraints = { + _any = { + fields = { + no_upgrade = { _type = "boolean" }, + op = { _type = "string" }, + version = { + fields = { + string = { _type = "string" }, + }, + _any = { _type = "number" }, + } + } + } } } } @@ -69,12 +82,11 @@ local manifest_formats = type_check.declare_schemas({ -- 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") +function type_manifest.check(manifest: Manifest, globals: {string: any}): boolean, string --! 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, "") + return type_check.type_check_table("3.0", manifest as {any: any}, format, "") end return type_manifest -- cgit v1.2.3-55-g6feb