Skip to main content

SchemaGetterField

interface

A node field read directly on export.

interface SchemaGetterField

Import

import { SchemaGetterField } from '@modular/sdk/editor';

Members5

field
string
getterTableoptional
{ readonly [key: string]: unknown; }

A lookup table from the stored field value to the serialized one, for a property whose two representations differ — TextNode stores `mode` as a bitmask and serializes it as a name. Without this such a property needs an accessor method, and a method is a call plus, by convention, a `getLatest()`. Stating the mapping keeps the property on the direct-read path: the table is a plain object of primitives, so it is as inlinable by a code generator as the field read is. The export direction's table; SchemaSetterField.setterTable is its import mirror. Each is declared only on the direction that reads it, so naming the wrong one is a type error rather than a silently ignored property.

methodoptional
string

The accessor method this direct field access stands in for, when it is not the conventional `get<Prop>`/`set<Prop>` for the property. Naming one keeps a subclass in charge of its own property: if any class between the one that declared this field and the node's own class overrides that method, the field access is abandoned and the method is called instead. Leaving it out defers to the conventional name, which is what nearly every property wants — a node that predates its schema already has those accessors, and overriding `getStyle()` on a TextNode subclass is ordinary, so migrating a property to a field must not silently take that back. Name one only when the accessor is spelled differently, as TextNode's `text` is (`getTextContent`) and LinkNode's `url` is (`getURL`). A class with no such method defers to nothing, since both prototypes then resolve `undefined`.

setterTableoptional
never

Declared as `never` rather than left out: an excess property is only rejected for a fresh object literal, and these accessors are captured by an inferred type parameter (so the schema can carry the names it declares), which is not fresh. Stating the wrong direction's table as `never` rejects it by assignability instead, which inference cannot launder away.

whenoptional
string

The name of a node predicate that decides whether this property is written at all. Naming it keeps the property on the direct-field path: without it, a conditionally-persisted property needs an accessor method, and a method is a call plus a `getLatest()` on every export of every node. The property is written only when its value differs from the schema default *and* the predicate returns true — the default is what parsing would restore anyway, so writing it says nothing, and testing it first is what keeps the predicate off the common path. ElementNode's `textFormat` and `textStyle` are the motivating case: both are persisted only for an element with no TextNode child. The predicate must be a pure, zero-argument method: it is called once per export by the walk for each property that names it, and once in total by generated code, which hoists a predicate that several properties share. Like the field read it gates, this is what SchemaFieldBase.method stands in for: a subclass that overrides that accessor abandons the field *and* the predicate, because a method that replaces the read replaces the decision to make it.