From 0261da6fd6b6bcd42dbe46cee4ad05eb39a0ef62 Mon Sep 17 00:00:00 2001 From: Diego Resendez Date: Fri, 30 Oct 2026 08:53:49 -0500 Subject: [PATCH] feat(types): export every type a public signature uses Public declarations named types the entry points did not export, so a caller could invoke the API but could not name its parameters or results. The affected types were ModuleOptions, Ctor, BusLike, ArgSource, GraphNodeView, GraphRouteView, StandardIssue, StandardResult, the experimental mesh types, and the adapter option types: DenoServeOptions, BunServeOptions and EdgeCtx. Export them all. The changes are additive only, and no beta.2 name moves. Bun's private BunServeShortOptions becomes the exported BunServeOptions, and the ambient Bun.serve shape is renamed so the two cannot collide. channel() had started returning TappableChannel, which leaked the internal tap symbol into its public return type. Restore the beta.2 return type, Channel. ws-core still finds the tap through the symbol, not through the signature. Signed-off-by: Diego Resendez --- src/bun.ts | 17 ++++++++++++----- src/channel.ts | 7 +++++-- src/deno.ts | 8 ++++++-- src/edge.ts | 3 ++- src/index.ts | 17 +++++++++++------ src/logger.ts | 3 ++- src/params.ts | 2 +- 7 files changed, 39 insertions(+), 18 deletions(-) diff --git a/src/bun.ts b/src/bun.ts index 905b666..b2d71d6 100644 --- a/src/bun.ts +++ b/src/bun.ts @@ -1,6 +1,7 @@ import { channel } from './channel'; import type { Channel } from './channel'; import type { App } from './app/types'; +import { refuseTls } from './security'; import { WS_MAX_MESSAGE_BYTES, DEFAULT_MAX_WS_MESSAGE_BYTES, @@ -32,7 +33,8 @@ interface BunWebSocketHandler { drain?(ws: BunServerWebSocket): void; error?(ws: BunServerWebSocket, error?: unknown): void; } -interface BunServer { +/** The part of the server `Bun.serve` returns that {@link BunServeResult} builds on. */ +export interface BunServer { port: number; // Returns a promise, verified on Bun 1.3 — the previous `void` here was simply wrong, and it // hid the fact that this is awaitable at all. @@ -53,14 +55,18 @@ export interface BunServeResult extends BunServer { */ close(options?: { timeoutMs?: number }): Promise; } -interface BunServeOptions { +interface BunNativeServeOptions { port?: number; hostname?: string; fetch(request: Request, server: BunServer): Response | Promise | undefined; websocket?: BunWebSocketHandler; } -type BunServeShortOptions = { port?: number; hostname?: string }; -declare const Bun: { serve(options: BunServeOptions): BunServer }; +/** Options for {@link serveBun}; passed through to `Bun.serve`. */ +export interface BunServeOptions { + port?: number; + hostname?: string; +} +declare const Bun: { serve(options: BunNativeServeOptions): BunServer }; /** Per-connection state stashed on ws.data between fetch (upgrade) and the open/message/close callbacks. */ interface BunConnData { @@ -104,7 +110,7 @@ function bunSocket(ws: BunServerWebSocket): WsSocket { * * **Boots before it binds**, which is why it is async — see the `await app.boot()` below. */ -export async function serveBun(app: App, options?: BunServeShortOptions): Promise { +export async function serveBun(app: App, options?: BunServeOptions): Promise { // The same gate `listen()` runs before it binds a socket, and for the same reason: resolve the // graph and run the provider factories here, so a missing key or an unreachable pool is a startup // failure rather than a 500 on every request. @@ -113,6 +119,7 @@ export async function serveBun(app: App, options?: BunServeShortOptions): Promis // the first request would fix the failure in place and the runtime would answer from it forever, // without ever reaching `onError`. This was documented as something the caller should remember to // do, which made the correct use of a core helper depend on reading a README. + refuseTls(app, 'serveBun'); await app.boot(); const server = Bun.serve({ diff --git a/src/channel.ts b/src/channel.ts index 302270d..435856e 100644 --- a/src/channel.ts +++ b/src/channel.ts @@ -118,13 +118,15 @@ function newSub(onReturn: () => void): Sub { * Creates a fan-out {@link Channel}. Values pushed are delivered to every active subscriber. * @param opts.buffer Per-subscriber queue cap; drops oldest when exceeded (default: unbounded). */ -export function channel(opts: { buffer?: number } = {}): TappableChannel { +export function channel(opts: { buffer?: number } = {}): Channel { const cap = opts.buffer ?? Infinity; const subs = new Set, 'iterator'>>(); let done = false; let closedFlag = false; - return { + // Public type stays `Channel` (as in beta.2): the tap is internal plumbing, found by `ws-core` + // through the symbol rather than through this signature. + const ch: TappableChannel = { get closed() { return closedFlag; }, @@ -161,4 +163,5 @@ export function channel(opts: { buffer?: number } = {}): TappableChannel { return () => subs.delete(sink); }, }; + return ch; } diff --git a/src/deno.ts b/src/deno.ts index 4abcc9f..4ee4bdf 100644 --- a/src/deno.ts +++ b/src/deno.ts @@ -1,4 +1,5 @@ import type { App } from './app/types'; +import { refuseTls } from './security'; import { beginDrain } from './http/health'; import { eventSocket, toWsRequest, upgradeSafely, type EventfulSocket } from './http/ws-adapter'; import { closeWithDeadline } from './http/shutdown'; @@ -12,7 +13,8 @@ interface WebSocket extends EventfulSocket { // Minimal ambient for the Deno globals we use — avoids a @types/deno devDep. // Mirrors the real Deno.serve / Deno.upgradeWebSocket signatures we call. -interface DenoServeOptions { +/** Options for {@link serveDeno}; passed through to `Deno.serve`. */ +export interface DenoServeOptions { port?: number; hostname?: string; signal?: AbortSignal; @@ -21,7 +23,8 @@ interface DenoServeOptions { interface DenoServeHandlerInfo { remoteAddr: { hostname: string; port: number; transport: string }; } -interface DenoHttpServer { +/** The part of the server `Deno.serve` returns that {@link DenoServer} builds on. */ +export interface DenoHttpServer { finished: Promise; shutdown(): Promise; } @@ -65,6 +68,7 @@ export async function serveDeno(app: App, options?: DenoServeOptions): Promise): void; } declare const WebSocketPair: { new (): { 0: EdgeWebSocket; 1: EdgeWebSocket } }; diff --git a/src/index.ts b/src/index.ts index d215580..774dea6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -22,7 +22,7 @@ export type { App, AppOptions, InspectLine, Explain, ExplainNode, MeshConfig } f // Graph visualization export { toMermaid, toDOT } from './graph-viz'; -export type { GraphView } from './graph-viz'; +export type { GraphView, GraphNodeView, GraphRouteView } from './graph-viz'; export { buildOpenApi } from './openapi'; export type { OpenApiDoc, OpenApiInfo, OpenApiRoute } from './openapi'; @@ -48,7 +48,7 @@ export { Options, Html, } from './metadata'; -export type { Transport, HttpMethod, RouteDecorator, TransformerFn } from './metadata'; +export type { Transport, HttpMethod, RouteDecorator, TransformerFn, ModuleOptions, Ctor } from './metadata'; export type { Plugin, PluginApi, ScopeApi, ScopeNode } from './plugin'; export type { Hooks } from './app'; export type { TeardownFn } from './lifecycle'; @@ -79,7 +79,7 @@ export type { StepFn, CompiledFlow } from './flow'; // Parameter decorators export { needs, ctx, param, query, body, headers, header, cookies, cookie, inbound, abort } from './params'; -export type { Query, RequestHeaders, Headers, Context, ArgSpec, ArgDecorator } from './params'; +export type { Query, RequestHeaders, Headers, Context, ArgSpec, ArgSource, ArgDecorator } from './params'; // Cookies export { setCookie, parseCookies } from './cookies'; @@ -87,7 +87,7 @@ export type { CookieOptions } from './cookies'; // Observability export { createDefaultLogger, logRequests, withConsoleFallback } from './logger'; -export type { Logger, LogLevel, LogFields } from './logger'; +export type { Logger, LogLevel, LogFields, BusLike } from './logger'; // Streaming export { channel, isAsyncIterable } from './channel'; @@ -103,10 +103,15 @@ export type { CompressionOptions } from './http/compression'; export { UNMATCHED_ROUTE } from './http/core'; export type { TlsOptions, CorsOptions, SecurityOptions } from './security'; export type { UploadedFile, MultipartBody } from './multipart'; -export type { StandardSchemaV1 } from './standard-schema'; +export type { StandardSchemaV1, StandardIssue, StandardResult } from './standard-schema'; // Mesh — experimental (`createApp({ experimental: true })`): outside the API freeze, may change in a minor. export { connectLink } from './mesh/link'; export { buildRemote, envelopeFrom } from './mesh/teacup'; export { buildManifest, createMeshControl, MESH_CONTROL_PATH } from './mesh/teapot'; -export type { Manifest, RequestEnvelope, Frame } from './mesh/protocol'; +export type { Manifest, RequestEnvelope, Frame, RouteEntry } from './mesh/protocol'; +export type { Link, ManifestPolicy, ReconnectOptions } from './mesh/link'; +export type { SocketCtor, EventfulSocket } from './http/ws-adapter'; +export type { RemoteScopeNode, RemoteRoute } from './mesh/teacup'; +export type { MeshControlDeps } from './mesh/teapot'; +export type { ResponseShape } from './pipeline'; diff --git a/src/logger.ts b/src/logger.ts index 81e2344..1bea8d1 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -129,7 +129,8 @@ export function logRequests(bus: BusLike, logger: Logger): () => void { } /** The slice of {@link Bus} request logging needs — `on` only, matching what a plugin is handed. */ -interface BusLike { +/** The part of a {@link Bus} that {@link logRequests} subscribes to. */ +export interface BusLike { on(event: 'request:end' | 'request:failed', listener: (payload: EventPayload) => void): () => void; } diff --git a/src/params.ts b/src/params.ts index 3bfa2e7..887b4e9 100644 --- a/src/params.ts +++ b/src/params.ts @@ -16,7 +16,7 @@ export type Headers = RequestHeaders; /** Per-request bag that accumulates values produced by steps and providers. */ export type Context = Record; -type ArgSource = 'ctx' | 'needs' | 'params' | 'query' | 'body' | 'headers' | 'cookies' | 'inbound' | 'abort'; +export type ArgSource = 'ctx' | 'needs' | 'params' | 'query' | 'body' | 'headers' | 'cookies' | 'inbound' | 'abort'; /** Describes how a single handler parameter is sourced and (optionally) validated. */ export interface ArgSpec { index: number;