-- Compiled with roblox-ts v1.2.7 local TS = _G[script] local LogLevel = TS.import(script, TS.getModule(script, "@rbxts", "log").out).LogLevel local RunService = TS.import(script, TS.getModule(script, "@rbxts", "services")).RunService local ZrLuauFunction = TS.import(script, TS.getModule(script, "@rbxts", "zirconium").out.Data.LuauFunction).default local Server = TS.import(script, script.Parent.Parent, "Server").default local ZirconContext = TS.import(script, script.Parent, "ZirconContext").ZirconContext local zirconTypeOf local function emitArgumentError(func, context, arg, index, validator) local _errorMessage = validator.ErrorMessage local err = type(_errorMessage) == "function" and validator.ErrorMessage(arg, index, func) or validator.ErrorMessage -- Have to dynamically import if zirconTypeOf == nil then zirconTypeOf = TS.Promise.new(function(resolve) resolve(TS.import(script, script.Parent.Parent, "Shared", "typeId")) end):expect().zirconTypeOf end local _fn = Server.Log local _object = { SourceContext = "(function '" .. (func:GetName() .. "')"), Level = LogLevel.Error, } local _left = "Template" local _condition = err if _condition == nil then _condition = "Expected {ValidatorType}, got {ArgType}" end _object[_left] = "Argument #{ArgIndex} to '{FunctionName}': " .. _condition _object.Timestamp = DateTime.now():ToIsoDate() _object.FunctionName = func:GetName() _object.FunctionArgs = func:GetArgumentTypes() _object.FunctionVariadicArg = func:GetVariadicType() _object.LogToPlayer = context:getExecutor() _object.ArgIndex = index + 1 _object.ValidatorType = validator.Type _object.ArgType = zirconTypeOf(arg) _fn.WriteStructured(_object) end local ZirconFunction do local super = ZrLuauFunction ZirconFunction = setmetatable({}, { __tostring = function() return "ZirconFunction" end, __index = super, }) ZirconFunction.__index = ZirconFunction function ZirconFunction.new(...) local self = setmetatable({}, ZirconFunction) return self:constructor(...) or self end function ZirconFunction:constructor(name, zirconCallback, metadata) self.name = name self.zirconCallback = zirconCallback self.metadata = metadata local _binding = metadata local VariadicValidator = _binding.VariadicValidator local ArgumentValidators = _binding.ArgumentValidators super.constructor(self, function(context, ...) local args = { ... } -- We'll need to type check all the arguments to ensure they're valid -- and transform as appropriate for the user side local executor = context:getExecutor() local transformedArguments = {} if #ArgumentValidators > 0 then do local i = 0 local _shouldIncrement = false while true do if _shouldIncrement then i += 1 else _shouldIncrement = true end if not (i < #ArgumentValidators) then break end local validator = ArgumentValidators[i + 1] local argument = args[i + 1] if validator and validator:Validate(argument, executor) then if validator.Transform ~= nil then transformedArguments[i + 1] = validator:Transform(argument, executor) else transformedArguments[i + 1] = argument end else if RunService:IsServer() then emitArgumentError(self, context, argument, i, validator) end return nil end end end elseif not VariadicValidator then transformedArguments = args end if #args > #ArgumentValidators and VariadicValidator then do local i = #ArgumentValidators local _shouldIncrement = false while true do if _shouldIncrement then i += 1 else _shouldIncrement = true end if not (i < #args) then break end local argument = args[i + 1] if VariadicValidator:Validate(argument, executor) then if VariadicValidator.Transform ~= nil then transformedArguments[i + 1] = VariadicValidator:Transform(argument, executor) else transformedArguments[i + 1] = argument end else if RunService:IsServer() then emitArgumentError(self, context, argument, i, VariadicValidator) end return nil end end end end -- / This is not pretty, I know. return self.zirconCallback(ZirconContext.new(context, self), unpack(transformedArguments)) end) end function ZirconFunction:GetName() return self.name end function ZirconFunction:GetArgumentTypes() local _binding = self.metadata local ArgumentValidators = _binding.ArgumentValidators local _arg0 = function(v) return v.Type end -- ▼ ReadonlyArray.map ▼ local _newValue = table.create(#ArgumentValidators) for _k, _v in ipairs(ArgumentValidators) do _newValue[_k] = _arg0(_v, _k - 1, ArgumentValidators) end -- ▲ ReadonlyArray.map ▲ local args = _newValue return args end function ZirconFunction:GetVariadicType() local _binding = self.metadata local VariadicValidator = _binding.VariadicValidator local _result = VariadicValidator if _result ~= nil then _result = _result.Type end return _result end function ZirconFunction:RegisterToContext(context) context:registerGlobal(self.name, self) end function ZirconFunction:GetDescription() return self.metadata.Description end function ZirconFunction:toString() local _exp = self:GetArgumentTypes() local _arg0 = function(typeName, argIndex) return typeName end -- ▼ ReadonlyArray.map ▼ local _newValue = table.create(#_exp) for _k, _v in ipairs(_exp) do _newValue[_k] = _arg0(_v, _k - 1, _exp) end -- ▲ ReadonlyArray.map ▲ local argTypes = _newValue local varadicType = self:GetVariadicType() if varadicType ~= nil then local _arg0_1 = "..." .. varadicType -- ▼ Array.push ▼ argTypes[#argTypes + 1] = _arg0_1 -- ▲ Array.push ▲ end return (self.metadata.Description ~= nil and "/* " .. (self.metadata.Description .. " */") or "") .. (" function " .. (self.name .. "(")) .. table.concat(argTypes, ", ") .. ") { [ZirconFunction] }" end function ZirconFunction:__tostring() return self:toString() end end return { emitArgumentError = emitArgumentError, ZirconFunction = ZirconFunction, }