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

@rank-lang/server-runtime

v0.3.1

Published

Rank server runtime workspace package

Readme

@rank-lang/server-runtime

Helpers for loading and validating Rank server entrypoints.

Full documentation →

Install

npm install @rank-lang/server-runtime

API

loadRankServerApp(entry, cwd?, options?)

Loads a Rank entry module through @rank-lang/compiler, validates the server-specific exports, and returns either:

  • { ok: true, app }
  • { ok: false, diagnostic }

Validation rules:

  • pub main must exist
  • pub main must be a function value
  • pub main must accept zero or one parameters
  • when pub main accepts one parameter, it must be typed as std::Runtime::ExecutionContext<Routes>
  • optional pub config must be an object literal or zero-argument function

The success result contains:

  • entryPath: resolved absolute entry path
  • moduleGraph: loaded compiler module graph configured for serve-time evaluation
  • hasConfig: whether pub config was present
  • mainDeclaration: validated pub main declaration
  • configDeclaration: validated pub config declaration when present

prepareServeRuntime(options)

Normalizes host and port options, loads the server app, and returns either:

  • { ok: true, runtime, note }
  • { ok: false, diagnostic }

runtime exposes:

  • app: the loaded RankServerApp
  • host, port: resolved listener coordinates
  • shutdownGracePeriodMs: resolved grace period (ms)
  • defaultResponseFormat: resolved response format from pub config
  • maxRequestBodyBytes: resolved body size limit from pub config
  • requestTimeoutMs: resolved request deadline from pub config
  • dispatch(request): dispatch a ServeRequestInput and get a ServeDispatchResult
  • close(): shut down provider runtime state

ServeRequestInput shape:

  • method: HTTP method string
  • path: request path
  • headers?: header map
  • body?: raw request body string
  • remoteAddress?: client IP
  • requestId?: forwarded to req.ctx.request_id
  • timeReceived?: forwarded to req.ctx.time_received

ServeDispatchResult shape: { status, headers, body }.

Options (ServeRuntimeOptions):

  • entry: path to the .rank server entrypoint
  • cwd?: working directory for resolving entry (default: process.cwd())
  • host?: bind host (default: localhost)
  • port?: bind port (default: 0, OS-assigned)
  • shutdownGracePeriodMs?: drain timeout before force-close. Defaults to 30_000
  • dev?: enable verbose error detail strings in runtime-generated responses
  • frozenLockfile?: fail if provider lockfile would be updated
  • offline?: disable network access during provider resolution
  • providerCapabilities?: override allowed provider capabilities
  • allowedHttpHosts?: override allowed outbound HTTP hosts
  • allowedEnvPatterns?: override allowed env var patterns
  • providerTimeoutMs?: override provider invocation timeout

startServeRuntime(options)

Accepts the same options as prepareServeRuntime. Starts a Node HTTP listener and returns either:

  • { ok: true, runtime, note }
  • { ok: false, diagnostic }

runtime extends PreparedServeRuntime with:

  • server: the bound Node HTTP server
  • url: the bound listener URL
  • stop(): stops accepting new connections, closes idle keep-alives, waits up to shutdownGracePeriodMs, then force-closes remaining connections before shutting down provider runtime state

Current execution scope:

  • exact method/path route matching plus match-prefixed path params
  • synthesized 404 and 405 before handler execution
  • HTTP::AppConfig.allowedOrigins / allowCredentials synthesize CORS preflight OPTIONS responses and attach matching CORS headers to ordinary responses for admitted origins; maxRequestBodyBytes caps request body size (default 1_048_576)
  • route-local query, JSON body, header, and cookie validation before handler execution
  • route-local API-key auth execution for named routes whose executable auth metadata is supplied inline on HTTP::ApiKeyAuth<T> { ... }; same-named value binding probing remains available as a compatibility fallback
  • req.params, req.query, req.body, req.headers, req.cookies, and req.ctx.request_id / req.ctx.time_received materialization
  • authenticated routes also materialize req.auth after successful verifier execution
  • response serialization for json, yaml, and text
  • compatible explicit content-type overrides are preserved; conflicting ones fail with a structured runtime error
  • ordinary redirect responses work through status plus location headers with no special helper type
  • manual set-cookie headers are rejected when typed cookies output is also present
  • request deadlines are enforced through requestTimeoutMs
  • options.dev === true adds verbose detail strings to runtime-generated validation and request-shape error responses while keeping opaque internal 500s unchanged
  • graceful shutdown stops accepting new connections, closes idle keep-alives, rejects late-arriving requests with a structured 503 once draining begins, and force-closes remaining connections after shutdownGracePeriodMs
  • the host exposes a reserved readiness endpoint at /.well-known/rank/ready, returning 200 { ok: true, state: "ready" } while serving and 503 RUNTIME_DRAINING once shutdown has begun
  • zero-arg pub config Env<T> {} reads are filtered through the admitted allow-env view before listener startup
  • undeclared incoming headers and cookies are ignored unless the route contract declares a rest field
  • bare allow-env = ["*"] emits a visible startup warning before serving begins

Example

import { startServeRuntime } from "@rank-lang/server-runtime";

const started = await startServeRuntime({
  entry: "src/server.rank",
  port: 3000,
});

if (!started.ok) {
  throw new Error(started.diagnostic);
}

console.log(started.note);
await started.runtime.stop();

Development

npm run build -w @rank-lang/server-runtime
npm run test -w @rank-lang/server-runtime
npm run typecheck -w @rank-lang/server-runtime

Publishing

Build the package first, then publish from the workspace root:

npm run build -w @rank-lang/server-runtime
npm publish -w @rank-lang/server-runtime