Core
defineEventStream
Declare a typed Server-Sent Events endpoint.
@defjs/core · Function
Signature
function defineEventStream< const P extends string, const M extends string = "GET", TInput extends AnyStruct | undefined = undefined, TEvents extends EventStructs = EventStructs, TError extends AnyStruct | undefined = undefined, >( definition: Omit<EventStreamDefinitionBase<TEvents>, "method" | "path"> & EventStreamErrorField<TError> & { input?: TInput; method?: M; path: P; } & BuilderField< NoInfer<TInput>, EventStreamRequestShape<NoInfer<P>, NoInfer<M>> >, ): EventStreamEndpoint<EndpointArgs<TInput>, EventStreamData<TEvents>, TError>;
Pass path, event structs, and buffer/queue limits. Call the returned operation with a client and, when declared, the input.
- definition —
path, aneventsmap, and the requiredmaxBufferSizeandmaxQueueSizelimits (positive safe integers). Optionalmethod(default'GET'),operation,input, anderror. A declaredinputalways requires an explicitbuilder.inputonly defines the parameters; the builder alone decides where each value goes. Only definitions withoutinputmay omitbuilder.
EventStreamDefinitionBase, EventStreamErrorField, and BuilderField are internal helper types: error is required only when TError is a struct, and builder is (input: BuilderInput<TInput>) => EventStreamRequestShape when input is declared.
Parameters
Prop
Type
definition Omit<EventStreamDefinitionBase<TEvents>, "method" | "path"> &
EventStreamErrorField<TError> & {
input?: TInput;
method?: M;
path: P;
} & BuilderField<
NoInfer<TInput>,
EventStreamRequestShape<NoInfer<P>, NoInfer<M>>
>SSE contract (path, events, buffer limits, optional input).
Returns
An operation (client, ...input) => Promise<error-first tuple>.
Examples
import { defineEventStream, struct } from "@defjs/core"; const ticks = defineEventStream({ maxBufferSize: 64 * 1024, maxQueueSize: 100, path: "/ticks", events: { message: struct.object({ text: struct.string() }) }, });