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

@microverse.ts/host-surface

v0.3.0

Published

Fluent host surface DSL: Zod bridges, capability checks, component hooks, and LuaDefManifest for runtime + LuaLS stubs.

Readme

@microverse.ts/host-surface

Declare a host surface in TypeScript: Zod schemas, capabilities, component types, and handlers that compile into:

  1. Runtime bridge tables for mergeEnv (what Lua calls at execution time).
  2. A LuaDefManifest for @microverse.ts/lua-defs (.d.lua stubs for LuaLS).

Most applications import defineHostSurfaceFor from @microverse.ts/microverse-lua instead of this package directly. Use @microverse.ts/host-surface when you need HostScriptSession or custom runtime wiring.

Monorepo overview: root README. Lua microverse lifecycle: @microverse.ts/microverse-lua.

Defining a surface

import { defineHostSurfaceFor } from '@microverse.ts/microverse-lua';
import { z } from 'zod';

export default defineHostSurfaceFor<MyHost>()
  .componentType('OrderEcho', {
    extends: 'AuditOnly',
    capabilities: ['orders:read', 'notifications:send'],
    props: z.object({ label: z.string().optional() }),
    state: z.object({}),
    hooks: ['OrderPlaced'],
  })
  .componentType('AuditOnly', {
    capabilities: ['audit:record'],
    props: z.object({}),
    state: z.object({}),
    hooks: ['OrderPlaced'],
  })
  .bridge('orders')
  .method('get', {
    requires: 'orders:read',
    input: z.object({ orderId: z.string() }),
    output: orderDto,
    description: 'Load order by id',
    handler: ({ host }, { orderId }) => host.orders.get(orderId),
  })
  .componentHooks(componentHooks) // optional
  .build();

| Step | Role | |------|------| | defineHostSurfaceFor<THost>() | Start builder; handler receives typed host. | | .componentType(name, …) | Declares props, state, capability set, and hook subset for Lua Name:extend(). | | .bridge('orders') | Bridge table on self.bridges after OrderEcho:extend() (only bridges allowed by the active type). | | .method('get', { … }) | One bridge method: requires, input, output, handler. | | .componentHooks(…) | Optional Zod map → on* domain events; each type lists which hooks it implements. | | .build() | Compiled {@link HostSurface} with componentTypes registry. |

requires is a domain:action capability string on each bridge method. Each component type lists which capabilities its instances may use; runtime mounts only those bridges/methods on self.bridges. Disallowed bridges are absent (nil in Lua), not denied at call time.

Bridges are not global in the slot: use self.bridges.orders:get(…) from component methods after YourType:extend().

Host object

The host is your engine context (services, repos, config). It is not generated here—you construct it in your app and pass it to MicroverseLua.create({ host, surface }) or HostScriptSession.

Component domain events

Call .componentHooks({ OrderPlaced: z.object({ … }), … }) before .build().

  • TypeScript emits via emitToAllInstances('OrderPlaced', payload).
  • Lua implements onOrderPlaced on the table from OrderEcho:extend() (when that type’s hooks includes OrderPlaced).
  • Manifest emits MicroverseEvt_* payload classes and per-type on* fields on OrderEchoComponent in .d.lua.

Component types and inheritance

| Field | Rule | |-------|------| | capabilities | Union of parent + child (deduplicated). | | props / state | Zod parent.extend(childShape). | | hooks | Union of parent + child hook names. |

extends must reference another type on the same surface. Names must be unique; cycles are rejected at build().

HostScriptSession

Lower-level API when you manage slots yourself (one session = one env slot):

const session = new HostScriptSession({
  runtime,
  surface,
  host,
  slotKey: createLuaEnvSlotKey('script:my-id'),
});
await session.openSession();
await session.runChunk(luaSource); // script must call YourType:extend() first
await session.setProps({ … }); // validated against active type’s props schema

MicroverseLua in @microverse.ts/microverse-lua wraps this for the common case (shared VM, script catalog + instances, broadcast hooks).

Generating .d.lua

microverse generate-lua-defs --surface src/mySurface.ts

Requires export default of the compiled surface (.build() result). The manifest emits, per component type:

  • AuditOnlyProps, AuditOnlyState, AuditOnlyBridges
  • AuditOnlyComponent (with on* only for that type’s hooks)
  • AuditOnly:extend() → AuditOnlyComponent singleton stub

See @microverse.ts/cli and @microverse.ts/lua-defs.

Optional Lua type names on Zod schemas (luaType('OrderDto', z.object({ … }))) improve stub names—see bridge payload patterns in consumer surfaces (e.g. examples/sorting-lab).

Async bridges and Lua patterns

Bridge handlers are synchronous at the Lua boundary; Wasmoon does not auto-resolve Promise into Lua values. For async TypeScript work, use an async handler on the surface; Lua calls the bridge with :await() or an onComplete callback. See:

Reference