Skip to content

Types ​

Shared type definitions for the Mayari ecosystem. Use them in your handlers, middleware, and libraries to follow Mayari's type contracts.

Installation ​

bash
embr add mayari/types
embr i

Setup ​

Projects generated by mayari-cli ​

The CLI sets up the type definitions for you, so the types are available globally. You do not need to require them.

Projects created manually ​

If you created the project structure yourself, require the library where you need it:

lua
local types = require("types")

You can also set up the type definitions yourself so the types appear globally, as mayari-cli does.

Available types ​

  • Request
  • Request<T> (a request with a typed body, params, and query)
  • Middleware
  • Handler
  • Next
  • ResponsePayload
  • ResponseOptions
  • ValidatorSchema

Example: writing a typed Guard rule ​

lua
local types = require("types")

local myToken = "foe"

local function AuthRule(req: types.Request)
    local token = req.headers and req.headers["authorization"]

    if not token or token ~= myToken then
        return false
    end

    return true
end

return AuthRule