Skip to content

Field Introspection

Schema instances also expose three read-only introspection helpers:

  • schema.getFieldDefinitions() returns a frozen snapshot map of the top-level field definitions.
  • schema.getFieldDefinition(path) resolves one field definition by dotted path, including nested object fields and numeric array segments such as roles.0.id, and returns it as a frozen snapshot.
  • schema.getFieldMessages(path) returns the field's messages object as a frozen snapshot, or {} when none exist.

These helpers are intentionally inspection-only. They clone the schema metadata they expose so adapter code can read field settings without gaining a back door to mutate runtime validation behavior.

Example:

javascript
const roleSchema = createSchema({
  id: { type: 'string', required: true }
})

const teamSchema = createSchema({
  name: { type: 'string', required: true },
  roles: {
    type: 'array',
    items: roleSchema
  }
})

const topLevelDefinitions = teamSchema.getFieldDefinitions()
const roleIdDefinition = teamSchema.getFieldDefinition('roles.0.id')
const roleIdMessages = teamSchema.getFieldMessages('roles.0.id')

In that example:

  • topLevelDefinitions contains snapshots for name and roles
  • roleIdDefinition resolves through the array item schema to the nested id field
  • roleIdMessages returns {} because that field did not define a messages object

Treat the returned objects as metadata for rendering and adapter logic, not as something to mutate.

GPL-3.0-only