npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@inlay/render

v0.0.10

Published

Server-side component resolution for Inlay element trees. Given an element like `<com.example.Greeting name="world">`, the renderer looks up the component implementation, expands it, and recurses until everything is primitives the host can render.

Readme

@inlay/render

Server-side component resolution for Inlay element trees. Given an element like <com.example.Greeting name="world">, the renderer looks up the component implementation, expands it, and recurses until everything is primitives the host can render.

Install

npm install @inlay/render @inlay/core

Example

A minimal Hono server that accepts an element, resolves it through packs, and returns HTML. Uses Hono's JSX for safe output.

/** @jsxImportSource hono/jsx */
import { Hono } from "hono";
import { serve } from "@hono/node-server";
import { $, serializeTree, deserializeTree, isValidElement } from "@inlay/core";
import { render } from "@inlay/render";
import type { RenderContext } from "@inlay/render";

// Records — in-memory stand-in for AT Protocol
const records = {
  // Primitives: no body. The host renders these directly.
  "at://did:plc:host/at.inlay.component/stack": {
    $type: "at.inlay.component", type: "org.atsui.Stack",
  },
  "at://did:plc:host/at.inlay.component/text": {
    $type: "at.inlay.component", type: "org.atsui.Text",
  },

  // Template: a stored element tree with Binding placeholders.
  "at://did:plc:app/at.inlay.component/greeting": {
    $type: "at.inlay.component",
    type: "com.example.Greeting",
    body: {
      $type: "at.inlay.component#bodyTemplate",
      node: serializeTree(
        $("org.atsui.Stack", { gap: "small" },
          $("org.atsui.Text", {}, "Hello, "),
          $("org.atsui.Text", {}, $("at.inlay.Binding", { path: ["name"] })),
        )
      ),
    },
    imports: ["at://did:plc:host/at.inlay.pack/main"],
  },

  // Pack: maps NSIDs → component records
  "at://did:plc:host/at.inlay.pack/main": {
    $type: "at.inlay.pack", name: "host",
    exports: [
      { type: "org.atsui.Stack", component: "at://did:plc:host/at.inlay.component/stack" },
      { type: "org.atsui.Text", component: "at://did:plc:host/at.inlay.component/text" },
      { type: "com.example.Greeting", component: "at://did:plc:app/at.inlay.component/greeting" },
    ],
  },
};

// Resolver — I/O layer that render() calls into
const resolver = {
  async fetchRecord(uri) { return records[uri] ?? null; },
  async xrpc(params) { throw new Error(`No handler for ${params.nsid}`); },
  async resolveLexicon() { return null; },
};

// Primitives → JSX
const primitives = {
  "org.atsui.Stack": async ({ props, ctx }) => {
    const p = props as { gap?: string; children?: unknown[] };
    return (
      <div style={`display:flex;flex-direction:column;gap:${p.gap ?? 0}`}>
        {await renderChildren(p.children, ctx)}
      </div>
    );
  },
  "org.atsui.Text": async ({ props, ctx }) => {
    const p = props as { children?: unknown };
    return <span>{await renderNode(p.children, ctx)}</span>;
  },
};

// Walk loop — resolve elements, render primitives to JSX
async function renderNode(node, ctx) {
  if (node == null) return <></>;
  if (typeof node === "string") return <>{node}</>;
  if (Array.isArray(node)) return <>{await Promise.all(node.map(n => renderNode(n, ctx)))}</>;

  if (isValidElement(node)) {
    const result = await render(node, ctx, { resolver });
    if (result.node === null) {
      // Primitive: host renders using element type + result.props
      const Primitive = primitives[node.type];
      if (!Primitive) return <>{`<!-- unknown: ${node.type} -->`}</>;
      return Primitive({ props: result.props, ctx: result.context });
    }
    return renderNode(result.node, result.context);
  }
  return <>{String(node)}</>;
}

async function renderChildren(children, ctx) {
  if (!children) return <></>;
  const items = Array.isArray(children) ? children : [children];
  return <>{await Promise.all(items.map(c => renderNode(c, ctx)))}</>;
}

// Server
const app = new Hono();

app.get("/", async (c) => {
  const element = deserializeTree({
    $: "$", type: "com.example.Greeting", props: { name: "world" },
  });
  const ctx = { imports: ["at://did:plc:host/at.inlay.pack/main"] };
  const body = await renderNode(element, ctx);
  return c.html(<html><body>{body}</body></html>);
});

serve({ fetch: app.fetch, port: 3000 });

Returns:

<html><body>
  <div style="display:flex;flex-direction:column;gap:small">
    <span>Hello, </span>
    <span>world</span>
  </div>
</body></html>

The com.example.Greeting template expanded its Binding for name, resolved to org.atsui.Stack and org.atsui.Text primitives, and the host turned those into HTML.

In practice

A production host will also want:

  • Persistent global caching keyed by component + props + response cache tags
  • Streaming so slow XRPC calls and record fetches don't block the page
  • Prefetching for links so navigation feels instant

See proto/ for a working implementation with all of the above.

How it works

render() resolves one element at a time. It returns node: null when the element is a primitive (the host renders it using element.type + result.props) or a non-null node tree when the element expanded into a subtree that needs more passes. The walk loop drives this to completion.

  1. Binding resolutionat.inlay.Binding elements in props are resolved against the current scope. The concrete values are available on result.props.
  2. Type lookup — the element's NSID is looked up across the import stack. First pack that exports the type wins.
  3. Component rendering — depends on the component's body:
    • No body — a primitive; returns node: null with resolved props.
    • Template — element tree expanded with prop bindings.
    • External — XRPC call to the component's service. Children are passed as slots and restored from the response.
  4. Error handling — errors throw with componentStack stamped on the error. MissingError propagates for at.inlay.Maybe to catch.

API

| Function | Description | |----------|-------------| | createContext(component, componentUri?) | Create a RenderContext from a component record | | render(element, context, options) | Render a single element. Returns Promise<RenderResult> | | resolvePath(obj, path) | Resolve a dotted path array against an object | | MissingError | Thrown when a binding path can't be resolved |

Render options:

  • resolver: Resolver — I/O callbacks (required)
  • maxDepth?: number — nesting limit (default 30)

Types

  • Resolver{ fetchRecord, xrpc, resolveLexicon }
  • RenderContext{ imports, component?, componentUri?, depth?, scope?, stack? }
  • RenderResult{ node, context, props, cache? }
  • RenderOptions{ resolver, maxDepth? }
  • ComponentRecord — re-exported from generated lexicon defs
  • CachePolicy — re-exported from generated lexicon defs