Parser Contract
The signature, inputs, outputs, and constraints a conforming parser must satisfy.
Parser Contract
The parser transforms normalized input into a view-specific data model. Physical-format interpretation happens earlier in a Source Adapter; the component downstream should never need to understand the source.
Signature
export default async function parse(input: any, context: any): Promise<unknown>;input— the normalized representation of the source file or source directory selection, shaped according to the capability declared inaccepts. See Capabilities for the exact shape per capability.context— everything else the parser is allowed to know:
{
input, // data normalized by a Source Adapter
source, // declared source metadata, not file handles
settings, // the manifest's settings, merged with any runtime overrides
resources, // resolved paths under resources/
workspace // workspace-level metadata (no arbitrary fs access)
}- Return value — any JSON-serializable data model. This becomes the
dataprop passed to the component.
Example
export default async function parse(input: any, context: any) {
const rows = input.rows ?? [];
const totalSales = rows.reduce((sum: number, row: any) => {
return sum + Number(row.Total ?? row.total ?? 0);
}, 0);
const salesByMonth = rows.map((row: any) => ({
month: row.Month ?? row.month,
total: Number(row.Total ?? row.total ?? 0)
}));
const topClients = [...rows]
.sort((a: any, b: any) => Number(b.Total ?? b.total ?? 0) - Number(a.Total ?? a.total ?? 0))
.slice(0, context.settings?.topClientsLimit ?? 10);
return { totalSales, salesByMonth, topClients };
}Constraints (MUST / MUST NOT)
- The parser MUST NOT read files directly. It only sees the normalized
inputit is handed, even when the source is a directory. - The parser MUST NOT use absolute paths. Any path it produces or consumes is relative.
- The parser MUST be a pure function of
(input, context)— same inputs, same output. No reliance on hidden global or session state. - The parser MUST be re-executable: running it again after the declared source changes should produce an updated, correct data model without manual intervention.
- The parser SHOULD fail with a clear, catchable error rather than throwing something opaque
when
inputdoesn't match what it expects (e.g., an expected column is missing) — the runtime surfaces this to the user with an option to regenerate. - The parser SHOULD verify that
inputcarries the information the view was built for — not merely that it has the declared shape — and fail with the same kind of clear error when it recognizably does not. The runtime guarantees the shape of the normalized input, never its meaning.
What the runtime guarantees the parser
inputhas already been produced by the selected Source Adapter according to the capability the MView declared inaccepts— the parser is not responsible for interpreting raw source bytes.context.sourcedescribes the file or declared directory selection but does not grant filesystem access.context.settingsis the manifest'ssettings, already merged with any user overrides.
Relationship to the component
The parser's return value is opaque to the runtime — it's whatever shape the paired component expects. The Component Contract defines what happens next.
