Skip to content

@nimir/referencesResolve nested references, type-safely

Declare which fields are IDs, get fully resolved objects back. Batched, deduplicated, cached.

Before

ts
const ticket = await fetchTicket('t-1');

const assignee = ticket.assigneeId ? await fetchUser(ticket.assigneeId) : null;

const watchers = await Promise.all(ticket.watcherIds.map(id => (id ? fetchUser(id) : null)));
// 3 network calls, no batching, no types, repeat per field...

After

ts
const refs = defineReferences(c => ({
  User: c.source<User>({ batch: ids => fetchUsers(ids) }),
}));

const result = await refs.inline(ticket, {
  fields: { assigneeId: 'User', watcherIds: 'User' },
});

result.assigneeIdT; // User | null
result.watcherIdTs; // (User | null)[]
// 1 network call, all IDs batched, fully typed

AI / LLM integration — Machine-readable docs available at llms.txt and ship with the npm package.