Expose — the AtomForge character as a customs officer clearing declared crates

@atom-forge/expose · Server output

Nothing leaves unless it is declared.

Expose decides what a server sends to the client. A view names every field that may go out; everything else stays behind—including the column someone adds to the table next month. The compiler knows the exact shape of what left.

Allow-list TypeScript No dependencies Any database

What it is

An allow-list, not a filter.

A view is a plain function: it receives the source row and returns the part it is responsible for, naming every field. expose runs one or more views on a row and merges their parts; compose joins views into a reusable one; fieldsOf builds views for fields copied as they are.

Because a view is just a function, Expose works with any database layer and any transport. It pairs naturally with AtomForge RPC: RPC carries the data, Expose decides what goes into it.

Why choose Expose?

Safe by default

A field reaches the client only when a view names it. New columns, password hashes and internal flags stay on the server until someone deliberately adds them.

Exact output types

The result type contains only the named fields. Reading output.passwordHash is a compile error, not a runtime surprise.

Composable views

Build small views per concern—identity, contact, links—and compose them into the shapes each endpoint needs. A later view can extend a key instead of replacing it.

Missing rows handled

null and undefined become null without running a view, so optional relations need no extra check at the call site.

How it works

  1. Write views

    Use fieldsOf for plain fields and write a view by hand for computed or nested data. Never spread the source row.

  2. Gather them

    Keep the views per entity in their own files and collect them into a plain views object.

  3. Expose at the boundary

    Check permissions first, then return expose(row, views.user.card) instead of the raw row.

An honest fit check

Trade-offs, not fine print

It cannot see what you skip

The library cannot stop code from returning a row without calling it. A project that needs this guarantee adds its own guard test.

A view is not a permission check

A view says what goes out, not who may get it. Authorization still happens before the call.

Discipline inside views

Spreading the source or returning a nested row as it is lets everything out. Run nested data through its own view.

In practice

Only named fields go out

From the Expose documentation. passwordHash is neither in the result nor on its type.

TypeScript · Illustrative · adapted from the source texts; package API not verified here
import { compose, expose } from '@atom-forge/expose';

const identity = (source: { id: string; name: string }) => ({ id: source.id, name: source.name });
const contact = (source: { email: string }) => ({ email: source.email });
const card = compose(identity, contact);

const row = { id: 'u1', name: 'Ada', email: 'ada@example.com', passwordHash: 'secret' };

expose(row, card);
// { id: 'u1', name: 'Ada', email: 'ada@example.com' }

Name plain fields with fieldsOf

The type lists what may go out by name; the call picks the fields. Never pass it names that come from a request.

TypeScript · Illustrative · adapted from the source texts; package API not verified here
import { expose, fieldsOf } from '@atom-forge/expose';

type PublicUser = { id: string; name: string; email: string };
const fields = fieldsOf<PublicUser>();

expose(row, fields('id', 'name'));
// { id: 'u1', name: 'Ada' }