@orkestrel/server 0.0.23 → 0.0.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,6 +5,7 @@ import type { EmitterErrorHandler } from '@orkestrel/emitter';
5
5
  import type { EmitterHooks } from '@orkestrel/emitter';
6
6
  import type { EmitterInterface } from '@orkestrel/emitter';
7
7
  import type { IncomingMessage } from 'node:http';
8
+ import type { Server as Server_2 } from 'node:http';
8
9
 
9
10
  /**
10
11
  * Represents one parsed entry of a weighted `Accept` / `Accept-Encoding` /
@@ -275,6 +276,9 @@ export declare interface Connection {
275
276
  */
276
277
  export declare type ConnectionStateFunction<TState> = (connection: Connection) => TState;
277
278
 
279
+ /** Names the identity brand carried by body-limit errors across package copies. */
280
+ export declare const CONTENT_TOO_LARGE_ERROR_BRAND: unique symbol;
281
+
278
282
  /**
279
283
  * Represents the {@link HTTPError} thrown when a request body exceeds the body
280
284
  * pipeline's size limit — a `413 Content Too Large`.
@@ -391,11 +395,11 @@ export declare function createNegotiator(): NegotiatorInterface;
391
395
  export declare function createServer<TState>(options: ServerOptions<TState>): ServerInterface<TState>;
392
396
 
393
397
  /**
394
- * Creates a {@link StreamInterface} — a generic Server-Sent-Events stream whose
398
+ * Creates an {@link SSEStreamInterface} — a generic Server-Sent-Events stream whose
395
399
  * `response` is a fetch-standard streaming `Response` a route returns.
396
400
  *
397
401
  * @param options - {@link StreamOptions}
398
- * @returns A {@link StreamInterface} whose stream is open
402
+ * @returns An {@link SSEStreamInterface} whose stream is open
399
403
  *
400
404
  * @example
401
405
  * ```ts
@@ -410,7 +414,7 @@ export declare function createServer<TState>(options: ServerOptions<TState>): Se
410
414
  * // return stream.response from the route handler
411
415
  * ```
412
416
  */
413
- export declare function createStream(options?: StreamOptions): StreamInterface;
417
+ export declare function createStream(options?: StreamOptions): SSEStreamInterface;
414
418
 
415
419
  /**
416
420
  * Decodes a cookie value with `decodeURIComponent`, falling back to the raw
@@ -621,7 +625,7 @@ export declare const HTTP_ERROR_BRAND: unique symbol;
621
625
  export declare class HTTPError extends Error {
622
626
  readonly status: number;
623
627
  readonly context?: Readonly<Record<string, unknown>>;
624
- readonly [HTTP_ERROR_BRAND] = true;
628
+ readonly [HTTP_ERROR_BRAND]: this;
625
629
  constructor(status: number, message: string, context?: Readonly<Record<string, unknown>>);
626
630
  }
627
631
 
@@ -669,6 +673,16 @@ export declare function isAddressInfo(value: unknown): value is AddressInfo;
669
673
  */
670
674
  export declare function isCompressibleType(type: string): boolean;
671
675
 
