diff --git a/src/common/controllers.lua b/src/common/controllers.lua index 5cb0b2e..d37759c 100644 --- a/src/common/controllers.lua +++ b/src/common/controllers.lua @@ -4,7 +4,7 @@ local controllers = {} --- Set a controller. ---@param controller string The controller to set. ----@return table +---@return string[] function controllers.setController(controller) utils.validateArweaveId(controller) @@ -18,7 +18,7 @@ end --- Remove a controller. ---@param controller string The controller to remove. ----@return table +---@return string[] function controllers.removeController(controller) utils.validateArweaveId(controller) local controllerExists = false @@ -36,7 +36,7 @@ function controllers.removeController(controller) end --- Get all controllers. ----@return table +---@return string[] function controllers.getControllers() return Controllers end diff --git a/src/common/main.lua b/src/common/main.lua index c6bcb64..a925805 100644 --- a/src/common/main.lua +++ b/src/common/main.lua @@ -36,7 +36,7 @@ function ant.init() ---@alias Description string ---@description A brief description of this ANT up to 255 characters Description = Description or "A brief description of this ANT." - ---@alias Keywords table + ---@alias Keywords string[] ---@description A list of keywords that describe this ANT. Each keyword must be a string, unique, and less than 32 characters. There can be up to 16 keywords Keywords = Keywords or {} ---@alias Denomination integer diff --git a/src/common/types.lua b/src/common/types.lua index 548d320..5ab943b 100644 --- a/src/common/types.lua +++ b/src/common/types.lua @@ -40,7 +40,7 @@ --- Logo: string, --- Balances: table, --- Owner: string, ---- Controllers: table, +--- Controllers: string[], --- Denomination: integer, --- TotalSupply: integer, --- Initialized: boolean, diff --git a/src/common/utils.lua b/src/common/utils.lua index 044e6dd..58c791f 100644 --- a/src/common/utils.lua +++ b/src/common/utils.lua @@ -3,172 +3,6 @@ local constants = require(".common.constants") local json = require(".common.json") local utils = { _version = "0.0.1" } -local function isArray(table) - if type(table) == "table" then - local maxIndex = 0 - for k, _ in pairs(table) do - if type(k) ~= "number" or k < 1 or math.floor(k) ~= k then - return false -- If there's a non-integer key, it's not an array - end - maxIndex = math.max(maxIndex, k) - end - -- If the highest numeric index is equal to the number of elements, it's an array - return maxIndex == #table - end - return false -end - ---- @param fn function ---- @param arity number -utils.curry = function(fn, arity) - assert(type(fn) == "function", "function is required as first argument") - arity = arity or debug.getinfo(fn, "u").nparams - if arity < 2 then - return fn - end - - return function(...) - local args = { ... } - - if #args >= arity then - return fn(table.unpack(args)) - else - return utils.curry(function(...) - return fn(table.unpack(args), ...) - end, arity - #args) - end - end -end - ---- Concat two Array Tables. ---- @param a table ---- @param b table -utils.concat = utils.curry(function(a, b) - assert(type(a) == "table", "first argument should be a table that is an array") - assert(type(b) == "table", "second argument should be a table that is an array") - assert(isArray(a), "first argument should be a table") - assert(isArray(b), "second argument should be a table") - - local result = {} - for i = 1, #a do - result[#result + 1] = a[i] - end - for i = 1, #b do - result[#result + 1] = b[i] - end - return result -end, 2) - ---- reduce applies a function to a table ---- @param fn function ---- @param initial any ---- @param t table -utils.reduce = utils.curry(function(fn, initial, t) - assert(type(fn) == "function", "first argument should be a function that accepts (result, value, key)") - assert(type(t) == "table" and isArray(t), "third argument should be a table that is an array") - local result = initial - for k, v in pairs(t) do - if result == nil then - result = v - else - result = fn(result, v, k) - end - end - return result -end, 3) - ---- @param fn function ---- @param data table -utils.map = utils.curry(function(fn, data) - assert(type(fn) == "function", "first argument should be a unary function") - assert(type(data) == "table" and isArray(data), "second argument should be an Array") - - local function map(result, v, k) - result[k] = fn(v, k) - return result - end - - return utils.reduce(map, {}, data) -end, 2) - ---- @param fn function ---- @param data table -utils.filter = utils.curry(function(fn, data) - assert(type(fn) == "function", "first argument should be a unary function") - assert(type(data) == "table" and isArray(data), "second argument should be an Array") - - local function filter(result, v) - if fn(v) then - table.insert(result, v) - end - return result - end - - return utils.reduce(filter, {}, data) -end, 2) - ---- @param fn function ---- @param t table -utils.find = utils.curry(function(fn, t) - assert(type(fn) == "function", "first argument should be a unary function") - assert(type(t) == "table", "second argument should be a table that is an array") - for _, v in pairs(t) do - if fn(v) then - return v - end - end -end, 2) - ---- @param propName string ---- @param value string ---- @param object table -utils.propEq = utils.curry(function(propName, value, object) - assert(type(propName) == "string", "first argument should be a string") - -- assert(type(value) == "string", "second argument should be a string") - assert(type(object) == "table", "third argument should be a table") - - return object[propName] == value -end, 3) - ---- @param data table -utils.reverse = function(data) - assert(type(data) == "table", "argument needs to be a table that is an array") - return utils.reduce(function(result, v, i) - result[#data - i + 1] = v - return result - end, {}, data) -end - ---- @param ... function -utils.compose = utils.curry(function(...) - local mutations = utils.reverse({ ... }) - - return function(v) - local result = v - ---@diagnostic disable-next-line - for _, fn in pairs(mutations) do - assert(type(fn) == "function", "each argument needs to be a function") - result = fn(result) - end - return result - end -end, 2) - ---- @param propName string ---- @param object table -utils.prop = utils.curry(function(propName, object) - return object[propName] -end, 2) - ---- @param val any ---- @param t table -utils.includes = utils.curry(function(val, t) - assert(type(t) == "table", "argument needs to be a table") - return utils.find(function(v) - return v == val - end, t) ~= nil -end, 2) - --- @param t table utils.keys = function(t) assert(type(t) == "table", "argument needs to be a table") @@ -179,26 +13,10 @@ utils.keys = function(t) return keys end ---- @param t table -utils.values = function(t) - assert(type(t) == "table", "argument needs to be a table") - local values = {} - for _, value in pairs(t) do - table.insert(values, value) - end - return values -end - function utils.hasMatchingTag(tag, value) return Handlers.utils.hasMatchingTag(tag, value) end ----@param msg AoMessage -function utils.reply(msg) - ---@diagnostic disable-next-line - Handlers.utils.reply(msg) -end - --- Deep copies a table --- @param original table The table to copy --- @return table|nil The deep copy of the table or nil if the original is nil @@ -399,7 +217,7 @@ end --- @param handlers Handlers --- @description Get the names of all handlers ---- @return table +--- @return string[] function utils.getHandlerNames(handlers) local names = {} for _, handler in ipairs(handlers.list) do @@ -485,7 +303,7 @@ function utils.createActionHandler(action, msgHandler, position) return utils.createHandler("Action", action, msgHandler, position) end ----@param keywords table +---@param keywords string[] ---@description Validates the keywords ---Amount of keywords must be less than or equal to 16 ---Each keyword must be a unique string of 32 characters or less