`sseEncoder` wrote one field. With no `id:` on the wire the browser had nothing to put in
`Last-Event-ID`, so every automatic reconnect rebuilt the route's iterable from its start
and lost the gap in silence — a healthy-looking stream that had simply skipped events.
Half of this already worked and it was worth checking before designing anything: the
request envelope has always carried every header, so a handler could already read
`@header('last-event-id')`. It just always arrived empty, because we never gave the
browser an id to send.
`sse(data, { id, event, retry })` tags a stream item; `sseEncoder` writes the fields ahead
of `data:`. An app that never calls it sees byte-identical output. `event:` and `retry:`
come along because the envelope carries them for free and neither was reachable before.
**green-tea stores nothing.** No buffer, no retention window, no replay. The framework
carries the marker in both directions and the handler decides what the gap means, because
only the source knows: a paged log re-reads from an offset, a live sensor has no past
worth delivering. Framework-managed replay would need a stream identity that survives a
disconnect — which does not exist, since every request builds a fresh iterable — plus a
retention policy no default can get right and an in-process buffer that breaks the moment
there are two instances. This commit is also the prerequisite for any of that: whatever
replay might land later keys on these ids.
An id with a newline is rejected, not stripped. An id is exactly the value most likely to
be derived from a request — a cursor, a page token — and the SSE format is line-based, so
one newline lets a caller append arbitrary fields to somebody else's stream. Stripping
would resume from the wrong place invisibly, which is the failure this whole feature
exists to close, so it throws where the stream can report it.
`ndjsonEncoder` unwraps the payload and drops the fields: a `negotiate` route yields the
same items to both encoders, and NDJSON has no frame to carry them and no resumption
protocol to use them.
Verified non-vacuous: reverting just the two `encode` functions fails the six framing and
round-trip assertions and leaves the validation ones passing, which is the right split.
Closes #46
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
94 lines
2.9 KiB
TypeScript
94 lines
2.9 KiB
TypeScript
/**
|
|
* @green-tea/core — a decorator-driven, type-safe HTTP framework.
|
|
* Public API barrel: application bootstrap, routing/DI decorators, streaming,
|
|
* request validation, security helpers, and the cross-server mesh.
|
|
*/
|
|
import 'reflect-metadata';
|
|
|
|
/** Package version, replaced at publish time. */
|
|
export const VERSION = '26.8.0-beta.0';
|
|
|
|
// Application
|
|
export { createApp } from './app';
|
|
export type { App, InspectLine, Explain, MeshConfig } from './app';
|
|
|
|
// Graph visualization
|
|
export { toMermaid, toDOT } from './graph-viz';
|
|
export type { GraphView } from './graph-viz';
|
|
export { buildOpenApi } from './openapi';
|
|
export type { OpenApiDoc, OpenApiInfo, OpenApiRoute } from './openapi';
|
|
|
|
// Views
|
|
export { render } from './views';
|
|
|
|
// Routing & decorators
|
|
export {
|
|
Provider,
|
|
Step,
|
|
Route,
|
|
Get,
|
|
Head,
|
|
Module,
|
|
Transformer,
|
|
Sse,
|
|
Ws,
|
|
Stream,
|
|
Post,
|
|
Put,
|
|
Patch,
|
|
Delete,
|
|
Options,
|
|
Html,
|
|
} from './metadata';
|
|
export type { Transport, HttpMethod, RouteDecorator, TransformerFn } from './metadata';
|
|
export type { Plugin, PluginApi, ScopeApi, ScopeNode } from './plugin';
|
|
export type { Hooks } from './app';
|
|
export type { TeardownFn } from './lifecycle';
|
|
|
|
// Transformers & error signals
|
|
export { JsonTransformer } from './transformers';
|
|
export type { ErrorRenderer, ErrorRequest, ErrorResponse } from './transformers';
|
|
export {
|
|
HttpError,
|
|
Unauthorized,
|
|
NotFound,
|
|
Redirect,
|
|
NotModified,
|
|
ValidationError,
|
|
TransportMismatchError,
|
|
} from './signals';
|
|
|
|
// Bus & flow
|
|
export { Bus } from './bus';
|
|
export type { LifecycleEvent, EventPayload, Correlation, Events } from './bus';
|
|
export { flow, Flow } from './flow';
|
|
export type { StepFn, CompiledFlow } from './flow';
|
|
|
|
// Parameter decorators
|
|
export { needs, ctx, param, query, body, headers, header, inbound, abort } from './params';
|
|
export type { Query, Headers, Context, ArgSpec, ArgDecorator } from './params';
|
|
|
|
// Observability
|
|
export { createDefaultLogger, logRequests, withConsoleFallback } from './logger';
|
|
export type { Logger, LogLevel, LogFields } from './logger';
|
|
|
|
// Streaming
|
|
export { channel, isAsyncIterable } from './channel';
|
|
export type { Channel } from './channel';
|
|
export { Rooms } from './rooms';
|
|
export { sse, isSseEvent, sseEncoder, ndjsonEncoder } from './encoders';
|
|
export type { StreamEncoder, SseEvent, SseFields } from './encoders';
|
|
|
|
// HTTP, security & validation
|
|
export type { RequestLimits } from './http';
|
|
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';
|
|
|
|
// Mesh
|
|
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';
|