docs: update portal for WRNexusJS 0.4.0
This commit is contained in:
@@ -10,11 +10,11 @@ page wrnexusrouter {
|
||||
<header class="topbar">
|
||||
<a class="brand" href="/"><span>W</span> WRNexusJS</a>
|
||||
<nav aria-label="Primary"><a href="/getting-started">Get started</a><a href="/packages">Packages</a><a href="/components">Components</a><a href="/language">Language</a><a href="/architecture">Architecture</a></nav>
|
||||
<div class="topbar-actions"><a class="preview-pill" href="/access">Private preview · v0.3.6</a><button data-wire-theme-toggle class="theme-button" aria-label="Toggle color theme" title="Toggle color theme">◐</button></div>
|
||||
<div class="topbar-actions"><a class="preview-pill" href="/access">Private preview · v0.4.0</a><button data-wire-theme-toggle class="theme-button" aria-label="Toggle color theme" title="Toggle color theme">◐</button></div>
|
||||
</header>
|
||||
<div class="mobile-doc-nav"><details><summary>Browse documentation</summary><nav><a href="/getting-started">Get started</a><a href="/packages">Packages</a><a href="/components">Components</a><a href="/language">Language</a><a href="/architecture">Architecture</a><a href="/tutorial">Tutorial</a><a href="/guides/project-structure">Guides</a><a href="/examples">Examples</a><a href="/search">Search</a></nav></details></div>
|
||||
<main class="portal-main docs-layout">
|
||||
<article id="main" class="documentation prose standalone package-document"><nav class="breadcrumbs" aria-label="Breadcrumb"><a href="/">Home</a><span>/</span><a href="/packages">Packages</a><span>/</span><span aria-current="page">@wrnexus/router</span></nav><section class="doc-intro"><span class="eyebrow">Core · Package reference</span><h1>@wrnexus/router</h1><p>Filesystem discovery, route matching, and typed route generation.</p><div class="doc-meta"><span>v0.3.6</span><span>Private registry</span><span>Core</span></div><section id="access" class="access-callout"><h2>Install the package</h2><p>After WorkRoot approves private registry access, install the release-aligned package:</p><pre><code>bun add @wrnexus/router@0.3.6</code><button type="button" class="copy-button" aria-label="Copy installation command">Copy</button></pre><p><a href="/access">Request preview access</a>. Never put registry tokens in source control.</p></section></section><section id="guide"><blockquote>File-based router that maps an <code>app/</code> directory onto route tables and matches request paths against them.</blockquote>
|
||||
<article id="main" class="documentation prose standalone package-document"><nav class="breadcrumbs" aria-label="Breadcrumb"><a href="/">Home</a><span>/</span><a href="/packages">Packages</a><span>/</span><span aria-current="page">@wrnexus/router</span></nav><section class="doc-intro"><span class="eyebrow">Core · Package reference</span><h1>@wrnexus/router</h1><p>Filesystem discovery, route matching, and typed route generation.</p><div class="doc-meta"><span>v0.4.0</span><span>Private registry</span><span>Core</span></div><section id="access" class="access-callout"><h2>Install the package</h2><p>After WorkRoot approves private registry access, install the release-aligned package:</p><pre><code>bun add @wrnexus/router@0.4.0</code><button type="button" class="copy-button" aria-label="Copy installation command">Copy</button></pre><p><a href="/access">Request preview access</a>. Never put registry tokens in source control.</p></section></section><section id="guide"><blockquote>File-based router that maps an <code>app/</code> directory onto route tables and matches request paths against them.</blockquote>
|
||||
<p>Part of the <strong>WRNexusJS</strong> framework — an SSR-first, Bun-native full-stack web framework.</p>
|
||||
<h3 id="overview">Overview</h3>
|
||||
<p><code>@wrnexus/router</code> scans an application's <code>app/</code> directory once at startup and builds route tables for pages, API endpoints, realtime channels, middleware, server-rendered <code>.wrn</code> components, layouts, and validation schemas. It also compiles URL patterns (<code>/users/[id]</code>) into RegExps and matches request paths against them. Request input is never turned into a file path, which makes the router immune to path traversal. This is a server-side package used by the WRNexusJS runtime to resolve incoming requests, plus a codegen helper for compile-time typed links.</p>
|
||||
@@ -187,6 +187,23 @@ declare function matchRoute(routes: Route[], pathname: string): RouteMatch | nul
|
||||
|
||||
declare function generateRoutesFile(pages: Route[]): string;
|
||||
|
||||
interface NamedRoute extends Route {
|
||||
name: string;
|
||||
metadata?: Record<string, unknown>;
|
||||
}
|
||||
interface RouteManifestEntry {
|
||||
name: string;
|
||||
path: string;
|
||||
file: string;
|
||||
params: ReturnType<typeof getRouteParams>;
|
||||
metadata?: Record<string, unknown>;
|
||||
}
|
||||
declare function routeName(raw: string): string;
|
||||
declare function nameRoutes(routes: readonly Route[], metadata?: Record<string, Record<string, unknown>>): NamedRoute[];
|
||||
declare function createRouteManifest(routes: readonly NamedRoute[]): RouteManifestEntry[];
|
||||
declare function routeUrl(route: Pick<NamedRoute, "raw" | "paramMeta">, params?: Record<string, string | number | Array<string | number> | null | undefined>, query?: Record<string, string | number | boolean | null | undefined>): string;
|
||||
declare function findNamedRoute(routes: readonly NamedRoute[], name: string): NamedRoute;
|
||||
|
||||
/**
|
||||
* @wrnexus/router — file-based router.
|
||||
*
|
||||
@@ -199,7 +216,7 @@ declare function generateRoutesFile(pages: Route[]): string;
|
||||
* app/pages/*.wrn api -> embedded /api/* routes
|
||||
* app/pages/*.wrn realtime -> embedded /realtime/* routes
|
||||
* app/middleware/*.ts -> global middleware (alphabetical)
|
||||
* app/components/*.wrn -> server-rendered components (by basename),
|
||||
* app/components/*.wrn -> server-rendered components (by declaration),
|
||||
* mounted in a page via data-component="<name>"
|
||||
*/
|
||||
|
||||
@@ -225,12 +242,22 @@ interface Router {
|
||||
matchApi(pathname: string): RouteMatch | null;
|
||||
matchRealtime(pathname: string): RouteMatch | null;
|
||||
}
|
||||
interface ExternalRouteDefinition {
|
||||
kind: "page" | "api" | "realtime";
|
||||
path: string;
|
||||
entry: string;
|
||||
name?: string;
|
||||
}
|
||||
interface RouterOptions {
|
||||
/**
|
||||
* Extra directories to scan for `.wrn` components (e.g. `@wrnexus/ui`).
|
||||
* Scanned before `app/components`, so an app component of the same name wins.
|
||||
*/
|
||||
componentDirs?: string[];
|
||||
/** Package-owned routes registered by the plugin contribution system. */
|
||||
externalRoutes?: ExternalRouteDefinition[];
|
||||
/** Package-owned middleware executed before app/middleware. */
|
||||
middlewareFiles?: string[];
|
||||
}
|
||||
/**
|
||||
* Convert a scanned file's relative path into a URL route pattern.
|
||||
@@ -242,7 +269,7 @@ declare function fileToRoute(rel: string, prefix?: string): string;
|
||||
/** Scan an app directory and build all route tables. */
|
||||
declare function buildRouter(appDir: string, opts?: RouterOptions): Router;
|
||||
|
||||
export { type ComponentRef, type Route, type RouteMatch, type Router, type RouterOptions, buildRouter, compileRoutePattern, fileToRoute, findRouteConflicts, generateRoutesFile, getRouteParams, matchRoute, sortRoutes };
|
||||
export { type ComponentRef, type ExternalRouteDefinition, type NamedRoute, type Route, type RouteManifestEntry, type RouteMatch, type Router, type RouterOptions, buildRouter, compileRoutePattern, createRouteManifest, fileToRoute, findNamedRoute, findRouteConflicts, generateRoutesFile, getRouteParams, matchRoute, nameRoutes, routeName, routeUrl, sortRoutes };
|
||||
</code></pre></section><section id="examples" class="examples"><h2>Examples</h2><p>Copy-ready examples from the installed package documentation.</p><div class="example-grid"><article class="example-card"><h3>Typical usage</h3><pre data-language="ts"><code>import { buildRouter } from "@wrnexus/router";
|
||||
|
||||
const router = buildRouter("./app", {
|
||||
@@ -273,7 +300,7 @@ const routes = sortRoutes([{ raw: "/posts/[slug]", file: "
|
||||
const m = matchRoute(routes, "/posts/hello"); // { route, params: { slug: "hello" } }</code></pre></article></div></section></article>
|
||||
<aside class="on-this-page"><h2>On this page</h2><nav><a class="toc-level-2" href="#guide">Guide</a><a class="toc-level-3" href="#overview">Overview</a><a class="toc-level-3" href="#directory-conventions">Directory conventions</a><a class="toc-level-3" href="#api">API</a><a class="toc-level-4" href="#buildrouter-appdir-opts-router">buildRouter(appDir, opts?): Router</a><a class="toc-level-4" href="#route-matching">Route matching</a><a class="toc-level-4" href="#typed-routes-codegen">Typed-routes codegen</a><a class="toc-level-4" href="#re-exports">Re-exports</a><a class="toc-level-3" href="#usage">Usage</a><a class="toc-level-3" href="#requirements-notes">Requirements / Notes</a><a class="toc-level-2" href="#api">Complete API</a><a class="toc-level-2" href="#examples">Examples</a></nav></aside>
|
||||
</main>
|
||||
<footer><div class="footer-brand"><span class="footer-mark" aria-hidden="true">W</span><p><strong>WRNexusJS 0.3.6</strong><span>Complete API documentation generated from installed package declarations.</span></p></div><nav aria-label="Footer"><a href="/packages">All packages</a><a href="/getting-started">Get started</a><a href="/security">Security</a><a href="/support">Support</a><a href="/llms.txt">AI guide</a></nav><p class="footer-meta">Private Developer Preview · Bun-native</p></footer>
|
||||
<footer><div class="footer-brand"><span class="footer-mark" aria-hidden="true">W</span><p><strong>WRNexusJS 0.4.0</strong><span>Complete API documentation generated from installed package declarations.</span></p></div><nav aria-label="Footer"><a href="/packages">All packages</a><a href="/getting-started">Get started</a><a href="/security">Security</a><a href="/support">Support</a><a href="/llms.txt">AI guide</a></nav><p class="footer-meta">Private Developer Preview · Bun-native</p></footer>
|
||||
<BackToTop />
|
||||
</div>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user