@orkestrel/server 0.0.22 → 0.0.24

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`.
@@ -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.
@@ -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`.
@@ -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.