Runtime data validation
luastra/dataBuilds composable runtime schemas for values that static Luau types cannot trust, then returns structured success or failure from decoding. Nested object and array schemas retain an exact path to invalid data.
Create schemas once near the application boundary and decode values arriving from forms, storage, locations, or servers before assigning them to typed state.
Schemas validate runtime data; they do not replace useful Luau annotations inside trusted application code.
Complete example
local Data = require("luastra/data")
local profileSchema = Data.object({
name = Data.string({ minBytes = 1, maxBytes = 80, trim = true }),
score = Data.number({ integer = true, min = 0 }),
})
local result = Data.decode(profileSchema, unknownValue)
if result.success then
profile = result.value
else
validationMessage = result.error.code .. " at " .. result.error.path
end