import type { BaseSchema, Infer } from "anyvali"; import type { RouteHandlerContext } from "../contracts/route.js"; import { type BpStreamHandler } from "../contracts/streaming.js"; /** * Schema configuration for a streaming route handler. * `item` is required (the canonical per-frame payload); `summary` is the * optional end-of-stream aggregate. Cross-item invariants belong in `summary`, * not `item` - see spec/streaming.md section 3. */ export interface StreamHandlerSchemas, TSummary extends BaseSchema | undefined = undefined, TQuery extends BaseSchema | undefined = undefined, THeaders extends BaseSchema | undefined = undefined, TParamsSchema extends BaseSchema | undefined = undefined> { readonly item: TItem; readonly summary?: TSummary; readonly params?: TParamsSchema; readonly query?: TQuery; readonly headers?: THeaders; } type SchemaOutput | undefined, TDefault> = T extends BaseSchema ? Infer : TDefault; /** Generator return type: summary value when a summary schema is declared, else void. */ type SummaryReturn | undefined> = TSummary extends BaseSchema ? Infer : void; /** * Create a streaming route handler. Mirrors `createHandler` but the handler is * an async generator yielding items; the generator's `return` value is the * summary frame (when a `summary` schema is declared). * * The adapter - not this factory - drives the stream: it validates every * yielded item against `schemas.item` before emission and negotiates the * representation (buffered JSON / NDJSON frames / themed HTML over SSE). * * The buffered JSON response schema (`{ items, summary? }`) is derived here so * codegen and the manifest never need a hand-written ResponseSchema for * streaming views. * * @example * ```ts * export const handleGet = createStreamHandler( * { item: ItemSchema, summary: SummarySchema, query: QuerySchema }, * async function* (ctx) { * for (const row of await loadRows(ctx.query.q)) yield row; * return { total: 12 }; * } * ); * ``` */ export declare function createStreamHandler, TSummary extends BaseSchema | undefined = undefined, TQuery extends BaseSchema | undefined = undefined, THeaders extends BaseSchema | undefined = undefined, TParams = Record, TPlugin = unknown, TServiceConfig = Record, TParamsSchema extends BaseSchema | undefined = undefined>(schemas: StreamHandlerSchemas, handler: (ctx: RouteHandlerContext, SchemaOutput>, SchemaOutput>, Record, TPlugin, TServiceConfig>) => AsyncGenerator, SummaryReturn, void>): BpStreamHandler, SummaryReturn, SchemaOutput, SchemaOutput>, SchemaOutput>>; export declare namespace createStreamHandler { function forContext>(): , TSummary extends BaseSchema | undefined = undefined, TQuery extends BaseSchema | undefined = undefined, THeaders extends BaseSchema | undefined = undefined, TParams = Record, TParamsSchema extends BaseSchema | undefined = undefined>(schemas: StreamHandlerSchemas, handler: (ctx: RouteHandlerContext, SchemaOutput>, SchemaOutput>, Record, TPlugin, TServiceConfig>) => AsyncGenerator, SummaryReturn, void>) => BpStreamHandler, SummaryReturn, SchemaOutput, SchemaOutput>, SchemaOutput>>; } export {}; //# sourceMappingURL=streamHandler.d.ts.map