676
+ /**
677
+ * Recognizes a branded body-limit error, including subclasses and other package copies.
678
+ *
679
+ * @example
680
+ * ```ts
681
+ * isContentTooLargeError(new ContentTooLargeError(1024)) // true
682
+ * ```
683
+ */
684
+ export declare function isContentTooLargeError(value: unknown): value is ContentTooLargeError;
685
+
672
686
  /**
673
687
  * Checks whether a string is safe to interpolate as a `Set-Cookie` attribute value —
674
688
  * the guard {@link serializeCookie} applies to a `Domain` and a `Path` before it
@@ -731,20 +745,16 @@ export declare function isDangerousKey(key: string): boolean;
731
745
  /**
732
746
  * Narrows an unknown caught value to an {@link HTTPError}, including a subclass such
733
747
  * as {@link ContentTooLargeError}, and recognizes an instance from another copy of
734
- * this package through a structural brand fallback.
748
+ * this package through its own identity brand.
735
749
  *
736
750
  * @param value - The value to test (typically a `catch` binding)
737
751
  * @returns True if `value` is an {@link HTTPError}; false otherwise
738
752
  *
739
753
  * @remarks
740
- * Tries `instanceof` first, then falls back to a total structural check for
741
- * an instance built by a different copy of this package (the dual-package
742
- * hazard — version skew, a linked workspace duplicate) whose `HTTPError`
743
- * constructor is a distinct object from this copy's: the value must carry
744
- * the cross-copy brand (interned by using `Symbol.for`, so every copy resolves the
745
- * same key) and expose the exact fields the server's error boundary reads off
746
- * a recognized `HTTPError` — a numeric `status` and a string `message`. A
747
- * plain object that merely carries a `status` without the brand is rejected.
754
+ * Requires a global Error instance with a derived prototype, its own identity brand,
755
+ * a numeric status, a string message, and an absent or object-valued context.
756
+ * Callable contexts are accepted. Subclass names are unrestricted.
757
+ * Transparent proxies and branded plain objects are rejected.
748
758
  *
749
759
  * @example
750
760
  * ```ts
@@ -767,10 +777,9 @@ export declare function isHTTPError(value: unknown): value is HTTPError;
767
777
  * @returns True if `value` is a {@link ServerError}; false otherwise
768
778
  *
769
779
  * @remarks
770
- * Recognizes an instance built by this copy of the package. A `ServerError`
771
- * is raised by a `Server` to the caller that invoked it directly, so both sides
772
- * hold the same copy and the cross-copy brand {@link isHTTPError} needs has no
773
- * consumer here.
780
+ * Requires the own identity brand, a declared code, a string message, and an absent
781
+ * or object-valued context on a global Error with a derived prototype.
782
+ * Callable contexts and subclasses are accepted; transparent proxies are rejected.
774
783
  *
775
784
  * @example
776
785
  * ```ts
@@ -811,6 +820,28 @@ export declare function isServerError(value: unknown): value is ServerError;
811
820
  */
812
821
  export declare function isValidRequestId(value: string): boolean;
813
822
 
