← Runtime data validation

Data.object

luastra/data
Data.object(fields: { [string]: Schema }, optionsValue: ObjectOptions?): Schema

Builds a schema for a table with named fields, validating each field through its own child schema and applying the object options for unknown keys. Nested schemas preserve a structured path to every failure.

Before you use it

Add luastra/data to this module's dependencies in luastra.json, then import it with require("luastra/data"). No host capability is required. Define schemas outside render when they are reused.

How it fits

This pure constructor returns an immutable schema synchronously; Data.decode performs the actual validation later.

When to use it

Use Data.object at storage, server, or form boundaries where several named values must be accepted together. Declare all trusted fields explicitly and decide deliberately whether unknown fields should be rejected.

Parameters

ParameterType / valuesDescription
fields{ [string]: Schema }Map from each admitted field name to the schema that validates its value.
optionsValueObjectOptions?Optional policy controlling object validation, including unknown fields.
optionsValue.exactboolean?Rejects undeclared keys unless explicitly set to false; defaults to true.

Returns

Schema — an immutable runtime schema that can be composed or passed to Data.decode.

What happens next

An immutable schema ready to compose or pass to Data.decode.

Failures and fixes

Ordinary invalid input is a Data.decode failure, not an exception. Invalid schema options are programmer errors and fail immediately. String bounds count UTF-8 bytes; Data.string has no pattern option in this alpha.

Availability

Public-source alpha API in 0.5.0-alpha; host-independent and synchronous.

Focused example

local Data = require("luastra/data")
local form = Data.object({ name = Data.string { minBytes = 1 }, active = Data.boolean() })

Continue learning

Prerequisites

Data.booleanData.string

Complete inventory

View all pages in Runtime data validation
← Previous: Data.arrayNext: Data.optional →