aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorV1K1NGbg <victor@ilchev.com>2024-08-01 22:04:19 +0300
committerV1K1NGbg <victor@ilchev.com>2024-08-05 20:51:31 +0300
commitafc79ce5bdec2e242ab2d19cdfe236958c7e2275 (patch)
tree7cc1dab4bff668b8ea7905644403f3d0a2ecfe60
parentfcb36443db545fbd5bf7adfde08ce1a800a41c6f (diff)
downloadluarocks-afc79ce5bdec2e242ab2d19cdfe236958c7e2275.tar.gz
luarocks-afc79ce5bdec2e242ab2d19cdfe236958c7e2275.tar.bz2
luarocks-afc79ce5bdec2e242ab2d19cdfe236958c7e2275.zip
more changes
-rw-r--r--src/luarocks/core/vers.tl7
-rw-r--r--src/luarocks/queries.tl1
-rw-r--r--src/luarocks/upload/multipart.tl38
-rw-r--r--src/mimetypes.d.tl2
4 files changed, 25 insertions, 23 deletions
diff --git a/src/luarocks/core/vers.tl b/src/luarocks/core/vers.tl
index 554296af..eae6d3d5 100644
--- a/src/luarocks/core/vers.tl
+++ b/src/luarocks/core/vers.tl
@@ -8,9 +8,10 @@ local record vers
8 metamethod __le: function(Version, Version): boolean 8 metamethod __le: function(Version, Version): boolean
9 end 9 end
10 10
11 record Constraints 11 record Constraint
12 op: string 12 op: string
13 version: Version | string 13 version: Version | string
14 no_upgrade: boolean
14 end 15 end
15end 16end
16 17
@@ -28,7 +29,7 @@ local deltas: {string: integer} = {
28} 29}
29 30
30local type Version = vers.Version 31local type Version = vers.Version
31local type Constraints = vers.Constraints 32local type Constraint = vers.Constraint
32 33
33local version_mt: metatable<Version> = { 34local version_mt: metatable<Version> = {
34 --- Equality comparison for versions. 35 --- Equality comparison for versions.
@@ -196,7 +197,7 @@ end
196-- @param constraints table: An array of constraints in table format. 197-- @param constraints table: An array of constraints in table format.
197-- @return boolean: True if version satisfies all constraints, 198-- @return boolean: True if version satisfies all constraints,
198-- false otherwise. 199-- false otherwise.
199function vers.match_constraints(version: Version, constraints: {Constraints}): boolean 200function vers.match_constraints(version: Version, constraints: {Constraint}): boolean
200 local ok = true 201 local ok = true
201 setmetatable(version, version_mt) 202 setmetatable(version, version_mt)
202 for _, constr in ipairs(constraints) do 203 for _, constr in ipairs(constraints) do
diff --git a/src/luarocks/queries.tl b/src/luarocks/queries.tl
index 15394c4d..3848bd2e 100644
--- a/src/luarocks/queries.tl
+++ b/src/luarocks/queries.tl
@@ -200,7 +200,6 @@ end
200-- @param query table: a query table 200-- @param query table: a query table
201-- @return string: a result such as `my_user/my_rock 1.0` or `my_rock`. 201-- @return string: a result such as `my_user/my_rock 1.0` or `my_rock`.
202function query_mt.__tostring(self: Query): string 202function query_mt.__tostring(self: Query): string
203 -- function query_mt:__tostring(): string
204 local out = {} 203 local out = {}
205 if self.namespace then 204 if self.namespace then
206 table.insert(out, self.namespace) 205 table.insert(out, self.namespace)
diff --git a/src/luarocks/upload/multipart.tl b/src/luarocks/upload/multipart.tl
index d6a5c012..2be9c45f 100644
--- a/src/luarocks/upload/multipart.tl
+++ b/src/luarocks/upload/multipart.tl
@@ -1,17 +1,17 @@
1 1
2local record multipart 2local record multipart
3 record TableMap<K, V> 3 record Parameters
4 map: {K: V} 4 {{string, string | File}}
5 array: {V} 5 map: {string: string | File}
6 end 6 end
7end 7end
8 8
9local type TableMap = multipart.TableMap 9local type Parameters = multipart.Parameters
10 10
11local record File 11local record File
12 mimetype: string --! TEMP 12 mimetype: string
13 fname: string 13 fname: string
14 mime: function(File): string --! TEMP 14 mime: function(File): string
15end 15end
16 16
17-- socket.url.escape(s) from LuaSocket 3.0rc1 --? 17-- socket.url.escape(s) from LuaSocket 3.0rc1 --?
@@ -21,13 +21,13 @@ function multipart.url_escape(s: string): string
21 end)) 21 end))
22end 22end
23 23
24function File.mime(self: File): string --! TEMP 24function File.mime(self: File): string
25 if not self.mimetype then 25 if not self.mimetype then
26 local mimetypes_ok, mimetypes = pcall(require, "luarocks.upload.mimetypes") --! TEMP 26 local mimetypes_ok, mimetypes = pcall(require, "mimetypes")
27 if mimetypes_ok then 27 if mimetypes_ok then
28 self.mimetype = mimetypes.guess(self.fname) --! TEMP 28 self.mimetype = mimetypes.guess(self.fname)
29 end 29 end
30 self.mimetype = self.mimetype or "application/octet-stream" --! TEMP 30 self.mimetype = self.mimetype or "application/octet-stream"
31 end 31 end
32 return self.mimetype 32 return self.mimetype
33end 33end
@@ -62,10 +62,10 @@ end
62-- {key2, value2}, 62-- {key2, value2},
63-- key3: value3 63-- key3: value3
64-- } 64-- }
65function multipart.encode(params: TableMap<string, string>): string, string --! Table map type 65function multipart.encode(params: Parameters): string, string --! Table map type
66 local tuples = {} --! type 66 local tuples: {{string, string | File}} = {} --! type
67 for i = 1, #params.array do 67 for i = 1, #params do
68 tuples[i] = params.array[i] 68 tuples[i] = params[i]
69 end 69 end
70 for k,v in pairs(params.map) do 70 for k,v in pairs(params.map) do
71 if k is string then 71 if k is string then
@@ -78,7 +78,7 @@ function multipart.encode(params: TableMap<string, string>): string, string --!
78 k = multipart.url_escape(k) 78 k = multipart.url_escape(k)
79 local buffer: {string} = { 'Content-Disposition: form-data; name="' .. k .. '"' } 79 local buffer: {string} = { 'Content-Disposition: form-data; name="' .. k .. '"' }
80 local content: string 80 local content: string
81 if type(v) == "table" and v.__class == File then 81 if v is File then
82 buffer[1] = buffer[1] .. ('; filename="' .. v.fname:gsub(".*[/\\]", "") .. '"') 82 buffer[1] = buffer[1] .. ('; filename="' .. v.fname:gsub(".*[/\\]", "") .. '"')
83 table.insert(buffer, "Content-type: " .. v:mime()) 83 table.insert(buffer, "Content-type: " .. v:mime())
84 content = v:content() 84 content = v:content()
@@ -105,12 +105,14 @@ function multipart.encode(params: TableMap<string, string>): string, string --!
105 "\r\n", "--", boundary, "--", "\r\n" }), boundary 105 "\r\n", "--", boundary, "--", "\r\n" }), boundary
106end 106end
107 107
108function multipart.new_file(fname: string, mime: string): File --! TEMP 108function multipart.new_file(fname: string, mime: string): File
109 local self: File = {} 109 local self: File = {}
110
110 setmetatable(self, { __index = File }) 111 setmetatable(self, { __index = File })
111 self.__class = File --! 112 self.__class = File --! no such field in teal
113
112 self.fname = fname 114 self.fname = fname
113 self.mimetype = mime --TEMP 115 self.mimetype = mime
114 return self 116 return self
115end 117end
116 118
diff --git a/src/mimetypes.d.tl b/src/mimetypes.d.tl
index 3b6ad692..a735225d 100644
--- a/src/mimetypes.d.tl
+++ b/src/mimetypes.d.tl
@@ -1,5 +1,5 @@
1local record mimetypes 1local record mimetypes
2 guess: function(string): string --! TEMP 2 guess: function(string): string
3end 3end
4 4
5return mimetypes \ No newline at end of file 5return mimetypes \ No newline at end of file