823
+ /**
824
+ * Yields matching media ranges through the first exact rejection.
825
+ *
826
+ * @example
827
+ * ```ts
828
+ * Array.from(iterateMediaMatches([{ value: 'text/plain', q: 1 }], 'text/plain'))
829
+ * // [{ q: 1, rank: 0 }]
830
+ * ```
831
+ */
832
+ export declare function iterateMediaMatches(entries: readonly AcceptEntry[], candidate: string): Generator<MediaMatch, void, unknown>;
833
+
834
+ /**
835
+ * Yields the same lazily collected request-body promise on every read.
836
+ *
837
+ * @example
838
+ * ```ts
839
+ * const bodies = iterateRequestBody(new Request('http://localhost/'), 1024)
840
+ * bodies.next().value === bodies.next().value // true
841
+ * ```
842
+ */
843
+ export declare function iterateRequestBody(request: Request, limit: number): Generator<Promise<unknown>, never, unknown>;
844
+
814
845
  /**
815
846
  * Checks whether a request's `If-None-Match` header matches a resource's current
816
847
  * `ETag` — the RFC 7232 §2.3.2 weak comparison.
@@ -1617,6 +1648,25 @@ export declare class Server<TState> implements ServerInterface<TState> {
1617
1648
  destroy(): Promise<void>;
1618
1649
  }
1619
1650
 
1651
+ /** Names the identity brand carried by lifecycle errors across package copies. */
1652
+ export declare const SERVER_ERROR_BRAND: unique symbol;
1653
+
1654
+ /**
1655
+ * Owns one startup attempt's listening subscription and validated bound port.
1656
+ *
1657
+ * @remarks
1658
+ * Create an instance per bind attempt. Subscribe before calling the native server's
1659
+ * `listen`, retain `pending` for failure cleanup, and record the native address after
1660
+ * listening settles. Reading `port` before a valid address was recorded throws.
1661
+ */
1662
+ export declare class ServerBinding {
1663
+ #private;
1664
+ get pending(): Promise<readonly unknown[]> | undefined;
1665
+ get port(): number;
1666
+ subscribe(server: Server_2, signal: AbortSignal): Promise<readonly unknown[]>;
1667
+ record(address: unknown): void;
1668
+ }
1669
+
1620
1670
  /**
1621
1671
  * Represents the error this package raises when a caller programmed a call the
1622
1672
  * entity refuses, carrying `'STATUS'` or `'NEXT'` as its code.
@@ -2006,62 +2056,6 @@ export declare interface SSEMessage {
2006
2056
  readonly retry?: number;
2007
2057
  }
2008
2058
 
2009
- /**
2010
- * Represents the Server-Sent-Events handle over an open, fetch-standard streaming
2011
- * `Response`. Implements exactly {@link StreamInterface}.
2012
- *
2013
- * @remarks
2014
- * Builds the `Response` at construction from
2015
- * {@link import('./constants.js').SSE_HEADERS} with any `options.headers`
2016
- * merged over them, at `options.status` (default `200`). A caller repeating one
2017
- * of those keys therefore replaces the seam's value, in any casing. The
2018
- * instance owns the stream's
2019
- * controller, its text encoder, the closed flag, and the parked producer's
2020
- * wakeup, so the whole handle is one entity rather than a closure over four
2021
- * bindings.
2022
- *
2023
- * `write` serializes one message ({@link serializeEvent}), enqueues it, and
2024
- * returns whether the controller still has positive desired size. A producer
2025
- * receiving `false` awaits `drain()`; that promise resolves on the next
2026
- * consumer pull restoring capacity, or on stream closure. `comment` writes a
2027
- * `: text` keep-alive line a conforming SSE parser ignores; `end` closes the
2028
- * stream. Every method is a safe no-op once `closed` (ended by `end()`, or
2029
- * the consumer cancelled the stream), so a late write never throws.
2030
- *
2031
- * The readiness signal reflects only the process-local `ReadableStream`
2032
- * queue — it is not proof that a remote peer consumed bytes. When the response
2033
- * pump honors its socket sink's drain state, socket pressure stops body pulls
2034
- * and therefore keeps this queue full, letting a cooperative producer bound
2035
- * its buffering. Ignoring the return value preserves an unconditional-enqueue
2036
- * producer. The default stream strategy counts chunks rather than their byte
2037
- * length, so a byte-bounded producer must also cap each message. Return
2038
- * `response` before awaiting a `false` write, because the consumer cannot pull
2039
- * until it receives the response.
2040
- *
2041
- * @example
2042
- * ```ts
2043
- * import { Stream } from '@src/server'
2044
- *
2045
- * const stream = new Stream()
2046
- * void Promise.resolve().then(async () => {
2047
- * if (!stream.write({ event: 'token', data: 'hello' })) await stream.drain()
2048
- * stream.comment('keep-alive')
2049
- * stream.end()
2050
- * })
2051
- * // return stream.response from the route handler
2052
- * ```
2053
- */
2054
- export declare class Stream implements StreamInterface {
2055
- #private;
2056
- constructor(options?: StreamOptions);
2057
- get response(): Response;
2058
- get closed(): boolean;
2059
- write(message: SSEMessage): boolean;
2060
- comment(text: string): void;
2061
- drain(): Promise<void>;
2062
- end(): void;
2063
- }
2064
-
2065
2059
  /**
2066
2060
  * Represents a handle to write Server-Sent Events to an open, fetch-standard streaming
2067
2061
  * `Response` — the generic streaming surface `createStream` returns over a
@@ -2090,7 +2084,7 @@ export declare class Stream implements StreamInterface {
2090
2084
  * Return `response` before awaiting a `false` write: the consumer cannot pull
2091
2085
  * until it receives the response.
2092
2086
  */
