docs: correct the dead-output component count from 11 to 9
Quality / quality (ubuntu-latest) (push) Failing after 12m8s
Quality / quality (windows-latest) (push) Canceled after 0s

Counted from source: the 22 remaining outputs sit in 9 components, not 11.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-09 10:14:28 +05:30
co-authored by Claude Opus 5
parent 8389d9674e
commit 9ed896d2b9
12 changed files with 436 additions and 18 deletions
+7 -2
View File
@@ -13,7 +13,7 @@ import { spawn, type ChildProcess } from "node:child_process";
import { existsSync } from "node:fs";
import { dirname, join, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { RPC_INTERNAL_HEADER, RPC_PATH_PREFIX } from "@wrnexus/rpc";
import { RPC_INTERNAL_HEADER, RPC_PATH_PREFIX, RPC_STREAM_PATH_PREFIX } from "@wrnexus/rpc";
import { RESTART_EXIT_CODE } from "./restart.ts";
export type GatewayForwardAuth = (
@@ -446,7 +446,12 @@ export function stripUntrustedInternalHeaders(headers: Headers): Headers {
* must never be reachable from outside the workspace.
*/
export function isRpcGatewayPath(pathname: string): boolean {
return pathname === RPC_PATH_PREFIX || pathname.startsWith(`${RPC_PATH_PREFIX}/`);
return (
pathname === RPC_PATH_PREFIX ||
pathname.startsWith(`${RPC_PATH_PREFIX}/`) ||
pathname === RPC_STREAM_PATH_PREFIX ||
pathname.startsWith(`${RPC_STREAM_PATH_PREFIX}/`)
);
}
/** Boot every app as a child process, then route by Host on one gateway port. */
+57 -2
View File
@@ -2,14 +2,21 @@ import {
RPC_IDENTITY_HEADER,
RPC_INTERNAL_HEADER,
RPC_PATH_PREFIX,
RPC_STREAM_PATH_PREFIX,
type ServiceImplementation,
type StreamImplementation,
} from "@wrnexus/rpc";
export { RPC_INTERNAL_HEADER };
const EDGE_HEADERS = ["x-forwarded-for", "x-forwarded-host", "x-forwarded-proto", "forwarded"];
export function isRpcPath(pathname: string): boolean {
return pathname === RPC_PATH_PREFIX || pathname.startsWith(`${RPC_PATH_PREFIX}/`);
return (
pathname === RPC_PATH_PREFIX ||
pathname.startsWith(`${RPC_PATH_PREFIX}/`) ||
pathname === RPC_STREAM_PATH_PREFIX ||
pathname.startsWith(`${RPC_STREAM_PATH_PREFIX}/`)
);
}
export function isInternalCaller(req: Request): boolean {
@@ -26,11 +33,14 @@ function json(body: unknown, status = 200): Response {
export async function handleRpcRequest(
req: Request,
url: URL,
services: Map<string, ServiceImplementation>,
services: Map<string, ServiceImplementation | StreamImplementation>,
): Promise<Response | null> {
if (!isRpcPath(url.pathname)) return null;
if (!isInternalCaller(req)) return new Response("Not found", { status: 404 });
if (req.method !== "POST") return new Response("Method not allowed", { status: 405 });
const streaming =
url.pathname === RPC_STREAM_PATH_PREFIX ||
url.pathname.startsWith(`${RPC_STREAM_PATH_PREFIX}/`);
const segments = url.pathname.split("/");
const SAFE_SEGMENT = /^[A-Za-z0-9_-]+$/;
const serviceName = segments[3];
@@ -46,6 +56,51 @@ export async function handleRpcRequest(
} catch {
return json({ ok: false, code: "RPC_INVALID", message: "Invalid input", retryable: false });
}
if (streaming) {
if (!("stream" in service) || typeof service.stream !== "function") {
return json({
ok: false,
code: "RPC_UNKNOWN",
message: "Unknown procedure",
retryable: false,
});
}
const encoder = new TextEncoder();
const identity = req.headers.get(RPC_IDENTITY_HEADER) ?? undefined;
const iterator = service.stream(procedure, payload, identity)[Symbol.asyncIterator]();
const body = new ReadableStream<Uint8Array>({
async pull(controller) {
try {
const next = await iterator.next();
if (next.done) {
controller.close();
return;
}
controller.enqueue(
encoder.encode(`data: ${JSON.stringify({ ok: true, value: next.value })}\n\n`),
);
} catch {
controller.enqueue(
encoder.encode('data: {"ok":false,"code":"RPC_HANDLER","message":"Stream failed"}\n\n'),
);
controller.close();
}
},
async cancel() {
await iterator.return?.();
},
});
return new Response(body, {
headers: {
"content-type": "text/event-stream; charset=utf-8",
"cache-control": "private, no-store",
"x-accel-buffering": "no",
},
});
}
if (!("invoke" in service) || typeof service.invoke !== "function") {
return json({ ok: false, code: "RPC_UNKNOWN", message: "Unknown procedure", retryable: false });
}
return json(
await service.invoke(procedure, payload, req.headers.get(RPC_IDENTITY_HEADER) ?? undefined),
);
+16 -8
View File
@@ -90,7 +90,7 @@ import {
} from "@wrnexus/i18n";
import { runMiddleware } from "./pipeline.ts";
import { handleRpcRequest, isRpcPath } from "./rpc-dispatch.ts";
import type { ServiceImplementation } from "@wrnexus/rpc";
import type { ServiceImplementation, StreamImplementation } from "@wrnexus/rpc";
import type { HmrHub } from "./hmr.ts";
import type {
DevToolbarConfig,
@@ -888,16 +888,24 @@ export function createHandlers(deps: RuntimeDeps): Handlers {
// co-located helper with no default export) must not permanently break
// every route in the app. Only a SUCCESSFUL load is cached; a failed
// attempt logs loudly and is retried on the next RPC request.
let servicesPromise: Promise<Map<string, ServiceImplementation>> | undefined;
const loadServices = (): Promise<Map<string, ServiceImplementation>> => {
let servicesPromise:
Promise<Map<string, ServiceImplementation | StreamImplementation>> | undefined;
const loadServices = (): Promise<Map<string, ServiceImplementation | StreamImplementation>> => {
if (!servicesPromise) {
servicesPromise = (async () => {
const services = new Map<string, ServiceImplementation>();
const services = new Map<string, ServiceImplementation | StreamImplementation>();
for (const entry of router.services) {
const imported = await loadModule(entry.file);
const implementation = imported.default as ServiceImplementation | undefined;
if (!implementation || typeof implementation.invoke !== "function") {
throw new Error(`RPC service ${entry.file} must default-export implement(...)`);
const implementation = imported.default as
(ServiceImplementation | StreamImplementation) | undefined;
if (
!implementation ||
(typeof (implementation as ServiceImplementation).invoke !== "function" &&
typeof (implementation as StreamImplementation).stream !== "function")
) {
throw new Error(
`RPC service ${entry.file} must default-export implement(...) or implementStream(...)`,
);
}
if (implementation.contract.name !== entry.name) {
throw new Error(
@@ -988,7 +996,7 @@ export function createHandlers(deps: RuntimeDeps): Handlers {
withSecurityHeaders(req, res, mode, runtimeSecurity, nonce);
if (isRpcPath(url.pathname)) {
let services: Map<string, ServiceImplementation>;
let services: Map<string, ServiceImplementation | StreamImplementation>;
try {
services = await loadServices();
} catch (error) {