Output fields
Declare typed output fields and validate handler results.
Output fields
Each leaf declares an output object. Field object keys are returned verbatim in the result object, so appId stays appId; unlike command and parameter keys, output keys are not converted to kebab case.
| Builder | Required handler value |
| --- | --- |
| field.string(constraint, options?) | string |
| field.int(constraint, options?) | integer number |
| field.number(constraint, options?) | number |
| field.bool(constraint, options?) | boolean |
| field.object(constraint, options?) | object |
| field.array(constraint, options?) | array |
| field.markdown(constraint, options?) | string |
| field.path(constraint, options?) | string |
| field.of(type, constraint, options?) | unknown |
| field.nullable(field) | the wrapped field value or null |
Fields are required by default. Pass { required: false } for a field that can be absent. field.nullable(field.string('...')) declares a present field that can be string | null; it does not make the field optional.
The handler result type is inferred from output. TypeScript reports a missing required field or a wrong value type at the defineLeaf call. The Fetch handler checks the returned object again before sending it. It rejects missing fields, known type mismatches, and keys that were not declared, returning a non-2xx handler_output_invalid error instead of a JSON success response.
field.of accepts any non-empty manifest type string. Its handler value is unknown because crtr only has built-in runtime checks for its recognized type grammar. Use one of the named builders when the result type is known.