UNPKG

@nestjs/common

Version:

Decorators, pipes, exceptions and utilities for NestJS applications: @Controller(), @Injectable(), @Body(), ValidationPipe, HttpException and more.

51 lines (50 loc) • 2.13 kB
import { RequestMethod } from '../../enums/request-method.enum.js'; /** * Interface defining options that can be passed to `@Sse()` decorator * * @publicApi */ export interface SseOptions { /** * HTTP request method of the route (default: `RequestMethod.GET`). */ method?: RequestMethod; /** * Maximum number of characters of event data (`data` and `comment`, plus * `type` and `id`) that may wait for a client that is not reading its * events (default: 4 * 1024 * 1024, i.e. 4M characters). An event counts * for at least 16 characters, so that events with little or no data (e.g. * `{ type: 'changed', data: '' }`) are limited in number too. Events wait * once the stream and socket buffers are full, as the producer cannot be * paused. Past this limit, the connection is dropped as if the client had * disconnected, and a warning is logged. Set to 0 or `Infinity` to disable. */ maxPendingDataLength?: number; } /** * Declares this route as a Server-Sent-Events endpoint * * Events wait in memory for a client that is not reading them. Once more than * `maxPendingDataLength` characters of event data (4M by default) wait for a * client whose stream is backed up, its connection is dropped. An * `EventSource` then reconnects, sending the id of the last event it received. * An event counts for at least 16 characters, whatever it carries. * Raise the limit for a route that streams bulk data faster than its clients * read, or set it to 0 or `Infinity` to lift it. * * @param path route path (default: `/`) * @param options `SseOptions` object specifying: * - `method` - HTTP request method of the route (default: `GET`). * - `maxPendingDataLength` - maximum number of characters of event data that * may wait for a client that is not reading them (default: 4M). 0 or * `Infinity` lifts the limit. * * @example * ```ts * @Sse('logs', { maxPendingDataLength: 64 * 1024 * 1024 }) * logs(): Observable<MessageEvent> { ... } * ``` * * @publicApi */ export declare function Sse(path?: string, options?: SseOptions): MethodDecorator;