Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commitdd348ac6c3

README.md

validate

Pure validator for asset.create opts — checks a creation opts table against the schema produced by asset.createSchema(typeName). Schema in, validated opts (or a teaching error string) out. Consumed by asset.create, which calls M.validate before forwarding opts to the type's onCreate. No FFI, no VFS.

Errors are teaching errors: they state what was wrong at which path (opts.cfg.size), what was expected, and then render the full creation-parameter contract so the caller can fix the call without reading the type's behavior.luau. Unknown parameter names get an edit-distance "did you mean" suggestion.

Types

  • ValidatorShape — { kind, literals?, item?, members?, fields?, indexer? }, the recursive shape encoding.
  • ValidatorParam — { name, shape?, optional?, default?, desc? }.
  • ValidatorSchema — { kind, desc?, example?, open?, error?, params?, indexer? }.

Exports

  • M.validate(schema, opts?) -> (validatedOpts?, err?) — validate and default-fill an opts table against an asset.createSchema result. Returns (validatedOpts, nil) on success (a new table for schema-kind schemas) or (nil, err) where err is a bare teaching error string. The caller owns presentation. Handles the legacy, error, none, and schema schema kinds.
  • M.shapeName(shape) -> string — render a single parameter shape (literal unions as "png" | "jpg", arrays as { T }, tables as table, primitives as their kind, nil/malformed as any). Used by asset.describe.
  • M.renderContract(schema) -> string — render a schema's creation-parameter contract as one aligned line per parameter, with an [extra keys] line for open schemas.

Usage

local V = require("@builtin::assetTypes.assetType.shared.create.validate")
local out, err = V.validate(schema, { bytes = png })
if err then error("asset.create: " .. err) end