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<T>. ws-core still finds the tap through the symbol, not through the signature. Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
7 files changed
+39
-18
No files matched your search
+12
-5
@@ -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<void>;
|
||||
}
|
||||
interface BunServeOptions {
|
||||
interface BunNativeServeOptions {
|
||||
port?: number;
|
||||
hostname?: string;
|
||||
fetch(request: Request, server: BunServer): Response | Promise<Response> | 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<BunServeResult> {
|
||||
export async function serveBun(app: App, options?: BunServeOptions): Promise<BunServeResult> {
|
||||
// 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({
|
||||
|
||||
+5
-2
@@ -118,13 +118,15 @@ function newSub<T>(onReturn: () => void): Sub<T> {
|
||||
* 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<T>(opts: { buffer?: number } = {}): TappableChannel<T> {
|
||||
export function channel<T>(opts: { buffer?: number } = {}): Channel<T> {
|
||||
const cap = opts.buffer ?? Infinity;
|
||||
const subs = new Set<Omit<Sub<T>, 'iterator'>>();
|
||||
let done = false;
|
||||
let closedFlag = false;
|
||||
|
||||
return {
|
||||
// Public type stays `Channel<T>` (as in beta.2): the tap is internal plumbing, found by `ws-core`
|
||||
// through the symbol rather than through this signature.
|
||||
const ch: TappableChannel<T> = {
|
||||
get closed() {
|
||||
return closedFlag;
|
||||
},
|
||||
@@ -161,4 +163,5 @@ export function channel<T>(opts: { buffer?: number } = {}): TappableChannel<T> {
|
||||
return () => subs.delete(sink);
|
||||
},
|
||||
};
|
||||
return ch;
|
||||
}
|
||||
+6
-2
@@ -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<void>;
|
||||
shutdown(): Promise<void>;
|
||||
}
|
||||
@@ -65,6 +68,7 @@ export async function serveDeno(app: App, options?: DenoServeOptions): Promise<D
|
||||
// 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, 'serveDeno');
|
||||
await app.boot();
|
||||
|
||||
// Deno's only force-close lever is the abort signal it was served with, so the adapter has to
|
||||
|
||||
+2
-1
@@ -8,7 +8,8 @@ import { MARK_EDGE } from './http/compression';
|
||||
interface EdgeWebSocket extends EventfulSocket {
|
||||
accept(): void;
|
||||
}
|
||||
interface EdgeCtx {
|
||||
/** The Workers execution context {@link edgeHandler} receives as its third argument. */
|
||||
export interface EdgeCtx {
|
||||
waitUntil(promise: Promise<unknown>): void;
|
||||
}
|
||||
declare const WebSocketPair: { new (): { 0: EdgeWebSocket; 1: EdgeWebSocket } };
|
||||
|
||||
+11
-6
@@ -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';
|
||||
+2
-1
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ export type Headers = RequestHeaders;
|
||||
/** Per-request bag that accumulates values produced by steps and providers. */
|
||||
export type Context = Record<string, unknown>;
|
||||
|
||||
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;
|
||||
|
||||
Reference in new issue
Block a user