← Runtime data validation

Data.Schema

luastra/data

Data.Schema is an exported, statically checked data contract of luastra/data. Its exact declaration documents the fields or alternatives accepted at the module boundary and is erased after Luau analysis.

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

The exported type describes schemas or the tagged success/failure result returned by Data.decode.

When to use it

Use Data.Schema when annotating values that cross the public luastra/data boundary or when exporting helpers built on that module. The type documents the exact checked shape and prevents unrelated tables from being substituted accidentally.

Fields or definition

ParameterType / valuesDescription
kindstringLiteral discriminator identifying the exact alternative in this union.
optionalboolean?Checked optional field of Data.Schema; its exact admitted type is boolean?.
options{ [string]: any }?Checked options field of Data.Schema; its exact admitted type is { [string]: any }?.
itemSchema?Checked item field of Data.Schema; its exact admitted type is Schema?.
fields{ [string]: Schema }?Validated bounded field map carried by the decoded or migrated value.

What happens next

A checked schema/result annotation.

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.

Exact declaration

export type Schema = {
    kind: string,
    optional: boolean?,
    options: { [string]: any }?,
    item: Schema?,
    fields: { [string]: Schema }?,
}

Complete inventory

View all pages in Runtime data validation
← Previous: Data.ObjectOptionsNext: Data.string →