Mortar — transforms & computed values

Mortar is the small bits of typed logic between bricks — pure functions that reshape data or derive a value. No network (that's what connections are for); just data in, data out.

Transform a response

A response rarely matches a chart's shape. Set a data brick's transform to a small module:

export default (rows, ctx) =>
  rows.map((r) => ({ label: r.region, value: Number(r.total) }));

The transformed value is what gets written to the dataset key.

Compute a value on a brick

For a derived or formatted value on a display brick (Text, Heading, StatCard), set bindCompute:

export default (_, ctx) => `$${ctx.get("revenue").toLocaleString()}`;

ctx.get(key) reads the store; ctx.record is the current record inside a Repeater.

Derived values

Register a derivation that recomputes a key from other keys whenever they change — handy for totals and rollups shared across several bricks.

Mortar is sandboxed and pure — it can't make network calls. Fetch with a connection, then shape with mortar.

SQL transforms (DuckDB)

For joins, aggregations, pivots, and window functions over data already in the page, reach for a SqlTransform brick instead of TS. Point inputs at existing dataset keys (each becomes a table named after its key), write a SELECT, and the result lands at targetKey — recomputing live when an input changes. It runs entirely in the browser via DuckDB-Wasm (no server, no connection):

SELECT region, sum(amount) AS total
FROM orders            -- an existing dataset key, exposed as a table
GROUP BY region
ORDER BY total DESC;

Charts, tables, and graph bricks bind to the transform's targetKey like any other dataset. This is the manipulation sibling of SqlData (which reaches a server database); SqlTransform reshapes data already loaded — including from a local file — with no round-trip, offline.

Next steps