withAccessors
functionReturn a copy of `schema` that records both accessor names at once, which is the common case for a property whose node methods do not follow the default `get<Prop>`/`set<Prop>` naming. Either direction may be omitted to keep the conventional name for that one. **This and withField go outside every other combinator**, because an accessor answers for the property as a whole and each combinator widens what the property holds: `nullable` admits `null`, `optional` admits an absent value, `transformValue` produces a type of its own, and a union produces any member's. `nullable(withAccessors(stringValue(), {setter: 'setLabel'}))` obliged `setLabel` to take a `string` while the parser hands it `null` for a document that omits the property. Written the other way round — `withAccessors(nullable(stringValue()), {setter: 'setNullableLabel'})` — the obligation is stated for what the property really parses to, and the compiler checks it. Exactly once per property: a second layer would name a direction the first already named, and the walk calls only the outer one — an obligation checked for an accessor that is never called — so both directions are named in one call, and every combinator, this one included, refuses a schema that already names an accessor. A development build holds the rule at run time too, for a caller the types do not reach.
Import
import { withAccessors } from '@modular/sdk/editor';Notes
- example
- ```ts nodeSchema<TextNode>()({ text: withAccessors(stringValue(), { getter: 'getTextContent', setter: 'setTextContent', }), }); ```
- __NO_SIDE_EFFECTS__