@orkestrel/server 0.0.1 → 0.0.2

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.
@@ -1,163 +1,307 @@
1
- import type { IncomingMessage } from 'node:http';
2
- import type { Duplex } from 'node:stream';
3
- import type { ConnectionInfo, MiddlewareHandler } from '@src/core';
4
- import type { DispatcherInterface } from '@orkestrel/router';
5
- import type { EmitterErrorHandler, EmitterHooks, EmitterInterface } from '@orkestrel/emitter';
6
- /**
7
- * The `Server`'s lifecycle state (AGENTS §10 vocabulary).
8
- *
9
- * @remarks
10
- * `idle` (never started, or a fresh instance) → `starting` (binding the
11
- * listener) → `listening` (accepting requests) → `stopping` (draining
12
- * in-flight requests) → `stopped` (closed; `start()` may run again, minting a
13
- * fresh stop signal). `destroy()` is a terminal teardown reachable from any
14
- * state, idempotent once `stopped`.
15
- */
16
- export type ServerStatus = 'idle' | 'starting' | 'listening' | 'stopping' | 'stopped';
17
- /**
18
- * The `Server`'s observable lifecycle events (AGENTS §13).
19
- *
20
- * @remarks
21
- * - `start` — `listen()` resolved; carries the actually-bound port (an
22
- * ephemeral `0` resolves to the OS-assigned one).
23
- * - `request` — fired once per incoming request, before the middleware onion
24
- * runs, carrying the raw method + the parsed pathname.
25
- * - `upgrade` — a raw protocol-upgrade fan-out settled; carries the original
26
- * `IncomingMessage` and whether a registered {@link UpgradeHandler} claimed it.
27
- * - `error` — a server-level fault: an escaping throw past the built-in
28
- * boundary, an upgrade handler's throw, or a listen failure.
29
- * - `stop` — `stop()` began (status just moved to `'stopping'`).
30
- * - `drain` — the graceful drain settled (deadline hit or all finished);
31
- * carries the still-pending request count (`0` on a clean drain).
32
- */
33
- export type ServerEventMap = {
34
- readonly start: readonly [port: number];
35
- readonly request: readonly [method: string, pathname: string];
36
- readonly upgrade: readonly [request: IncomingMessage, handled: boolean];
37
- readonly error: readonly [error: unknown];
38
- readonly stop: readonly [];
39
- readonly drain: readonly [pending: number];
40
- };
41
- /**
42
- * A raw `node:http` protocol-upgrade claimant — registered via
43
- * {@link ServerInterface.upgrade}.
44
- *
45
- * @remarks
46
- * Fan-out semantics (verbatim, PROPOSAL §4): handlers run in registration
47
- * order, the FIRST to return `true` CLAIMS (owns) the socket and stops the
48
- * fan-out; a handler that THROWS is treated as declined (the throw surfaces
49
- * on the `error` event) and the fan-out continues; if NONE claim it, the
50
- * socket is destroyed so an unhandled upgrade never leaks a dangling
51
- * connection. `request` / `socket` / `head` are node's own raw values, handed
52
- * over verbatim — no assertion at this boundary (AGENTS §14).
53
- *
54
- * @param request - The raw `node:http` upgrade request
55
- * @param socket - The raw, now-detached `Duplex` connection
56
- * @param head - The first packet of the upgraded stream, if any
57
- * @returns `true` to CLAIM the socket (this handler now owns it), `false` to
58
- * decline and let a later handler try
59
- */
60
- export type UpgradeHandler = (request: IncomingMessage, socket: Duplex, head: Buffer) => boolean;
61
- /**
62
- * Derives a consumer's per-request `TState` from the adapter-injected
63
- * {@link ConnectionInfo} — `ServerOptions.state`, invoked once per request
64
- * before the middleware onion runs.
65
- *
66
- * @typeParam TState - The consumer's opaque per-request state type
67
- */
68
- export type ConnectionStateFunction<TState> = (connection: ConnectionInfo) => TState;
69
- /**
70
- * Options for `createServer`.
71
- *
72
- * @param dispatcher - The `@orkestrel/router` {@link DispatcherInterface} the
73
- * composed middleware onion terminates into — bring-your-own router (the
74
- * composition seam stays explicit and independently testable).
75
- * @param state - {@link ConnectionStateFunction} — builds each request's
76
- * `TState` from the connection facts (peer IP, TLS flag). `X-Forwarded-For`
77
- * is never implicitly trusted here; a deployment behind a trusted proxy
78
- * derives its own client key in this function or in middleware.
79
- * @param middleware - Initial middleware, run in array order (outer-first);
80
- * more may be added later via `use`.
81
- * @param host - The network interface `start()` binds to (`node:http`
82
- * `server.listen`'s host). Omitted ⇒ node's default (all interfaces).
83
- * @param port - The TCP port `start()` binds to. Omitted or `0` ⇒ an
84
- * EPHEMERAL, OS-assigned free port (the default); `start()` always resolves
85
- * the actually-bound port. A port already in use rejects `start()` with
86
- * `EADDRINUSE` — no silent ephemeral fallback (use `discoverPort` to pick a
87
- * guaranteed-free port up front).
88
- * @param drain - The graceful-stop deadline in milliseconds: on `stop()` the
89
- * server stops accepting new connections and gives in-flight requests this
90
- * long to finish before forcing sockets closed. Defaults to
91
- * `DEFAULT_DRAIN_MS`. Must be a non-negative finite number.
92
- * @param limit - The default request-body byte cap the context's `body()`
93
- * reads through. Defaults to `DEFAULT_BODY_LIMIT`. Must be a non-negative
94
- * finite number.
95
- * @param expose - Whether a non-`HTTPError` throw's message is sent in the
96
- * 500 response body (an `HTTPError`'s own message is always client-facing).
97
- * Defaults to `false`.
98
- * @param report - A fire-and-forget sink the built-in boundary hands every
99
- * caught error to (logging / metrics); its own throw is swallowed so
100
- * reporting can never crash the response.
101
- * @param timeouts - `node:http` tuning knobs: `request` (max time to fully
102
- * receive + respond, `requestTimeout`), `headers` (max time to receive the
103
- * request headers, `headersTimeout`), `keepalive` (idle keep-alive socket
104
- * timeout, `keepAliveTimeout`). `headers` must not exceed `keepalive` (the
105
- * Slowloris footgun) — construction throws a `TypeError` otherwise.
106
- * @param on - The reserved {@link EmitterHooks} for {@link ServerEventMap}
107
- * (AGENTS §8), wiring initial lifecycle listeners at construction.
108
- * @param error - The emitter's listener-error handler (AGENTS §13) — a
109
- * listener throw routes here, never to the domain `error` event.
110
- */
111
- export interface ServerOptions<TState> {
112
- readonly dispatcher: DispatcherInterface<TState>;
113
- readonly state: ConnectionStateFunction<TState>;
114
- readonly middleware?: readonly MiddlewareHandler<TState>[];
115
- readonly host?: string;
116
- readonly port?: number;
117
- readonly drain?: number;
118
- readonly limit?: number;
119
- readonly expose?: boolean;
120
- readonly report?: (error: unknown) => void;
121
- readonly timeouts?: {
122
- readonly request?: number;
123
- readonly headers?: number;
124
- readonly keepalive?: number;
125
- };
126
- readonly on?: EmitterHooks<ServerEventMap>;
127
- readonly error?: EmitterErrorHandler;
128
- }
129
- /**
130
- * The HTTP server facade — an observable `node:http` lifecycle that composes
131
- * a middleware onion (the `@src/core` seam) around a consumed
132
- * `@orkestrel/router` {@link DispatcherInterface}.
133
- *
134
- * @typeParam TState - The consumer's opaque per-request state type
135
- *
136
- * @remarks
137
- * `use` adds middleware and `upgrade` registers a protocol-upgrade claimant,
138
- * both configurable before or after `start()`. `start()` binds the configured
139
- * `host`/`port` (an omitted/`0` port ⇒ an EPHEMERAL port, resolved from the
140
- * bound address) and resolves the actually-bound port. `stop()` refuses new
141
- * connections, fires the stop signal so in-flight handlers can observe it,
142
- * drains up to the configured deadline, then closes. `destroy()` is the final
143
- * idempotent teardown. Per request: a `Request` is built via the router's
144
- * `buildRequest` (its signal linked to the server's stop signal), the
145
- * composed middleware onion runs terminating in `dispatcher.handle`, and the
146
- * result is written back via `sendResponse` — every escaping throw is caught
147
- * by the built-in boundary (`HTTPError` → its status; anything else → a
148
- * hidden-unless-`expose` `500`) so a handler error can never crash the
149
- * process.
150
- */
151
- export interface ServerInterface<TState> {
152
- readonly id: string;
153
- readonly status: ServerStatus;
154
- readonly port: number | undefined;
155
- readonly dispatcher: DispatcherInterface<TState>;
156
- readonly emitter: EmitterInterface<ServerEventMap>;
157
- use(middleware: MiddlewareHandler<TState>): void;
158
- use(middleware: readonly MiddlewareHandler<TState>[]): void;
159
- upgrade(handler: UpgradeHandler): void;
160
- start(): Promise<number>;
161
- stop(): Promise<void>;
162
- destroy(): Promise<void>;
163
- }
1
+ import { AddressInfo } from 'node:net';
2
+ import { ConnectionInfo } from '../core/index.ts';
3
+ import { DispatcherInterface } from '@orkestrel/router';
4
+ import { Duplex } from 'node:stream';
5
+ import { EmitterErrorHandler } from '@orkestrel/emitter';
6
+ import { EmitterHooks } from '@orkestrel/emitter';
7
+ import { EmitterInterface } from '@orkestrel/emitter';
8
+ import { IncomingMessage } from 'node:http';
9
+ import { MiddlewareHandler } from '../core/index.ts';
10
+
11
+ /**
12
+ * Derives a consumer's per-request `TState` from the adapter-injected
13
+ * {@link ConnectionInfo} — `ServerOptions.state`, invoked once per request
14
+ * before the middleware onion runs.
15
+ *
16
+ * @typeParam TState - The consumer's opaque per-request state type
17
+ */
18
+ export declare type ConnectionStateFunction<TState> = (connection: ConnectionInfo) => TState;
19
+
20
+ /**
21
+ * Create a {@link ServerInterface} — the node face's HTTP server facade over
22
+ * a consumed `@orkestrel/router` dispatcher.
23
+ *
24
+ * @typeParam TState - The consumer's opaque per-request state type
25
+ * @param options - {@link ServerOptions}
26
+ * @returns A {@link ServerInterface}, not yet started
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * import { createServer } from '@src/server'
31
+ * import { createDispatcher } from '@orkestrel/router'
32
+ *
33
+ * const dispatcher = createDispatcher<{ readonly ip?: string }>()
34
+ * dispatcher.add({ method: 'GET', path: '/health', handler: () => new Response('ok') })
35
+ *
36
+ * const server = createServer({
37
+ * dispatcher,
38
+ * state: (connection) => ({ ip: connection.ip }),
39
+ * })
40
+ * const port = await server.start()
41
+ * await server.stop()
42
+ * ```
43
+ */
44
+ export declare function createServer<TState>(options: ServerOptions<TState>): ServerInterface<TState>;
45
+
46
+ /**
47
+ * Find a FREE TCP port — bind a throwaway `node:net` server, read the
48
+ * OS-assigned port, close it, and resolve that port.
49
+ *
50
+ * @remarks
51
+ * With no `preferred` it binds port `0` (an ephemeral OS-assigned free port)
52
+ * and returns it. With a `preferred` port it tries THAT port first and
53
+ * returns it when free; if already in use (`EADDRINUSE`) it FALLS BACK to an
54
+ * ephemeral free port rather than rejecting — a caller always gets a usable
55
+ * port. It binds then immediately closes a probe server, so the returned
56
+ * port is free at the instant of the probe (an inherent TOCTOU race — bind it
57
+ * promptly). Rejects only on an unexpected listen error other than a taken
58
+ * `preferred` port (e.g. a permission fault).
59
+ *
60
+ * @param preferred - An optional port to try first; taken (`EADDRINUSE`) ⇒
61
+ * fall back to an ephemeral port
62
+ * @returns A free TCP port number
63
+ *
64
+ * @example
65
+ * ```ts
66
+ * import { createServer, discoverPort } from '@src/server'
67
+ *
68
+ * const port = await discoverPort() // a guaranteed-free ephemeral port
69
+ * ```
70
+ */
71
+ export declare function discoverPort(preferred?: number): Promise<number>;
72
+
73
+ /**
74
+ * Whether a `node:net` `server.address()` return is the structured
75
+ * {@link AddressInfo} (carrying a numeric `port`) rather than a pipe `string`
76
+ * or `null` — the total, never-throwing narrow (AGENTS §14) `discoverPort`
77
+ * and the `Server`'s own port resolution read the bound port through.
78
+ *
79
+ * @param value - The `server.address()` return (`AddressInfo | string | null`)
80
+ * @returns `true` when `value` is an `AddressInfo` with a numeric `port`
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * import { isAddressInfo } from '@src/server'
85
+ *
86
+ * isAddressInfo({ address: '127.0.0.1', family: 'IPv4', port: 4000 }) // true
87
+ * isAddressInfo(null) // false
88
+ * ```
89
+ */
90
+ export declare function isAddressInfo(value: unknown): value is AddressInfo;
91
+
92
+ /**
93
+ * The HTTP server facade — an observable `node:http` lifecycle composing the
94
+ * `@src/core` middleware onion around a consumed `@orkestrel/router`
95
+ * dispatcher.
96
+ *
97
+ * @typeParam TState - The consumer's opaque per-request state type
98
+ *
99
+ * @remarks
100
+ * - **Lifecycle (AGENTS §10).** `start()` builds the underlying `node:http`
101
+ * server, binds the configured {@link ServerOptions.host} / {@link
102
+ * ServerOptions.port} (omitted/`0` port ⇒ EPHEMERAL, resolved from the
103
+ * bound address), and transitions `idle → starting → listening`. `stop()`
104
+ * transitions to `stopping`: refuses new connections, fires a fresh-per-run
105
+ * stop signal so in-flight handlers observe cancellation, drains up to the
106
+ * `drain` deadline (event-driven, no busy-loop), then closes → `stopped`.
107
+ * `destroy()` is the idempotent final teardown.
108
+ * - **Per request.** In-flight is tracked (finished on response `finish` or
109
+ * `close`); a `Request` is built via the router's `buildRequest`, its
110
+ * `signal` LINKED to this run's stop signal via `@orkestrel/abort`'s
111
+ * `linkSignal` (a fresh `Request` is constructed with the linked signal —
112
+ * `buildRequest`'s own abort, tied to client disconnect, composes with the
113
+ * server's stop signal via `AbortSignal.any`, so a handler awaiting
114
+ * `request.signal` observes BOTH); `context.state` is built via
115
+ * {@link ServerOptions.state} from the connection facts; the composed
116
+ * middleware onion runs, terminating in `dispatcher.handle`; the result is
117
+ * written back via `sendResponse`.
118
+ * - **The built-in boundary** wraps the WHOLE per-request chain, including
119
+ * setup: `buildRequest` runs behind its own inner boundary that maps a
120
+ * throw (e.g. a malformed `Host` header) to a silent `400` with no
121
+ * `error` emit; everything after (`Request` reconstruction, connection
122
+ * facts, `state`, the composed onion, and `dispatcher.handle`) runs
123
+ * behind the outer boundary — a thrown `HTTPError` renders as its status +
124
+ * message; any other throw renders `500` (message hidden unless
125
+ * `expose`), `report` is invoked (its own throw swallowed), and `error` is
126
+ * emitted. A server-owned last resort wraps the final `sendResponse`
127
+ * write itself: if even that fails, the connection is destroyed rather
128
+ * than left to escape as an unhandled error.
129
+ * - **Upgrade fan-out** — verbatim old semantics (first-claimer-wins, a
130
+ * throwing handler is treated as declined and surfaced on `error`, an
131
+ * unclaimed upgrade destroys the socket), bound per-run to this instance.
132
+ * - **Observable (§13).** Owns an {@link Emitter} over {@link ServerEventMap}
133
+ * exposed as `readonly emitter`; the emitter isolates a listener throw and
134
+ * routes it to the `error` OPTION (not the domain `error` event).
135
+ */
136
+ export declare class Server<TState> implements ServerInterface<TState> {
137
+ #private;
138
+ readonly id: `${string}-${string}-${string}-${string}-${string}`;
139
+ constructor(options: ServerOptions<TState>);
140
+ get status(): ServerStatus;
141
+ get port(): number | undefined;
142
+ get dispatcher(): DispatcherInterface<TState>;
143
+ get emitter(): EmitterInterface<ServerEventMap>;
144
+ use(middleware: MiddlewareHandler<TState>): void;
145
+ use(middleware: readonly MiddlewareHandler<TState>[]): void;
146
+ upgrade(handler: UpgradeHandler): void;
147
+ start(): Promise<number>;
148
+ stop(): Promise<void>;
149
+ destroy(): Promise<void>;
150
+ }
151
+
152
+ /**
153
+ * The `Server`'s observable lifecycle events (AGENTS §13).
154
+ *
155
+ * @remarks
156
+ * - `start` — `listen()` resolved; carries the actually-bound port (an
157
+ * ephemeral `0` resolves to the OS-assigned one).
158
+ * - `request` — fired once per incoming request, before the middleware onion
159
+ * runs, carrying the raw method + the parsed pathname.
160
+ * - `upgrade` — a raw protocol-upgrade fan-out settled; carries the original
161
+ * `IncomingMessage` and whether a registered {@link UpgradeHandler} claimed it.
162
+ * - `error` — a server-level fault: an escaping throw past the built-in
163
+ * boundary, an upgrade handler's throw, or a listen failure.
164
+ * - `stop` — `stop()` began (status just moved to `'stopping'`).
165
+ * - `drain` — the graceful drain settled (deadline hit or all finished);
166
+ * carries the still-pending request count (`0` on a clean drain).
167
+ */
168
+ export declare type ServerEventMap = {
169
+ readonly start: readonly [port: number];
170
+ readonly request: readonly [method: string, pathname: string];
171
+ readonly upgrade: readonly [request: IncomingMessage, handled: boolean];
172
+ readonly error: readonly [error: unknown];
173
+ readonly stop: readonly [];
174
+ readonly drain: readonly [pending: number];
175
+ };
176
+
177
+ /**
178
+ * The HTTP server facade — an observable `node:http` lifecycle that composes
179
+ * a middleware onion (the `@src/core` seam) around a consumed
180
+ * `@orkestrel/router` {@link DispatcherInterface}.
181
+ *
182
+ * @typeParam TState - The consumer's opaque per-request state type
183
+ *
184
+ * @remarks
185
+ * `use` adds middleware and `upgrade` registers a protocol-upgrade claimant,
186
+ * both configurable before or after `start()`. `start()` binds the configured
187
+ * `host`/`port` (an omitted/`0` port ⇒ an EPHEMERAL port, resolved from the
188
+ * bound address) and resolves the actually-bound port. `stop()` refuses new
189
+ * connections, fires the stop signal so in-flight handlers can observe it,
190
+ * drains up to the configured deadline, then closes. `destroy()` is the final
191
+ * idempotent teardown. Per request: a `Request` is built via the router's
192
+ * `buildRequest` (its signal linked to the server's stop signal), the
193
+ * composed middleware onion runs terminating in `dispatcher.handle`, and the
194
+ * result is written back via `sendResponse` — every escaping throw is caught
195
+ * by the built-in boundary (`HTTPError` → its status; anything else → a
196
+ * hidden-unless-`expose` `500`) so a handler error can never crash the
197
+ * process.
198
+ */
199
+ export declare interface ServerInterface<TState> {
200
+ readonly id: string;
201
+ readonly status: ServerStatus;
202
+ readonly port: number | undefined;
203
+ readonly dispatcher: DispatcherInterface<TState>;
204
+ readonly emitter: EmitterInterface<ServerEventMap>;
205
+ use(middleware: MiddlewareHandler<TState>): void;
206
+ use(middleware: readonly MiddlewareHandler<TState>[]): void;
207
+ upgrade(handler: UpgradeHandler): void;
208
+ start(): Promise<number>;
209
+ stop(): Promise<void>;
210
+ destroy(): Promise<void>;
211
+ }
212
+
213
+ /**
214
+ * Options for `createServer`.
215
+ *
216
+ * @param dispatcher - The `@orkestrel/router` {@link DispatcherInterface} the
217
+ * composed middleware onion terminates into — bring-your-own router (the
218
+ * composition seam stays explicit and independently testable).
219
+ * @param state - {@link ConnectionStateFunction} — builds each request's
220
+ * `TState` from the connection facts (peer IP, TLS flag). `X-Forwarded-For`
221
+ * is never implicitly trusted here; a deployment behind a trusted proxy
222
+ * derives its own client key in this function or in middleware.
223
+ * @param middleware - Initial middleware, run in array order (outer-first);
224
+ * more may be added later via `use`.
225
+ * @param host - The network interface `start()` binds to (`node:http`
226
+ * `server.listen`'s host). Omitted ⇒ node's default (all interfaces).
227
+ * @param port - The TCP port `start()` binds to. Omitted or `0` ⇒ an
228
+ * EPHEMERAL, OS-assigned free port (the default); `start()` always resolves
229
+ * the actually-bound port. A port already in use rejects `start()` with
230
+ * `EADDRINUSE` — no silent ephemeral fallback (use `discoverPort` to pick a
231
+ * guaranteed-free port up front).
232
+ * @param drain - The graceful-stop deadline in milliseconds: on `stop()` the
233
+ * server stops accepting new connections and gives in-flight requests this
234
+ * long to finish before forcing sockets closed. Defaults to
235
+ * `DEFAULT_DRAIN_MS`. Must be a non-negative finite number.
236
+ * @param limit - The default request-body byte cap the context's `body()`
237
+ * reads through. Defaults to `DEFAULT_BODY_LIMIT`. Must be a non-negative
238
+ * finite number.
239
+ * @param expose - Whether a non-`HTTPError` throw's message is sent in the
240
+ * 500 response body (an `HTTPError`'s own message is always client-facing).
241
+ * Defaults to `false`.
242
+ * @param report - A fire-and-forget sink the built-in boundary hands every
243
+ * caught error to (logging / metrics); its own throw is swallowed so
244
+ * reporting can never crash the response.
245
+ * @param timeouts - `node:http` tuning knobs: `request` (max time to fully
246
+ * receive + respond, `requestTimeout`), `headers` (max time to receive the
247
+ * request headers, `headersTimeout`), `keepalive` (idle keep-alive socket
248
+ * timeout, `keepAliveTimeout`). `headers` must not exceed `keepalive` (the
249
+ * Slowloris footgun) — construction throws a `TypeError` otherwise.
250
+ * @param on - The reserved {@link EmitterHooks} for {@link ServerEventMap}
251
+ * (AGENTS §8), wiring initial lifecycle listeners at construction.
252
+ * @param error - The emitter's listener-error handler (AGENTS §13) — a
253
+ * listener throw routes here, never to the domain `error` event.
254
+ */
255
+ export declare interface ServerOptions<TState> {
256
+ readonly dispatcher: DispatcherInterface<TState>;
257
+ readonly state: ConnectionStateFunction<TState>;
258
+ readonly middleware?: readonly MiddlewareHandler<TState>[];
259
+ readonly host?: string;
260
+ readonly port?: number;
261
+ readonly drain?: number;
262
+ readonly limit?: number;
263
+ readonly expose?: boolean;
264
+ readonly report?: (error: unknown) => void;
265
+ readonly timeouts?: {
266
+ readonly request?: number;
267
+ readonly headers?: number;
268
+ readonly keepalive?: number;
269
+ };
270
+ readonly on?: EmitterHooks<ServerEventMap>;
271
+ readonly error?: EmitterErrorHandler;
272
+ }
273
+
274
+ /**
275
+ * The `Server`'s lifecycle state (AGENTS §10 vocabulary).
276
+ *
277
+ * @remarks
278
+ * `idle` (never started, or a fresh instance) → `starting` (binding the
279
+ * listener) → `listening` (accepting requests) → `stopping` (draining
280
+ * in-flight requests) → `stopped` (closed; `start()` may run again, minting a
281
+ * fresh stop signal). `destroy()` is a terminal teardown reachable from any
282
+ * state, idempotent once `stopped`.
283
+ */
284
+ export declare type ServerStatus = 'idle' | 'starting' | 'listening' | 'stopping' | 'stopped';
285
+
286
+ /**
287
+ * A raw `node:http` protocol-upgrade claimant — registered via
288
+ * {@link ServerInterface.upgrade}.
289
+ *
290
+ * @remarks
291
+ * Fan-out semantics (verbatim, PROPOSAL §4): handlers run in registration
292
+ * order, the FIRST to return `true` CLAIMS (owns) the socket and stops the
293
+ * fan-out; a handler that THROWS is treated as declined (the throw surfaces
294
+ * on the `error` event) and the fan-out continues; if NONE claim it, the
295
+ * socket is destroyed so an unhandled upgrade never leaks a dangling
296
+ * connection. `request` / `socket` / `head` are node's own raw values, handed
297
+ * over verbatim — no assertion at this boundary (AGENTS §14).
298
+ *
299
+ * @param request - The raw `node:http` upgrade request
300
+ * @param socket - The raw, now-detached `Duplex` connection
301
+ * @param head - The first packet of the upgraded stream, if any
302
+ * @returns `true` to CLAIM the socket (this handler now owns it), `false` to
303
+ * decline and let a later handler try
304
+ */
305
+ export declare type UpgradeHandler = (request: IncomingMessage, socket: Duplex, head: Buffer) => boolean;
306
+
307
+ export { }