diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3fac404..fab0380 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,6 +49,10 @@ jobs: - run: npm run typecheck - run: npm test - run: npm run build + # The committed reports in api/ are the frozen surface (CARD-22, D20). A PR that changes a + # public type fails here until it regenerates them with `npm run api`, so the change shows up + # in the diff a reviewer reads instead of only in the published declarations. + - run: npm run api:check # Supply chain, deliberately after the code gates: an advisory published by a third party # must never decide whether a contributor gets to see their own lint and typecheck output. # Only what we ship blocks — with `reflect-metadata` as the sole runtime dependency, a diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index cea4f89..f69783e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -145,6 +145,7 @@ npm run typecheck # must be clean — this includes the compile-time-guarantee t npm test # all tests must pass npm run complexity:check npm run build +npm run api:check # the committed API reports in api/ still match the build npm audit --omit=dev # only what ships blocks; CI reports the rest ``` @@ -154,6 +155,7 @@ Bun and the edge in its `runtimes` job. - Write tests for new behavior (TDD welcome). We use Vitest. - `complexity:check` caps the cognitive complexity of every function in `src/`. What it measures is how much you have to hold in your head to follow a function from top to bottom, and it charges nesting more heavily than branching: a condition inside a closure inside a function costs several times what the same condition costs at the top level. Going over the threshold is not a verdict on your code — it means one function has grown to ask too much of whoever reads it next. The fix is nearly always to lift a nested closure out to module scope, where its branches are charged once instead of three times over. Raising `COMPLEXITY_MAX` is not the fix, even though the script suggests it. - Keep runtime dependencies at zero beyond `reflect-metadata`. +- **The public API is frozen from RC.1, and `api/` is its record.** `api/*.api.md` holds one report per export-map entry, and `npm run api:check` fails when the build declares something they do not. If you meant to change the API, run `npm run build && npm run api` and commit the regenerated report with your change, so the reviewer reads the API change as a diff rather than finding it after release. Until the stable release a change may only add: removing or narrowing anything published in `26.9.0-beta.2` is not accepted. The check also fails when a public signature names a type its entry point does not export, because a user would have no way to name it. Mesh is `@experimental` and outside the freeze, but it is still in the report, so a mesh change shows up there too. - A new option or method on a public interface has to change that interface too. An implementation that grows a parameter without `src/app/types.ts` growing it as well is unreachable for anyone consuming the package. - New public API needs a doc note in `README.md`, **and a companion pull request to [green-tea-docs](https://github.com/Expressive-Tea/green-tea-docs) updating the page that documents it.** It is a second pull request because a pull request cannot span two repositories — link the two to each other so a reviewer can see both. The documentation site used to be built by this repository's CI, so a stale page broke the build; it is now a separate repository that imports nothing from here, and nothing fails when the two disagree. Issue #18 happened when the two still lived together, which is the reason this line exists rather than a hope. If you would rather not write the docs change, say so in your pull request and a maintainer will — an unmentioned API change is the failure this line exists to prevent, not an unwritten page. - If your change only works on one runtime, say so in the pull request. green-tea runs on Node, Deno, Bun and the edge, and behavior that quietly differs between them is treated as a bug — an explicit "not available here" is fine, silence is not. diff --git a/api/bun.api.md b/api/bun.api.md new file mode 100644 index 0000000..f6b886d --- /dev/null +++ b/api/bun.api.md @@ -0,0 +1,48 @@ +## API Report File for "@green-tea/core" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts + +import http from 'http'; + +// @public +export interface BunServeOptions { + // (undocumented) + hostname?: string; + // (undocumented) + port?: number; +} + +// @public +export interface BunServer { + // (undocumented) + port: number; + // (undocumented) + requestIP(request: Request): { + address: string; + family: string; + port: number; + } | null; + // (undocumented) + stop(closeActiveConnections?: boolean): Promise; + // (undocumented) + upgrade(request: Request, options?: { + data?: unknown; + headers?: Record; + }): boolean; +} + +// @public +export interface BunServeResult extends BunServer { + close(options?: { + timeoutMs?: number; + }): Promise; +} + +// @public +export function serveBun(app: App, options?: BunServeOptions): Promise; + +// (No @packageDocumentation comment for this package) + +``` diff --git a/api/deno.api.md b/api/deno.api.md new file mode 100644 index 0000000..b8f118b --- /dev/null +++ b/api/deno.api.md @@ -0,0 +1,44 @@ +## API Report File for "@green-tea/core" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts + +import http from 'http'; + +// @public +export interface DenoHttpServer { + // (undocumented) + finished: Promise; + // (undocumented) + shutdown(): Promise; +} + +// @public +export interface DenoServeOptions { + // (undocumented) + hostname?: string; + // (undocumented) + onListen?: (addr: { + hostname: string; + port: number; + }) => void; + // (undocumented) + port?: number; + // (undocumented) + signal?: AbortSignal; +} + +// @public +export interface DenoServer extends DenoHttpServer { + close(options?: { + timeoutMs?: number; + }): Promise; +} + +// @public +export function serveDeno(app: App, options?: DenoServeOptions): Promise; + +// (No @packageDocumentation comment for this package) + +``` diff --git a/api/edge.api.md b/api/edge.api.md new file mode 100644 index 0000000..d34111a --- /dev/null +++ b/api/edge.api.md @@ -0,0 +1,20 @@ +## API Report File for "@green-tea/core" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts + +import http from 'http'; + +// @public +export interface EdgeCtx { + // (undocumented) + waitUntil(promise: Promise): void; +} + +// @public +export function edgeHandler(app: App): (request: Request, env?: unknown, ctx?: EdgeCtx) => Response | Promise; + +// (No @packageDocumentation comment for this package) + +``` diff --git a/api/index.api.md b/api/index.api.md new file mode 100644 index 0000000..c6494c6 --- /dev/null +++ b/api/index.api.md @@ -0,0 +1,1081 @@ +## API Report File for "@green-tea/core" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts + +import http from 'http'; + +// @public +export function abort(): ParameterDecorator; + +// @public +export interface App { + boot(): Promise; + // (undocumented) + bus: Bus; + close(options?: { + timeoutMs?: number; + }): Promise; + degraded(): string[]; + // (undocumented) + explain(routePath: string): Explain; + fetch(request: Request): Promise; + // (undocumented) + graph(): GraphView; + handleSignals Promise>(closer: T): T; + // (undocumented) + inspect(routePath: string): InspectLine[]; + // (undocumented) + listen(port: number): Promise; + logger: Logger; + openapi(info?: OpenApiInfo): OpenApiDoc; + ready(): Promise; + // (undocumented) + toDOT(): string; + // (undocumented) + toMermaid(): string; + upgrade(request: WsRequest, socket: WsSocket): Promise; +} + +// @public +export interface AppOptions { + // (undocumented) + bodyDuplicates?: 'array' | 'last'; + compression?: boolean | CompressionOptions; + // (undocumented) + cors?: CorsOptions; + // (undocumented) + devGraph?: boolean; + // (undocumented) + devOpenapi?: boolean; + etag?: boolean; + experimental?: boolean; + handleSignals?: boolean; + health?: boolean | { + drainDelayMs?: number; + }; + hooks?: Hooks[]; + // (undocumented) + limits?: RequestLimits; + logger?: Logger; + logRequests?: boolean; + // (undocumented) + mesh?: MeshConfig; + // (undocumented) + modules: Ctor[]; + onError?: ErrorRenderer; + // (undocumented) + overrides?: Record; + // (undocumented) + plugins?: Plugin[]; + // (undocumented) + security?: boolean | SecurityOptions; + shutdownTimeoutMs?: number; + static?: boolean | string | { + dir?: string; + cacheControl?: string; + }; + teardownTimeoutMs?: number; + // (undocumented) + tls?: TlsOptions; + // (undocumented) + trustProxy?: boolean; + viewEngine?: (source: string, data: unknown) => string; + views?: string; + warnGraphDepth?: number | false; +} + +// @public +export type ArgDecorator = (arg?: string | string[] | StandardSchemaV1, schema?: StandardSchemaV1) => ParameterDecorator; + +// @public (undocumented) +export type ArgSource = 'ctx' | 'needs' | 'params' | 'query' | 'body' | 'headers' | 'cookies' | 'inbound' | 'abort'; + +// @public +export interface ArgSpec { + // (undocumented) + index: number; + // (undocumented) + key?: string; + // (undocumented) + keys?: string[]; + // (undocumented) + schema?: StandardSchemaV1; + // (undocumented) + source: ArgSource; +} + +// @public +export const body: ArgDecorator; + +// @public +export function buildManifest(args: { + steps: string[]; + routes: RouteEntry[]; +}): Manifest; + +// @public +export function buildOpenApi(routes: OpenApiRoute[], info?: OpenApiInfo): OpenApiDoc; + +// @public +export function buildRemote(link: Link): { + steps: RemoteScopeNode[]; + routes: RemoteRoute[]; +}; + +// @public +export class Bus { + emit(event: LifecycleEvent, payload: EventPayload): void; + hasListeners(event: LifecycleEvent): boolean; + on(event: LifecycleEvent, listener: (p: EventPayload) => void): () => void; +} + +// @public +export interface BusLike { + // (undocumented) + on(event: 'request:end' | 'request:failed', listener: (payload: EventPayload) => void): () => void; +} + +// @public +export interface Channel extends AsyncIterable { + // (undocumented) + close(): void; + // (undocumented) + readonly closed: boolean; + // (undocumented) + fail(err: unknown): void; + // (undocumented) + push(value: T): void; +} + +// @public +export function channel(opts?: { + buffer?: number; +}): Channel; + +// @public +export interface CompiledFlow { + // (undocumented) + handler: (ctx: Acc) => unknown; + // (undocumented) + run(seed: Seed): Promise; + // (undocumented) + steps: { + name: string; + fn: StepFn; + }[]; +} + +// @public +export interface CompressionOptions { + encodings?: Array<'br' | 'gzip'>; + threshold?: number; +} + +// @public +export function connectLink(args: { + url: string; + secret: string; + timeoutMs?: number; + heartbeatMs?: number; + bus?: Bus; + Ctor?: SocketCtor; + reconnect?: boolean | ReconnectOptions; + onManifestChange?: ManifestPolicy; + logger?: Logger; + onReconnect?: (manifest: Manifest) => void; + onGone?: () => void; +}): Promise; + +// @public +export type Context = Record; + +// @public +export const cookie: ArgDecorator; + +// @public +export interface CookieOptions { + domain?: string; + expires?: Date; + httpOnly?: boolean; + maxAge?: number; + partitioned?: boolean; + path?: string; + sameSite?: 'strict' | 'lax' | 'none'; + secure?: boolean; +} + +// @public +export const cookies: ArgDecorator; + +// @public +export type Correlation = Pick; + +// @public +export interface CorsOptions { + // (undocumented) + allowedHeaders?: string[]; + // (undocumented) + credentials?: boolean; + // (undocumented) + exposedHeaders?: string[]; + // (undocumented) + maxAge?: number; + // (undocumented) + methods?: string[]; + // (undocumented) + origins: string | string[] | '*' | ((origin: string) => boolean); +} + +// @public +export function createApp(opts: AppOptions): App; + +// @public +export function createDefaultLogger(pretty?: boolean): Logger; + +// @public +export function createMeshControl(deps: MeshControlDeps): { + path: string; + maxFrameBytes: number; + handle: (socket: WsSocket) => Promise; +}; + +// @public +export type Ctor = new (...args: any[]) => any; + +// @public +export function ctx(): ParameterDecorator; + +// @public +export const Delete: RouteDecorator; + +// @public +export function envelopeFrom(ctx: any): RequestEnvelope; + +// @public +export type ErrorRenderer = (error: unknown, req: ErrorRequest) => ErrorResponse | undefined | void; + +// @public +export interface ErrorRequest { + // (undocumented) + headers: Record; + // (undocumented) + method: string; + // (undocumented) + url: string; +} + +// @public +export interface ErrorResponse { + // (undocumented) + body: string; + headers: Record; + // (undocumented) + status: number; +} + +// @public +export interface EventfulSocket { + // (undocumented) + addEventListener(type: 'open' | 'message' | 'close' | 'error', listener: (event: { + data?: string | ArrayBuffer; + error?: unknown; + }) => void): void; + readonly bufferedAmount?: number; + // (undocumented) + close(code?: number, reason?: string): void; + // (undocumented) + readonly readyState: number; + // (undocumented) + send(data: string): void; +} + +// @public +export interface EventPayload { + added?: string[]; + // (undocumented) + durationMs?: number; + // (undocumented) + error?: unknown; + // (undocumented) + method?: string; + name: string; + removed?: string[]; + requestId?: string; + route?: string; + // (undocumented) + scope?: string; + status?: number; + traceId?: string; + // (undocumented) + transport?: string; + url?: string; +} + +// @public +export interface Events { + // (undocumented) + on: Bus['on']; +} + +// @public +export interface Explain { + // (undocumented) + chain: ExplainNode[]; + // (undocumented) + method: HttpMethod; + // (undocumented) + pattern: string; + // (undocumented) + transport: Transport; +} + +// @public +export interface ExplainNode { + // (undocumented) + kind: 'provider' | 'step' | 'handler'; + // (undocumented) + name: string; + // (undocumented) + needs: string[]; + // (undocumented) + origin: string; + // (undocumented) + provides: string[]; +} + +// @public +export class Flow { + constructor(steps?: { + name: string; + fn: StepFn; + }[]); + handle(handler: (ctx: Acc) => unknown): CompiledFlow; + step(name: string, fn: StepFn): Flow; +} + +// @public +export function flow(): Flow; + +// @public +export type Frame = { + type: 'hello'; + v: number; + secret: string; +} | { + type: 'manifest'; + v: number; + steps: string[]; + routes: RouteEntry[]; +} | { + type: 'rpc-req'; + id: string; + kind: 'scope' | 'route'; + name: string; + ctx: RequestEnvelope; +} | { + type: 'rpc-res'; + id: string; + ok: true; + result: unknown; +} | { + type: 'rpc-res'; + id: string; + ok: false; + error: { + message: string; + status?: number; + }; +} | { + type: 'ping'; +} | { + type: 'pong'; +}; + +// @public +export const Get: RouteDecorator; + +// @public +export interface GraphNodeView { + // (undocumented) + kind: 'provider' | 'step'; + // (undocumented) + name: string; + // (undocumented) + needs: string[]; + // (undocumented) + origin: string; + // (undocumented) + provides: string[]; +} + +// @public +export interface GraphRouteView { + // (undocumented) + chain: string[]; + // (undocumented) + method: string; + // (undocumented) + pattern: string; + // (undocumented) + transport: string; +} + +// @public +export interface GraphView { + // (undocumented) + nodes: GraphNodeView[]; + // (undocumented) + routes: GraphRouteView[]; +} + +// @public +export const Head: RouteDecorator; + +// @public +export const header: ArgDecorator; + +// @public +export const headers: ArgDecorator; + +// @public @deprecated (undocumented) +type Headers_2 = RequestHeaders; +export { Headers_2 as Headers } + +// @public +export interface Hooks { + onShutdown?: TeardownFn; +} + +// @public +export function Html(path: string, opts?: { + template?: boolean; +}): MethodDecorator; + +// @public (undocumented) +export function Html(target: object, propertyKey: string | symbol): void; + +// @public +export const HTTP_ERROR: unique symbol; + +// @public +export class HttpError extends Error { + // (undocumented) + readonly [HTTP_ERROR] = true; + constructor(status: number, message?: string, body?: unknown | undefined, headers?: Record | undefined); + // (undocumented) + readonly body?: unknown | undefined; + // (undocumented) + readonly headers?: Record | undefined; + // (undocumented) + readonly status: number; +} + +// @public +export interface HttpErrorLike { + // (undocumented) + body?: unknown; + // (undocumented) + headers?: Record; + // (undocumented) + message: string; + // (undocumented) + status: number; +} + +// @public +export type HttpMethod = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS'; + +// @public +export function inbound(): ParameterDecorator; + +// @public +export interface InspectLine { + // (undocumented) + kind: 'provider' | 'step' | 'handler'; + // (undocumented) + name: string; + // (undocumented) + origin: string; +} + +// @public +export function isAsyncIterable(x: unknown): x is AsyncIterable; + +// @public +export function isHttpError(error: unknown): error is HttpErrorLike; + +// @public +export function isSseEvent(item: unknown): item is SseEvent; + +// @public +export function isValidationError(error: unknown): error is ValidationError; + +// @public +export const JsonTransformer: TransformerFn; + +// @public +export type LifecycleEvent = 'boot:provider:start' | 'boot:provider:ok' | 'boot:provider:fail' | 'request:step:enter' | 'request:step:leave' | 'request:step:error' | 'stream:open' | 'stream:close' | 'stream:error' | 'mesh:connect' | 'mesh:disconnect' | 'mesh:rpc:error' | 'mesh:boot:retry' | 'mesh:routes' | 'plugin:mounted' | 'request:start' | 'request:end' | 'request:failed' | 'route:matched' | 'route:unmatched'; + +// @public +export interface Link { + // (undocumented) + close(): void; + // (undocumented) + manifest: Manifest; + // (undocumented) + rpc(kind: 'scope' | 'route', name: string, ctx: RequestEnvelope): Promise; +} + +// @public +export type LogFields = Record; + +// @public +export interface Logger { + // (undocumented) + debug(message: string, fields?: LogFields): void; + // (undocumented) + error(message: string, fields?: LogFields): void; + // (undocumented) + info(message: string, fields?: LogFields): void; + // (undocumented) + warn(message: string, fields?: LogFields): void; +} + +// @public +export type LogLevel = 'debug' | 'info' | 'warn' | 'error'; + +// @public +export function logRequests(bus: BusLike, logger: Logger): () => void; + +// @public +export interface Manifest { + // (undocumented) + routes: RouteEntry[]; + // (undocumented) + steps: string[]; +} + +// @public +export type ManifestPolicy = 'refuse'; + +// @public +export const MESH_CONTROL_PATH = "/__mesh__/control"; + +// @public +export interface MeshConfig { + bootTimeoutMs?: number; + heartbeatMs?: number; + onManifestChange?: 'refuse'; + reconnect?: boolean | { + initialDelayMs?: number; + maxDelayMs?: number; + }; + // (undocumented) + secret?: string; + // (undocumented) + teapots?: Array<{ + url: string; + secret: string; + }>; + timeoutMs?: number; +} + +// @public +export interface MeshControlDeps { + // (undocumented) + bus?: Bus; + // (undocumented) + manifest: Manifest; + maxBodyBytes?: number; + // (undocumented) + resolveRoute: (name: string, env: RequestEnvelope) => Promise; + // (undocumented) + resolveScope: (name: string, env: RequestEnvelope) => Promise; + // (undocumented) + secret: string; +} + +// @public +export function Module(opts: ModuleOptions): ClassDecorator; + +// @public +export interface ModuleOptions { + // (undocumented) + controllers?: Ctor[]; + // (undocumented) + mountpoint: string; + // (undocumented) + providers?: Ctor[]; + // (undocumented) + steps?: Ctor[]; +} + +// @public +export interface MultipartBody { + // (undocumented) + fields: Record; + // (undocumented) + files: Record; +} + +// @public +export const ndjsonEncoder: StreamEncoder; + +// @public +export function needs(key: string): ParameterDecorator; + +// @public +export class NotFound extends HttpError { + constructor(message?: string); +} + +// @public +export class NotModified extends HttpError { + constructor(); +} + +// @public +export interface OpenApiDoc { + // (undocumented) + info: { + title: string; + version: string; + description?: string; + }; + // (undocumented) + openapi: string; + // (undocumented) + paths: Record>; +} + +// @public +export interface OpenApiInfo { + // (undocumented) + description?: string; + // (undocumented) + title?: string; + // (undocumented) + version?: string; +} + +// @public +export interface OpenApiRoute { + // (undocumented) + args: ArgSpec[]; + // (undocumented) + method: string; + // (undocumented) + pattern: string; + // (undocumented) + transport: Transport; +} + +// @public +export const Options: RouteDecorator; + +// @public +export const param: ArgDecorator; + +// @public +export function parseCookies(header: string | string[] | undefined): Record; + +// @public +export const Patch: RouteDecorator; + +// @public +export interface Plugin { + // (undocumented) + mount(api: PluginApi): void; + // (undocumented) + readonly name: string; +} + +// @public +export interface PluginApi { + // (undocumented) + bus: { + on: Bus['on']; + }; + onShutdown(fn: TeardownFn): void; + // (undocumented) + scope: ScopeApi; +} + +// @public +export const Post: RouteDecorator; + +// @public +export function Provider(opts: { + provides: string; + needs?: string[]; + optional?: boolean; +}): ClassDecorator; + +// @public +export const Put: RouteDecorator; + +// @public +export type Query = Record; + +// @public +export const query: ArgDecorator; + +// @public +export interface ReconnectOptions { + initialDelayMs?: number; + maxDelayMs?: number; +} + +// @public +export class Redirect extends HttpError { + constructor(location: string); + // (undocumented) + readonly location: string; +} + +// @public +export interface RemoteRoute { + // (undocumented) + handler: (req: RequestEnvelope) => Promise; + // (undocumented) + method: string; + // (undocumented) + pattern: string; +} + +// @public +export interface RemoteScopeNode { + // (undocumented) + name: string; + // (undocumented) + run: (ctx: any) => Promise>; +} + +// @public +export function render(source: string, data: unknown): string; + +// @public +export interface RequestEnvelope { + // (undocumented) + body: unknown; + correlation?: { + requestId?: string; + traceId?: string; + }; + // (undocumented) + headers: Record; + // (undocumented) + method: string; + // (undocumented) + params: Record; + // (undocumented) + query: Record; + url?: string; +} + +// @public +export type RequestHeaders = Record; + +// @public +export interface RequestLimits { + // (undocumented) + headersTimeoutMs?: number; + // (undocumented) + keepAliveTimeoutMs?: number; + // (undocumented) + maxBodyBytes?: number; + // (undocumented) + maxConcurrentRequests?: number; + // (undocumented) + maxConnections?: number; + // (undocumented) + maxParts?: number; + maxWsMessageBytes?: number; + maxWsQueue?: number; + // (undocumented) + requestTimeoutMs?: number; +} + +// @public +export interface ResponseShape { + // (undocumented) + body: string; + headers: Record; + // (undocumented) + status: number; +} + +// @public +export class Rooms { + names(): string[]; + room(name: string): Channel; +} + +// @public +export function Route(prefix: string): ClassDecorator; + +// @public +export type RouteDecorator = (path: string, opts?: { + export?: boolean; + duplicates?: 'array' | 'last'; + maxBodyBytes?: number; + maxParts?: number; +}) => MethodDecorator; + +// @public +export interface RouteEntry { + // (undocumented) + method: string; + // (undocumented) + pattern: string; +} + +// @public +export interface ScopeApi { + // (undocumented) + add(node: ScopeNode): void; +} + +// @public +export interface ScopeNode { + // (undocumented) + kind: 'step' | 'provider'; + // (undocumented) + name: string; + // (undocumented) + needs: string[]; + // (undocumented) + provides: string[]; + // (undocumented) + run: (ctx: any) => any; +} + +// @public +export interface SecurityOptions { + // (undocumented) + csp?: string; + // (undocumented) + dnsPrefetchControl?: boolean; + // (undocumented) + frameOptions?: 'SAMEORIGIN' | 'DENY' | false; + // (undocumented) + hsts?: boolean | { + maxAge?: number; + includeSubDomains?: boolean; + preload?: boolean; + }; + // (undocumented) + noSniff?: boolean; + // (undocumented) + referrerPolicy?: string | false; +} + +// @public +export function setCookie(name: string, value: string, options?: CookieOptions): string; + +// @public +export type SocketCtor = new (url: string) => EventfulSocket; + +// @public +export const Sse: RouteDecorator; + +// @public +export function sse(data: T, fields?: SseFields): SseEvent; + +// @public +export const sseEncoder: StreamEncoder; + +// @public +export interface SseEvent extends SseFields { + // (undocumented) + readonly [SSE_EVENT]: true; + // (undocumented) + data: T; +} + +// @public +export interface SseFields { + event?: string; + id?: string; + retry?: number; +} + +// @public +export interface StandardIssue { + // (undocumented) + readonly message: string; + // (undocumented) + readonly path?: ReadonlyArray; +} + +// @public +export type StandardResult = { + readonly value: T; + readonly issues?: undefined; +} | { + readonly issues: ReadonlyArray; +}; + +// @public +export interface StandardSchemaV1 { + // (undocumented) + readonly '~standard': { + readonly version: 1; + readonly vendor: string; + validate(value: unknown): StandardResult | Promise>; + readonly types?: { + readonly input: Input; + readonly output: Output; + }; + }; +} + +// @public +export function Step(opts: { + provides: string; + needs?: string[]; + optional?: boolean; + export?: boolean; +}): ClassDecorator; + +// @public +export type StepFn = (ctx: In) => Out | Promise; + +// @public +export const Stream: RouteDecorator; + +// @public +export interface StreamEncoder { + // (undocumented) + encode(item: unknown): string | Buffer; + // (undocumented) + encodeError(err: unknown): string | Buffer | null; + // (undocumented) + headers: Record; + // (undocumented) + ping?(): string; +} + +// @public +export type TeardownFn = () => void | Promise; + +// @public +export interface TlsOptions { + // (undocumented) + ca?: Buffer | string; + // (undocumented) + cert: Buffer | string; + // (undocumented) + key: Buffer | string; + // (undocumented) + passphrase?: string; +} + +// @public +export function toDOT(view: GraphView): string; + +// @public +export function toMermaid(view: GraphView): string; + +// @public +export function Transformer(fn: TransformerFn): MethodDecorator; + +// @public +export type TransformerFn = (value: unknown) => { + status?: number; + headers?: Record; + body: string; +}; + +// @public +export type Transport = 'buffer' | 'sse' | 'ndjson' | 'negotiate' | 'ws'; + +// @public +export class TransportMismatchError extends HttpError { + constructor(transport: string, got: 'stream' | 'value', req?: { + method?: string; + url?: string; + }); +} + +// @public +export class Unauthorized extends HttpError { + constructor(message?: string); +} + +// @public +export const UNMATCHED_ROUTE = ""; + +// @public +export interface UploadedFile { + // (undocumented) + contentType: string; + // (undocumented) + data: Buffer; + // (undocumented) + filename: string; + // (undocumented) + size: number; +} + +// @public (undocumented) +export const VALIDATION_ERROR: unique symbol; + +// @public +export class ValidationError extends HttpError { + // (undocumented) + readonly [VALIDATION_ERROR] = true; + constructor(issues: StandardIssue[], source: string); + // (undocumented) + issues: StandardIssue[]; + // (undocumented) + source: string; +} + +// @public +export const VERSION = "26.9.0-beta.2"; + +// @public +export function withConsoleFallback(logger: Logger): Logger; + +// @public +export const Ws: RouteDecorator; + +// @public +export interface WsRequest { + // (undocumented) + headers: Record; + // (undocumented) + ip: string; + // (undocumented) + protocol: 'http' | 'https'; + // (undocumented) + url: string; +} + +// @public +export interface WsSocket { + // (undocumented) + readonly abort: AbortSignal; + // (undocumented) + close(code?: number, reason?: string): void; + drained?(): Promise; + // (undocumented) + readonly inbound: AsyncIterable; + // (undocumented) + readonly isOpen: boolean; + // (undocumented) + send(data: string): void; + // (undocumented) + terminate(): void; +} + +// (No @packageDocumentation comment for this package) + +``` diff --git a/deno.lock b/deno.lock index d999d67..24cd71f 100644 --- a/deno.lock +++ b/deno.lock @@ -19,6 +19,7 @@ "packageJson": { "dependencies": [ "npm:@eslint/js@^9.39.5", + "npm:@microsoft/api-extractor@^7.59.4", "npm:@nestjs/common@^11.1.28", "npm:@nestjs/core@^11.1.28", "npm:@nestjs/platform-express@^11.1.28", diff --git a/package-lock.json b/package-lock.json index 8da0f23..9292434 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ }, "devDependencies": { "@eslint/js": "^9.39.5", + "@microsoft/api-extractor": "^7.59.4", "@nestjs/common": "^11.1.28", "@nestjs/core": "^11.1.28", "@nestjs/platform-express": "^11.1.28", @@ -1731,6 +1732,138 @@ "node": ">=8" } }, + "node_modules/@microsoft/api-extractor": { + "version": "7.59.4", + "resolved": "https://registry.npmjs.org/@microsoft/api-extractor/-/api-extractor-7.59.4.tgz", + "integrity": "sha512-XqseDKIw736qlhQwS9SOpbY4veOiP2Nc7YiWmgXXBmeA3kY9qGXw+Tu7DFpU9FvXywE1z8SvLJKUVxFpcX0kig==", + "dev": true, + "license": "MIT", + "dependencies": { + "@microsoft/api-extractor-model": "7.33.15", + "@microsoft/tsdoc": "~0.17.0", + "@microsoft/tsdoc-config": "~0.18.2", + "@rushstack/node-core-library": "5.25.1", + "@rushstack/rig-package": "0.7.4", + "@rushstack/terminal": "0.24.7", + "@rushstack/ts-command-line": "5.3.17", + "diff": "~8.0.2", + "minimatch": "10.2.3", + "resolve": "~1.22.1", + "semver": "~7.7.4", + "source-map": "~0.6.1", + "typescript": "5.9.3" + }, + "bin": { + "api-extractor": "bin/api-extractor" + }, + "engines": { + "node": ">=20.9.0" + } + }, + "node_modules/@microsoft/api-extractor-model": { + "version": "7.33.15", + "resolved": "https://registry.npmjs.org/@microsoft/api-extractor-model/-/api-extractor-model-7.33.15.tgz", + "integrity": "sha512-UpCnItIJwu03iNTWtJVKv8Qbf0MXN7WLQZUail9cpAQmnZiIX36YPRRoRxz0pocwytzUpmJhstsLkyW5tsaHBA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@microsoft/tsdoc": "~0.17.0", + "@microsoft/tsdoc-config": "~0.18.2", + "@rushstack/node-core-library": "5.25.1" + }, + "engines": { + "node": ">=20.9.0" + } + }, + "node_modules/@microsoft/api-extractor/node_modules/balanced-match": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz", + "integrity": "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==", + "dev": true, + "license": "MIT", + "engines": { + "node": "18 || 20 || >=22" + } + }, + "node_modules/@microsoft/api-extractor/node_modules/brace-expansion": { + "version": "5.0.12", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.12.tgz", + "integrity": "sha512-YovQ3rzhaLMIrDjNDMkNS01tea93qhEhG5xy8f6+R0l+dw3Ki+5sCoIoI942iuLZTHWogWktgwVDhU09iNEimQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^4.0.2" + }, + "engines": { + "node": "20 || >=22" + } + }, + "node_modules/@microsoft/api-extractor/node_modules/minimatch": { + "version": "10.2.3", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.3.tgz", + "integrity": "sha512-Rwi3pnapEqirPSbWbrZaa6N3nmqq4Xer/2XooiOKyV3q12ML06f7MOuc5DVH8ONZIFhwIYQ3yzPH4nt7iWHaTg==", + "dev": true, + "license": "BlueOak-1.0.0", + "dependencies": { + "brace-expansion": "^5.0.2" + }, + "engines": { + "node": "18 || 20 || >=22" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/@microsoft/api-extractor/node_modules/semver": { + "version": "7.7.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.4.tgz", + "integrity": "sha512-vFKC2IEtQnVhpT78h1Yp8wzwrf8CM+MzKMHGJZfBtzhZNycRFnXsHk6E5TxIkkMsgNS7mdX3AGB7x2QM2di4lA==", + "dev": true, + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@microsoft/tsdoc": { + "version": "0.17.1", + "resolved": "https://registry.npmjs.org/@microsoft/tsdoc/-/tsdoc-0.17.1.tgz", + "integrity": "sha512-VHyYyyoH63jFoO3shpw9Zfijk5v/9p/VrClW35z0/q6ooK7sSmxpzOkS4iZPxs3vO4XtBW4H38HRAKkAMIK7DA==", + "dev": true, + "license": "MIT" + }, + "node_modules/@microsoft/tsdoc-config": { + "version": "0.18.3", + "resolved": "https://registry.npmjs.org/@microsoft/tsdoc-config/-/tsdoc-config-0.18.3.tgz", + "integrity": "sha512-0I0rGXo1eJziw3EEErkDS9p/0RzBcyOiV+zbSDqOZTeURmhtut+WIvpih0LM5g+ZpZ9SyFxDfkhAcl/r8e2zGw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@microsoft/tsdoc": "0.17.1", + "ajv": "~8.18.0", + "jju": "~1.4.0", + "resolve": "~1.22.2" + } + }, + "node_modules/@microsoft/tsdoc-config/node_modules/ajv": { + "version": "8.18.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.18.0.tgz", + "integrity": "sha512-PlXPeEWMXMZ7sPYOHqmDyCJzcfNrUr3fGNKtezX14ykXOEIvyK81d+qydx89KY5O71FKMPaQ2vBfBFI5NHR63A==", + "dev": true, + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.3", + "fast-uri": "^3.0.1", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, "node_modules/@minimistjs/subarg": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/@minimistjs/subarg/-/subarg-1.0.0.tgz", @@ -2288,6 +2421,141 @@ "win32" ] }, + "node_modules/@rushstack/node-core-library": { + "version": "5.25.1", + "resolved": "https://registry.npmjs.org/@rushstack/node-core-library/-/node-core-library-5.25.1.tgz", + "integrity": "sha512-ozoRDwIx3jStOYpx86rFyXH4SaUR+DVT6HubQ59avLplJkWXSm5InztYH7RrOzzq9PJXTdq9/+lKX06SfkLVsA==", + "dev": true, + "license": "MIT", + "dependencies": { + "ajv": "~8.20.0", + "ajv-draft-04": "~1.0.0", + "ajv-formats": "~3.0.1", + "fs-extra": "~11.3.0", + "import-lazy": "~4.0.0", + "jju": "~1.4.0", + "resolve": "~1.22.1", + "semver": "~7.7.4" + }, + "engines": { + "node": ">=20.9.0" + }, + "peerDependencies": { + "@types/node": "*" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + } + } + }, + "node_modules/@rushstack/node-core-library/node_modules/semver": { + "version": "7.7.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.4.tgz", + "integrity": "sha512-vFKC2IEtQnVhpT78h1Yp8wzwrf8CM+MzKMHGJZfBtzhZNycRFnXsHk6E5TxIkkMsgNS7mdX3AGB7x2QM2di4lA==", + "dev": true, + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@rushstack/problem-matcher": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/@rushstack/problem-matcher/-/problem-matcher-0.2.1.tgz", + "integrity": "sha512-gulfhBs6n+I5b7DvjKRfhMGyUejtSgOHTclF/eONr8hcgF1APEDjhxIsfdUYYMzC3rvLwGluqLjbwCFZ8nxrog==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "@types/node": "*" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + } + } + }, + "node_modules/@rushstack/rig-package": { + "version": "0.7.4", + "resolved": "https://registry.npmjs.org/@rushstack/rig-package/-/rig-package-0.7.4.tgz", + "integrity": "sha512-SHZdzc9b2ptUb5uvRWALtAceD/QKZ4UAnZjcaKviTMPmHBnW14gs7XDocn6sDv2EqgnxxFPFkpV7/I3cUijCbw==", + "dev": true, + "license": "MIT", + "dependencies": { + "jju": "~1.4.0", + "resolve": "~1.22.1" + }, + "engines": { + "node": ">=20.9.0" + } + }, + "node_modules/@rushstack/terminal": { + "version": "0.24.7", + "resolved": "https://registry.npmjs.org/@rushstack/terminal/-/terminal-0.24.7.tgz", + "integrity": "sha512-o8J9nHOIwfYb0s0eG2WYhx7ed3YIvBXQHVFxYdXCmVdBOkTkdArJcgVzRS8ewUepmlic4nGgJPjKIVaNKSqEnA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@rushstack/node-core-library": "5.25.1", + "@rushstack/problem-matcher": "0.2.1", + "supports-color": "~8.1.1" + }, + "engines": { + "node": ">=20.9.0" + }, + "peerDependencies": { + "@types/node": "*" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + } + } + }, + "node_modules/@rushstack/terminal/node_modules/supports-color": { + "version": "8.1.1", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz", + "integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/supports-color?sponsor=1" + } + }, + "node_modules/@rushstack/ts-command-line": { + "version": "5.3.17", + "resolved": "https://registry.npmjs.org/@rushstack/ts-command-line/-/ts-command-line-5.3.17.tgz", + "integrity": "sha512-pIwhWawZXAT0nTXwvcE/InQ7uaVAgSeIzILMb2mBrI01Hz1yEvxrhV2+DE2Fzux8aZY9OJTdLsI+sk9kZDuAJw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@rushstack/terminal": "0.24.7", + "@types/argparse": "1.0.38", + "argparse": "~1.0.9", + "string-argv": "~0.3.1" + }, + "engines": { + "node": ">=20.9.0" + } + }, + "node_modules/@rushstack/ts-command-line/node_modules/argparse": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", + "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", + "dev": true, + "license": "MIT", + "dependencies": { + "sprintf-js": "~1.0.2" + } + }, "node_modules/@sindresorhus/is": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-7.2.0.tgz", @@ -2361,6 +2629,13 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/argparse": { + "version": "1.0.38", + "resolved": "https://registry.npmjs.org/@types/argparse/-/argparse-1.0.38.tgz", + "integrity": "sha512-ebDJ9b0e702Yr7pWgB0jzm+CX4Srzz8RcXtLJDJB+BSccqMa36uyH/zUsSYao5+BD1ytv3k3rPYCq4mAE1hsXA==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/autocannon": { "version": "7.12.7", "resolved": "https://registry.npmjs.org/@types/autocannon/-/autocannon-7.12.7.tgz", @@ -2987,6 +3262,21 @@ "url": "https://github.com/sponsors/epoberezkin" } }, + "node_modules/ajv-draft-04": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/ajv-draft-04/-/ajv-draft-04-1.0.0.tgz", + "integrity": "sha512-mv00Te6nmYbRp5DCwclxtt7yV/joXJPGS7nM+97GdxvuttCOfgI3K4U25zboyeX0O+myI8ERluxQe5wljMmVIw==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "ajv": "^8.5.0" + }, + "peerDependenciesMeta": { + "ajv": { + "optional": true + } + } + }, "node_modules/ajv-formats": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-3.0.1.tgz", @@ -3725,6 +4015,16 @@ "node": ">=8" } }, + "node_modules/diff": { + "version": "8.0.4", + "resolved": "https://registry.npmjs.org/diff/-/diff-8.0.4.tgz", + "integrity": "sha512-DPi0FmjiSU5EvQV0++GFDOJ9ASQUVFh5kD+OzOnYdi7n3Wpm9hWWGfB/O2blfHcMVTL5WkQXSnRiK9makhrcnw==", + "dev": true, + "license": "BSD-3-Clause", + "engines": { + "node": ">=0.3.1" + } + }, "node_modules/dunder-proto": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", @@ -4558,6 +4858,21 @@ "node": ">= 0.8" } }, + "node_modules/fs-extra": { + "version": "11.3.6", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.3.6.tgz", + "integrity": "sha512-w8ZNZr2mKIc7qeNaQ9AVPT1+iFaI+Avd4xudVOvdDJ8VytREi1Ft5Ih7hd9jjehod8vAM5GMsfQ/TpPf4EyoEA==", + "dev": true, + "license": "MIT", + "dependencies": { + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + }, + "engines": { + "node": ">=14.14" + } + }, "node_modules/fsevents": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", @@ -4709,6 +5024,13 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/graceful-fs": { + "version": "4.2.11", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", + "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==", + "dev": true, + "license": "ISC" + }, "node_modules/graphql": { "version": "16.14.2", "resolved": "https://registry.npmjs.org/graphql/-/graphql-16.14.2.tgz", @@ -4905,6 +5227,16 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/import-lazy": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/import-lazy/-/import-lazy-4.0.0.tgz", + "integrity": "sha512-rKtvo6a868b5Hu3heneU+L4yEQ4jYKLtjpnPeUdK7h0yzXGmyBTypknlkCvHFBqfX9YlorEiMM6Dnq/5atfHkw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/imurmurhash": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", @@ -4939,6 +5271,22 @@ "node": ">= 10" } }, + "node_modules/is-core-module": { + "version": "2.17.0", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.17.0.tgz", + "integrity": "sha512-J/vG0zBCbIKOQFfufSwyXdMrsohyJIUNkrnmo6WZGzoM7tr/lsbfW5b2BvisL6zsyMzK9UxV9L6c7AoFbyXHOA==", + "dev": true, + "license": "MIT", + "dependencies": { + "hasown": "^2.0.4" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/is-docker": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-3.0.0.tgz", @@ -5076,6 +5424,13 @@ "@pkgjs/parseargs": "^0.11.0" } }, + "node_modules/jju": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/jju/-/jju-1.4.0.tgz", + "integrity": "sha512-8wb9Yw966OSxApiCt0K3yNJL8pnNeIv+OEq2YMidz4FKP6nonSRoOXc80iXY4JaN2FC11B9qsNmDsm+ZOfMROA==", + "dev": true, + "license": "MIT" + }, "node_modules/joycon": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/joycon/-/joycon-3.1.1.tgz", @@ -5179,6 +5534,19 @@ "dev": true, "license": "MIT" }, + "node_modules/jsonfile": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.2.1.tgz", + "integrity": "sha512-zwOTdL3rFQ/lRdBnntKVOX6k5cKJwEc1HdilT71BWEu7J41gXIB2MRp+vxduPSwZJPWBxEzv4yH1wYLJGUHX4Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "universalify": "^2.0.0" + }, + "optionalDependencies": { + "graceful-fs": "^4.1.6" + } + }, "node_modules/keyv": { "version": "4.5.4", "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", @@ -5882,6 +6250,13 @@ "node": ">=8" } }, + "node_modules/path-parse": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", + "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", + "dev": true, + "license": "MIT" + }, "node_modules/path-scurry": { "version": "1.11.1", "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.11.1.tgz", @@ -6296,6 +6671,28 @@ "node": ">=0.10.0" } }, + "node_modules/resolve": { + "version": "1.22.13", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.13.tgz", + "integrity": "sha512-Dj/cW9zBV2aRj6XzCxuGIs3ESZKv02jixne3q6jFZYZ3/Tg09gHHviSMDL4kObh9pqSahdRHEnDoaP2gn8YLhA==", + "dev": true, + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "is-core-module": "^2.17.0", + "path-parse": "^1.0.7", + "supports-preserve-symlinks-flag": "^1.0.0" + }, + "bin": { + "resolve": "bin/resolve" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/resolve-from": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", @@ -6777,6 +7174,13 @@ "node": ">= 10.x" } }, + "node_modules/sprintf-js": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", + "integrity": "sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==", + "dev": true, + "license": "BSD-3-Clause" + }, "node_modules/stackback": { "version": "0.0.2", "resolved": "https://registry.npmjs.org/stackback/-/stackback-0.0.2.tgz", @@ -6810,6 +7214,16 @@ "node": ">=10.0.0" } }, + "node_modules/string-argv": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/string-argv/-/string-argv-0.3.2.tgz", + "integrity": "sha512-aqD2Q0144Z+/RqG52NeHEkZauTAUWJO8c6yTftGJKO3Tja5tUgIfmIl6kExvhtxSDP7fXB6DvzkfMpCd/F3G+Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.6.19" + } + }, "node_modules/string-width": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", @@ -6944,6 +7358,19 @@ "node": ">=8" } }, + "node_modules/supports-preserve-symlinks-flag": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", + "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/thenify": { "version": "3.3.1", "resolved": "https://registry.npmjs.org/thenify/-/thenify-3.3.1.tgz", @@ -7824,6 +8251,16 @@ "dev": true, "license": "MIT" }, + "node_modules/universalify": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", + "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 10.0.0" + } + }, "node_modules/unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", diff --git a/package.json b/package.json index 7765cca..a12611c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@green-tea/core", "version": "26.9.0-beta.2", - "description": "A zen, opinionated, type-safe framework \u2014 your API is a graph, not a middleware chain.", + "description": "A zen, opinionated, type-safe framework — your API is a graph, not a middleware chain.", "license": "MIT", "author": "green-tea contributors ", "repository": { @@ -86,6 +86,8 @@ ], "scripts": { "build": "tsup", + "api": "node scripts/api-report.mjs", + "api:check": "node scripts/api-report.mjs --check", "test": "vitest run", "test:dev": "vitest", "test:deno": "deno test --allow-net --allow-read --allow-run --allow-env --no-check test/deno/", @@ -137,6 +139,7 @@ }, "devDependencies": { "@eslint/js": "^9.39.5", + "@microsoft/api-extractor": "^7.59.4", "@nestjs/common": "^11.1.28", "@nestjs/core": "^11.1.28", "@nestjs/platform-express": "^11.1.28", @@ -150,8 +153,8 @@ "autocannon": "^8.0.0", "busboy": "^1.6.0", "cognitive-complexity-ts": "^0.8.2", - "eslint": "^9.39.5", "esbuild": "0.27.2", + "eslint": "^9.39.5", "express": "^5.2.1", "fastify": "^5.12.5", "graphql": "^16.9.0", diff --git a/scripts/api-report.mjs b/scripts/api-report.mjs new file mode 100644 index 0000000..6a567d6 --- /dev/null +++ b/scripts/api-report.mjs @@ -0,0 +1,70 @@ +// API report per export-map entry (CARD-22, D20). Reads the `.d.ts` that `tsup` emits, so run +// `npm run build` first. `npm run api:check` fails when a report in `api/` differs from what the +// build declares; `npm run api` rewrites them. A deliberate API change is a regenerated report in +// the same PR, which is what makes the change visible to a reviewer at all. +import { Extractor, ExtractorConfig } from '@microsoft/api-extractor'; +import { readFileSync } from 'node:fs'; +import { resolve } from 'node:path'; + +const check = process.argv.includes('--check'); +const root = resolve(import.meta.dirname, '..'); +const entries = ['index', 'deno', 'bun', 'edge']; +let failed = false; + +// An adapter's signatures name root types (`App`, `Logger`, …) that its own entry does not +// re-export. Those are nameable from `@green-tea/core`, so they pass; anything else still fails. +const rootExports = new Set( + [...readFileSync(resolve(root, 'dist/index.d.ts'), 'utf8').matchAll(/export \{([^}]*)\}/g)] + .flatMap((m) => m[1].split(',')) + .map((name) => name.trim().replace(/^type /, '').split(' as ').pop()), +); +const exportedByRoot = (message) => + message.messageId === 'ae-forgotten-export' && rootExports.has(/The symbol "([^"]+)"/.exec(message.text)?.[1]); + +for (const entry of entries) { + const config = ExtractorConfig.prepare({ + configObject: { + projectFolder: root, + mainEntryPointFilePath: `/dist/${entry}.d.ts`, + compiler: { tsconfigFilePath: '/tsconfig.json' }, + apiReport: { + enabled: true, + reportFileName: `${entry}.api.md`, + reportFolder: '/api/', + reportTempFolder: '/node_modules/.cache/api-extractor/', + }, + docModel: { enabled: false }, + dtsRollup: { enabled: false }, + tsdocMetadata: { enabled: false }, + messages: { + // The report records the surface; it is not a TSDoc linter. The one message that fails the + // run is a public signature naming a type the entry does not export (D19). + compilerMessageReporting: { default: { logLevel: 'warning' } }, + extractorMessageReporting: { + default: { logLevel: 'none' }, + 'ae-forgotten-export': { logLevel: 'error', addToApiReportFile: false }, + }, + tsdocMessageReporting: { default: { logLevel: 'none' } }, + }, + }, + configObjectFullPath: resolve(root, 'api-extractor.json'), + packageJsonFullPath: resolve(root, 'package.json'), + }); + + const result = Extractor.invoke(config, { + localBuild: !check, + messageCallback: (message) => { + if (entry !== 'index' && exportedByRoot(message)) message.logLevel = 'none'; + }, + }); + if (!result.succeeded) { + failed = true; + console.error( + check && result.apiReportChanged + ? `api/${entry}.api.md is out of date: run \`npm run build && npm run api\` and commit the report.` + : `api report for ${entry} failed (${result.errorCount} error(s)).`, + ); + } +} + +process.exit(failed ? 1 : 0);