2093
- export declare interface StreamInterface {
2087
+ export declare interface SSEStreamInterface {
2094
2088
  /** Holds the streaming `Response` to return from the route handler. */
2095
2089
  readonly response: Response;
2096
2090
  /** Reports whether the underlying stream is done (ended, or the consumer disconnected). */
@@ -2133,7 +2127,63 @@ export declare interface StreamInterface {
2133
2127
  }
2134
2128
 
2135
2129
  /**
2136
- * Options for a {@link StreamInterface} — how `createStream` opens the
2130
+ * Represents the Server-Sent-Events handle over an open, fetch-standard streaming
2131
+ * `Response`. Implements exactly {@link SSEStreamInterface}.
2132
+ *
2133
+ * @remarks
2134
+ * Builds the `Response` at construction from
2135
+ * {@link import('./constants.js').SSE_HEADERS} with any `options.headers`
2136
+ * merged over them, at `options.status` (default `200`). A caller repeating one
2137
+ * of those keys therefore replaces the seam's value, in any casing. The
2138
+ * instance owns the stream's
2139
+ * controller, its text encoder, the closed flag, and the parked producer's
2140
+ * wakeup, so the whole handle is one entity rather than a closure over four
2141
+ * bindings.
2142
+ *
2143
+ * `write` serializes one message ({@link serializeEvent}), enqueues it, and
2144
+ * returns whether the controller still has positive desired size. A producer
2145
+ * receiving `false` awaits `drain()`; that promise resolves on the next
2146
+ * consumer pull restoring capacity, or on stream closure. `comment` writes a
2147
+ * `: text` keep-alive line a conforming SSE parser ignores; `end` closes the
2148
+ * stream. Every method is a safe no-op once `closed` (ended by `end()`, or
2149
+ * the consumer cancelled the stream), so a late write never throws.
2150
+ *
2151
+ * The readiness signal reflects only the process-local `ReadableStream`
2152
+ * queue — it is not proof that a remote peer consumed bytes. When the response
2153
+ * pump honors its socket sink's drain state, socket pressure stops body pulls
2154
+ * and therefore keeps this queue full, letting a cooperative producer bound
2155
+ * its buffering. Ignoring the return value preserves an unconditional-enqueue
2156
+ * producer. The default stream strategy counts chunks rather than their byte
2157
+ * length, so a byte-bounded producer must also cap each message. Return
2158
+ * `response` before awaiting a `false` write, because the consumer cannot pull
2159
+ * until it receives the response.
2160
+ *
2161
+ * @example
2162
+ * ```ts
2163
+ * import { Stream } from '@src/server'
2164
+ *
2165
+ * const stream = new Stream()
2166
+ * void Promise.resolve().then(async () => {
2167
+ * if (!stream.write({ event: 'token', data: 'hello' })) await stream.drain()
2168
+ * stream.comment('keep-alive')
2169
+ * stream.end()
2170
+ * })
2171
+ * // return stream.response from the route handler
2172
+ * ```
2173
+ */
2174
+ export declare class Stream implements SSEStreamInterface {
2175
+ #private;
2176
+ constructor(options?: StreamOptions);
2177
+ get response(): Response;
2178
+ get closed(): boolean;
2179
+ write(message: SSEMessage): boolean;
2180
+ comment(text: string): void;
2181
+ drain(): Promise<void>;
2182
+ end(): void;
2183
+ }
2184
+
2185
+ /**
2186
+ * Options for an {@link SSEStreamInterface} — how `createStream` opens the
2137
2187
  * streaming response.
2138
2188
  *
2139
2189
  * @param status - The HTTP status the streaming response is opened with;
@@ -5,6 +5,7 @@ import type { EmitterErrorHandler } from '@orkestrel/emitter';
5
5
  import type { EmitterHooks } from '@orkestrel/emitter';
6
6
  import type { EmitterInterface } from '@orkestrel/emitter';
7
7
  import type { IncomingMessage } from 'node:http';
8
+ import type { Server as Server_2 } from 'node:http';
8
9
 
9
10
  /**
10
11
  * Represents one parsed entry of a weighted `Accept` / `Accept-Encoding` /
@@ -275,6 +276,9 @@ export declare interface Connection {
275
276
  */
276
277
  export declare type ConnectionStateFunction<TState> = (connection: Connection) => TState;
277
278
 
279
+ /** Names the identity brand carried by body-limit errors across package copies. */
280
+ export declare const CONTENT_TOO_LARGE_ERROR_BRAND: unique symbol;
281
+
278
282
  /**
279
283
  * Represents the {@link HTTPError} thrown when a request body exceeds the body
280
284
  * pipeline's size limit — a `413 Content Too Large`.
@@ -391,11 +395,11 @@ export declare function createNegotiator(): NegotiatorInterface;
391
395
  export declare function createServer<TState>(options: ServerOptions<TState>): ServerInterface<TState>;
392
396
 
393
397
  /**
394
- * Creates a {@link StreamInterface} — a generic Server-Sent-Events stream whose
398
+ * Creates an {@link SSEStreamInterface} — a generic Server-Sent-Events stream whose
395
399
  * `response` is a fetch-standard streaming `Response` a route returns.
396
400
  *
397
401
  * @param options - {@link StreamOptions}
398
- * @returns A {@link StreamInterface} whose stream is open
402
+ * @returns An {@link SSEStreamInterface} whose stream is open
399
403
  *
400
404
  * @example
401
405
  * ```ts
@@ -410,7 +414,7 @@ export declare function createServer<TState>(options: ServerOptions<TState>): Se
410
414
  * // return stream.response from the route handler
411
415
  * ```
412
416
  */
413
- export declare function createStream(options?: StreamOptions): StreamInterface;
417
+ export declare function createStream(options?: StreamOptions): SSEStreamInterface;
414
418
 
415
419
  /**
416
420
  * Decodes a cookie value with `decodeURIComponent`, falling back to the raw
@@ -621,7 +625,7 @@ export declare const HTTP_ERROR_BRAND: unique symbol;
621
625
  export declare class HTTPError extends Error {
622
626
  readonly status: number;
623
627
  readonly context?: Readonly<Record<string, unknown>>;
624
- readonly [HTTP_ERROR_BRAND] = true;
628
+ readonly [HTTP_ERROR_BRAND]: this;
625
629
  constructor(status: number, message: string, context?: Readonly<Record<string, unknown>>);
626
630
  }
627
631
 
@@ -669,6 +673,16 @@ export declare function isAddressInfo(value: unknown): value is AddressInfo;
669
673
  */
670
674
  export declare function isCompressibleType(type: string): boolean;
671
675
 
676
+ /**
677
+ * Recognizes a branded body-limit error, including subclasses and other package copies.
678
+ *
679
+ * @example
680
+ * ```ts
681
+ * isContentTooLargeError(new ContentTooLargeError(1024)) // true
682
+ * ```
683
+ */
684
+ export declare function isContentTooLargeError(value: unknown): value is ContentTooLargeError;
685
+
672
686
  /**
673
687
  * Checks whether a string is safe to interpolate as a `Set-Cookie` attribute value —
674
688
  * the guard {@link serializeCookie} applies to a `Domain` and a `Path` before it
@@ -731,20 +745,16 @@ export declare function isDangerousKey(key: string): boolean;
731
745
  /**
732
746
  * Narrows an unknown caught value to an {@link HTTPError}, including a subclass such
733
747
  * as {@link ContentTooLargeError}, and recognizes an instance from another copy of
734
- * this package through a structural brand fallback.
748
+ * this package through its own identity brand.
735
749
  *
736
750
  * @param value - The value to test (typically a `catch` binding)
737
751
  * @returns True if `value` is an {@link HTTPError}; false otherwise
738
752
  *
739
753
  * @remarks
740
- * Tries `instanceof` first, then falls back to a total structural check for
741
- * an instance built by a different copy of this package (the dual-package
742
- * hazard — version skew, a linked workspace duplicate) whose `HTTPError`
743
- * constructor is a distinct object from this copy's: the value must carry
744
- * the cross-copy brand (interned by using `Symbol.for`, so every copy resolves the
745
- * same key) and expose the exact fields the server's error boundary reads off
746
- * a recognized `HTTPError` — a numeric `status` and a string `message`. A
747
- * plain object that merely carries a `status` without the brand is rejected.
754
+ * Requires a global Error instance with a derived prototype, its own identity brand,
755
+ * a numeric status, a string message, and an absent or object-valued context.
756
+ * Callable contexts are accepted. Subclass names are unrestricted.
757
+ * Transparent proxies and branded plain objects are rejected.
748
758
  *
749
759
  * @example
750
760
  * ```ts
@@ -767,10 +777,9 @@ export declare function isHTTPError(value: unknown): value is HTTPError;
767
777
  * @returns True if `value` is a {@link ServerError}; false otherwise
768
778
  *
769
779
  * @remarks
770
- * Recognizes an instance built by this copy of the package. A `ServerError`
771
- * is raised by a `Server` to the caller that invoked it directly, so both sides
772
- * hold the same copy and the cross-copy brand {@link isHTTPError} needs has no
773
- * consumer here.
780
+ * Requires the own identity brand, a declared code, a string message, and an absent
781
+ * or object-valued context on a global Error with a derived prototype.
782
+ * Callable contexts and subclasses are accepted; transparent proxies are rejected.
774
783
  *
775
784
  * @example
776
785
  * ```ts
@@ -811,6 +820,28 @@ export declare function isServerError(value: unknown): value is ServerError;
811
820
  */
812
821
  export declare function isValidRequestId(value: string): boolean;
813
822
 
823
+ /**
824
+ * Yields matching media ranges through the first exact rejection.
825
+ *
826
+ * @example
827
+ * ```ts
828
+ * Array.from(iterateMediaMatches([{ value: 'text/plain', q: 1 }], 'text/plain'))
829
+ * // [{ q: 1, rank: 0 }]
830
+ * ```
831
+ */
832
+ export declare function iterateMediaMatches(entries: readonly AcceptEntry[], candidate: string): Generator<MediaMatch, void, unknown>;
833
+
834
+ /**
835
+ * Yields the same lazily collected request-body promise on every read.
836
+ *
837
+ * @example
838
+ * ```ts
839
+ * const bodies = iterateRequestBody(new Request('http://localhost/'), 1024)
840
+ * bodies.next().value === bodies.next().value // true
841
+ * ```
842
+ */
843
+ export declare function iterateRequestBody(request: Request, limit: number): Generator<Promise<unknown>, never, unknown>;
844
+
814
845
  /**
815
846
  * Checks whether a request's `If-None-Match` header matches a resource's current
816
847
  * `ETag` — the RFC 7232 §2.3.2 weak comparison.
@@ -1617,6 +1648,25 @@ export declare class Server<TState> implements ServerInterface<TState> {
1617
1648
  destroy(): Promise<void>;
1618
1649
  }
1619
1650
 
1651
+ /** Names the identity brand carried by lifecycle errors across package copies. */
1652
+ export declare const SERVER_ERROR_BRAND: unique symbol;
1653
+
1654
+ /**
1655
+ * Owns one startup attempt's listening subscription and validated bound port.
1656
+ *
1657
+ * @remarks
1658
+ * Create an instance per bind attempt. Subscribe before calling the native server's
1659
+ * `listen`, retain `pending` for failure cleanup, and record the native address after
1660
+ * listening settles. Reading `port` before a valid address was recorded throws.
1661
+ */
1662
+ export declare class ServerBinding {
1663
+ #private;
1664
+ get pending(): Promise<readonly unknown[]> | undefined;
1665
+ get port(): number;
1666
+ subscribe(server: Server_2, signal: AbortSignal): Promise<readonly unknown[]>;
1667
+ record(address: unknown): void;
1668
+ }
1669
+
1620
1670
  /**
1621
1671
  * Represents the error this package raises when a caller programmed a call the
1622
1672
  * entity refuses, carrying `'STATUS'` or `'NEXT'` as its code.
@@ -2006,62 +2056,6 @@ export declare interface SSEMessage {
2006
2056
  readonly retry?: number;
2007
2057
  }
2008
2058
 
2009
- /**
2010
- * Represents the Server-Sent-Events handle over an open, fetch-standard streaming
2011
- * `Response`. Implements exactly {@link StreamInterface}.
2012
- *
2013
- * @remarks
2014
- * Builds the `Response` at construction from
2015
- * {@link import('./constants.js').SSE_HEADERS} with any `options.headers`
2016
- * merged over them, at `options.status` (default `200`). A caller repeating one
2017
- * of those keys therefore replaces the seam's value, in any casing. The
2018
- * instance owns the stream's
2019
- * controller, its text encoder, the closed flag, and the parked producer's
2020
- * wakeup, so the whole handle is one entity rather than a closure over four
2021
- * bindings.
2022
- *
2023
- * `write` serializes one message ({@link serializeEvent}), enqueues it, and
2024
- * returns whether the controller still has positive desired size. A producer
2025
- * receiving `false` awaits `drain()`; that promise resolves on the next
2026
- * consumer pull restoring capacity, or on stream closure. `comment` writes a
2027
- * `: text` keep-alive line a conforming SSE parser ignores; `end` closes the
2028
- * stream. Every method is a safe no-op once `closed` (ended by `end()`, or
2029
- * the consumer cancelled the stream), so a late write never throws.
2030
- *
2031
- * The readiness signal reflects only the process-local `ReadableStream`
2032
- * queue — it is not proof that a remote peer consumed bytes. When the response
2033
- * pump honors its socket sink's drain state, socket pressure stops body pulls
2034
- * and therefore keeps this queue full, letting a cooperative producer bound
2035
- * its buffering. Ignoring the return value preserves an unconditional-enqueue
2036
- * producer. The default stream strategy counts chunks rather than their byte
2037
- * length, so a byte-bounded producer must also cap each message. Return
2038
- * `response` before awaiting a `false` write, because the consumer cannot pull
2039
- * until it receives the response.
2040
- *
2041
- * @example
2042
- * ```ts
2043
- * import { Stream } from '@src/server'
2044
- *
2045
- * const stream = new Stream()
2046
- * void Promise.resolve().then(async () => {
2047
- * if (!stream.write({ event: 'token', data: 'hello' })) await stream.drain()
2048
- * stream.comment('keep-alive')
2049
- * stream.end()
2050
- * })
2051
- * // return stream.response from the route handler
2052
- * ```
2053
- */
2054
- export declare class Stream implements StreamInterface {
2055
- #private;
2056
- constructor(options?: StreamOptions);
2057
- get response(): Response;
2058
- get closed(): boolean;
2059
- write(message: SSEMessage): boolean;
2060
- comment(text: string): void;
2061
- drain(): Promise<void>;
2062
- end(): void;
2063
- }
2064
-
2065
2059
  /**
2066
2060
  * Represents a handle to write Server-Sent Events to an open, fetch-standard streaming
2067
2061
  * `Response` — the generic streaming surface `createStream` returns over a
@@ -2090,7 +2084,7 @@ export declare class Stream implements StreamInterface {
2090
2084
  * Return `response` before awaiting a `false` write: the consumer cannot pull
2091
2085
  * until it receives the response.
2092
2086
  */
2093
- export declare interface StreamInterface {
2087
+ export declare interface SSEStreamInterface {
2094
2088
  /** Holds the streaming `Response` to return from the route handler. */
2095
2089
  readonly response: Response;
2096
2090
  /** Reports whether the underlying stream is done (ended, or the consumer disconnected). */
@@ -2133,7 +2127,63 @@ export declare interface StreamInterface {
2133
2127
  }
2134
2128
 
2135
2129
  /**
2136
- * Options for a {@link StreamInterface} — how `createStream` opens the
2130
+ * Represents the Server-Sent-Events handle over an open, fetch-standard streaming
2131
+ * `Response`. Implements exactly {@link SSEStreamInterface}.
2132
+ *
2133
+ * @remarks
2134
+ * Builds the `Response` at construction from
2135
+ * {@link import('./constants.js').SSE_HEADERS} with any `options.headers`
2136
+ * merged over them, at `options.status` (default `200`). A caller repeating one
2137
+ * of those keys therefore replaces the seam's value, in any casing. The
2138
+ * instance owns the stream's
2139
+ * controller, its text encoder, the closed flag, and the parked producer's
2140
+ * wakeup, so the whole handle is one entity rather than a closure over four
2141
+ * bindings.
2142
+ *
2143
+ * `write` serializes one message ({@link serializeEvent}), enqueues it, and
2144
+ * returns whether the controller still has positive desired size. A producer
2145
+ * receiving `false` awaits `drain()`; that promise resolves on the next
2146
+ * consumer pull restoring capacity, or on stream closure. `comment` writes a
2147
+ * `: text` keep-alive line a conforming SSE parser ignores; `end` closes the
2148
+ * stream. Every method is a safe no-op once `closed` (ended by `end()`, or
2149
+ * the consumer cancelled the stream), so a late write never throws.
2150
+ *
2151
+ * The readiness signal reflects only the process-local `ReadableStream`
2152
+ * queue — it is not proof that a remote peer consumed bytes. When the response
2153
+ * pump honors its socket sink's drain state, socket pressure stops body pulls
2154
+ * and therefore keeps this queue full, letting a cooperative producer bound
2155
+ * its buffering. Ignoring the return value preserves an unconditional-enqueue
2156
+ * producer. The default stream strategy counts chunks rather than their byte
2157
+ * length, so a byte-bounded producer must also cap each message. Return
2158
+ * `response` before awaiting a `false` write, because the consumer cannot pull
2159
+ * until it receives the response.
2160
+ *
2161
+ * @example
2162
+ * ```ts
2163
+ * import { Stream } from '@src/server'
2164
+ *
2165
+ * const stream = new Stream()
2166
+ * void Promise.resolve().then(async () => {
2167
+ * if (!stream.write({ event: 'token', data: 'hello' })) await stream.drain()
2168
+ * stream.comment('keep-alive')
2169
+ * stream.end()
2170
+ * })
2171
+ * // return stream.response from the route handler
2172
+ * ```
2173
+ */
2174
+ export declare class Stream implements SSEStreamInterface {
2175
+ #private;
2176
+ constructor(options?: StreamOptions);
2177
+ get response(): Response;
2178
+ get closed(): boolean;
2179
+ write(message: SSEMessage): boolean;
2180
+ comment(text: string): void;
2181
+ drain(): Promise<void>;
2182
+ end(): void;
2183
+ }
2184
+
2185
+ /**
2186
+ * Options for an {@link SSEStreamInterface} — how `createStream` opens the
2137
2187
  * streaming response.
2138
2188
  *
2139
2189
  * @param status - The HTTP status the streaming response is opened with;