Skip to content

Commit cd81046

Browse files
authored
Merge pull request #3 from pessoa736/dev
feat: add help system, LuaDoc annotations, and improved AI documentation
2 parents 83d8964 + dda7b3a commit cd81046

13 files changed

Lines changed: 1167 additions & 57 deletions

.github/copilot-instructions.md

Lines changed: 391 additions & 28 deletions
Large diffs are not rendered by default.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ luac.out
4747
/lua
4848
/lua_modules
4949
/.luarocks
50+
.pudimserver_initialized

PudimServer/ServerChecks.lua

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ local PortCheckParamsInter = utils:createInterface({
2424
local ServerChecks = {}
2525
ServerChecks.__index = ServerChecks
2626

27-
---@param Address string
28-
---@param Port number|string
29-
---@return boolean is_open
30-
---@return string erro
27+
--- Checks if a TCP port is open on the given address.
28+
---@param Address string Host address to check
29+
---@param Port number|string Port number to check
30+
---@return boolean is_open True if the port is accepting connections
31+
---@return string message Description of the result
3132
function ServerChecks.is_Port_Open(Address, Port)
3233
local CIPO = log.inSection("Check: is Port Open")
3334

PudimServer/cache.lua

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ local Cache = {}
3333
Cache.__index = Cache
3434

3535

36-
---@param config? CacheConfig
37-
---@return Cache
36+
--- Creates a new Cache instance with optional configuration.
37+
---@param config? CacheConfig Cache configuration (MaxSize, DefaultTTL)
38+
---@return Cache cache New cache instance
3839
function Cache.new(config)
3940
local CL = log.inSection("Cache")
4041

@@ -50,8 +51,9 @@ function Cache.new(config)
5051
end
5152

5253

53-
---@param key string
54-
---@return string? response
54+
--- Retrieves a cached response by key. Returns nil if expired or not found.
55+
---@param key string Cache key (typically "METHOD:path")
56+
---@return string? response Cached HTTP response or nil
5557
function Cache:get(key)
5658
local entry = self._entries[key]
5759
if not entry then return nil end
@@ -66,9 +68,10 @@ function Cache:get(key)
6668
end
6769

6870

69-
---@param key string
70-
---@param response string
71-
---@param ttl? number TTL em segundos (usa default se nil)
71+
--- Stores a response in the cache. Evicts oldest entry if cache is full.
72+
---@param key string Cache key (typically "METHOD:path")
73+
---@param response string HTTP response string to cache
74+
---@param ttl? number TTL in seconds (uses DefaultTTL if nil)
7275
function Cache:set(key, response, ttl)
7376
if not self._entries[key] then
7477
-- Evict oldest if full
@@ -85,7 +88,8 @@ function Cache:set(key, response, ttl)
8588
end
8689

8790

88-
---@param key string
91+
--- Removes a single entry from the cache.
92+
---@param key string Cache key to invalidate
8993
function Cache:invalidate(key)
9094
if self._entries[key] then
9195
self._entries[key] = nil
@@ -94,6 +98,7 @@ function Cache:invalidate(key)
9498
end
9599

96100

101+
--- Removes all entries from the cache.
97102
function Cache:clear()
98103
self._entries = {}
99104
self._size = 0
@@ -118,9 +123,11 @@ function Cache:_evict()
118123
end
119124

120125

121-
---@param cacheInstance Cache
122-
---@param ttl? number TTL customizado
123-
---@return PipelineEntry
126+
--- Creates a PipelineEntry that caches GET responses.
127+
--- Only caches GET requests. Cache key format: "method:path".
128+
---@param cacheInstance Cache The cache instance to use
129+
---@param ttl? number Custom TTL in seconds (uses cache's DefaultTTL if nil)
130+
---@return PipelineEntry entry Pipeline handler ready for Server:UseHandler()
124131
function Cache.createPipelineHandler(cacheInstance, ttl)
125132
return {
126133
name = "cache",

PudimServer/cors.lua

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ end
4646
---@param config? CorsConfig
4747
---@return table corsHeaders Headers CORS resolvidos
4848
---@return CorsConfig resolvedConfig Config com defaults aplicados
49+
--- Creates a resolved CORS configuration with defaults applied.
50+
---@param config? CorsConfig Raw CORS configuration
51+
---@return table resolvedConfig Config with all defaults filled in
4952
function cors.createConfig(config)
5053
local CL = log.inSection("CORS")
5154

@@ -65,9 +68,10 @@ function cors.createConfig(config)
6568
end
6669

6770

68-
---@param config table Config resolvida do CORS
69-
---@param requestOrigin string? Origin do request
70-
---@return table headers Headers CORS para adicionar na resposta
71+
--- Builds CORS response headers from a resolved config.
72+
---@param config table Resolved CORS config (from createConfig)
73+
---@param requestOrigin? string Origin header from the request
74+
---@return table<string, string> headers CORS headers to add to the response
7175
function cors.buildHeaders(config, requestOrigin)
7276
local headers = {}
7377

@@ -89,8 +93,9 @@ function cors.buildHeaders(config, requestOrigin)
8993
end
9094

9195

92-
---@param config table Config resolvida do CORS
93-
---@return string Resposta HTTP para preflight
96+
--- Returns a 204 No Content HTTP response for CORS preflight (OPTIONS) requests.
97+
---@param config table Resolved CORS config (from createConfig)
98+
---@return string response HTTP response string for preflight
9499
function cors.preflightResponse(config)
95100
local http = require("PudimServer.http")
96101
local headers = cors.buildHeaders(config)

0 commit comments

Comments
 (0)