@exhumer/signalr-client 1.0.2 → 2.0.0
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.
- package/README.md +64 -10
- package/dist/index.cjs +2875 -2679
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +598 -771
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +913 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +2901 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +17 -14
- package/dist/index.d.ts +0 -1086
- package/dist/index.js +0 -2715
- package/dist/index.js.map +0 -1
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,913 @@
|
|
|
1
|
+
import { Readable } from "node:stream";
|
|
2
|
+
import { Dispatcher, Dispatcher as Dispatcher$1 } from "undici";
|
|
3
|
+
import { CookieAgent, cookie } from "@exhumer/undici-cookie-agent";
|
|
4
|
+
import { CookieJar, CookieJar as CookieJar$1 } from "tough-cookie";
|
|
5
|
+
import { EventEmitter } from "node:events";
|
|
6
|
+
|
|
7
|
+
//#region src/constants.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* constants.ts
|
|
10
|
+
*
|
|
11
|
+
* All SignalR protocol constants, enumerations, and timing defaults.
|
|
12
|
+
* Uses `as const satisfies` (TS 4.9+) so values carry their narrow literal
|
|
13
|
+
* types while being verified against a constraint at compile time.
|
|
14
|
+
*/
|
|
15
|
+
declare const MessageType: Readonly<{
|
|
16
|
+
readonly Invocation: 1;
|
|
17
|
+
readonly StreamItem: 2;
|
|
18
|
+
readonly Completion: 3;
|
|
19
|
+
readonly StreamInvocation: 4;
|
|
20
|
+
readonly CancelInvocation: 5;
|
|
21
|
+
readonly Ping: 6;
|
|
22
|
+
readonly Close: 7;
|
|
23
|
+
}>;
|
|
24
|
+
/** Union of all valid message type numbers. */
|
|
25
|
+
type MessageTypeValue = (typeof MessageType)[keyof typeof MessageType];
|
|
26
|
+
declare const HubConnectionState: Readonly<{
|
|
27
|
+
readonly Disconnected: "Disconnected";
|
|
28
|
+
readonly Connecting: "Connecting";
|
|
29
|
+
readonly Connected: "Connected";
|
|
30
|
+
readonly Disconnecting: "Disconnecting";
|
|
31
|
+
readonly Reconnecting: "Reconnecting";
|
|
32
|
+
}>;
|
|
33
|
+
/** Union of all valid connection state strings. */
|
|
34
|
+
type HubConnectionState = (typeof HubConnectionState)[keyof typeof HubConnectionState];
|
|
35
|
+
declare const LogLevel: {
|
|
36
|
+
readonly Trace: 0;
|
|
37
|
+
readonly Debug: 1;
|
|
38
|
+
readonly Information: 2;
|
|
39
|
+
readonly Warning: 3;
|
|
40
|
+
readonly Error: 4;
|
|
41
|
+
readonly Critical: 5;
|
|
42
|
+
readonly None: 6;
|
|
43
|
+
};
|
|
44
|
+
type LogLevel = (typeof LogLevel)[keyof typeof LogLevel];
|
|
45
|
+
declare const HttpTransportType: {
|
|
46
|
+
readonly None: 0;
|
|
47
|
+
readonly WebSockets: 1;
|
|
48
|
+
readonly ServerSentEvents: 2;
|
|
49
|
+
readonly LongPolling: 4;
|
|
50
|
+
};
|
|
51
|
+
/** Bitmask of enabled transports - values can be OR-ed together. */
|
|
52
|
+
type HttpTransportType = (typeof HttpTransportType)[keyof typeof HttpTransportType];
|
|
53
|
+
declare const TransferFormat: {
|
|
54
|
+
readonly Text: 1;
|
|
55
|
+
readonly Binary: 2;
|
|
56
|
+
};
|
|
57
|
+
type TransferFormat = (typeof TransferFormat)[keyof typeof TransferFormat];
|
|
58
|
+
/** ASCII 30 - the byte that terminates every SignalR JSON message. */
|
|
59
|
+
declare const RECORD_SEPARATOR: "\u001E";
|
|
60
|
+
/** Negotiate version we advertise to the server. */
|
|
61
|
+
declare const NEGOTIATE_VERSION: 1;
|
|
62
|
+
declare const DEFAULT_TIMEOUT_IN_MS: 30000;
|
|
63
|
+
declare const DEFAULT_PING_INTERVAL_IN_MS: 15000;
|
|
64
|
+
declare const DEFAULT_SERVER_TIMEOUT_IN_MS: 30000;
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/http-client.d.ts
|
|
67
|
+
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
|
|
68
|
+
/**
|
|
69
|
+
* Per-request options accepted by every client method.
|
|
70
|
+
* These mirror the previous `node:http`-based API surface exactly so callers
|
|
71
|
+
* do not need to be changed when switching client implementations.
|
|
72
|
+
*/
|
|
73
|
+
interface RequestOptions {
|
|
74
|
+
/** Per-request headers merged on top of the instance-level defaults. */
|
|
75
|
+
readonly headers?: Record<string, string>;
|
|
76
|
+
/**
|
|
77
|
+
* Request body.
|
|
78
|
+
* Plain objects are serialised to JSON automatically.
|
|
79
|
+
* Strings are sent as-is (set Content-Type explicitly if needed).
|
|
80
|
+
*/
|
|
81
|
+
readonly body?: string | Uint8Array | Record<string, unknown> | null;
|
|
82
|
+
/** Override the session-level timeout for this single request (ms). */
|
|
83
|
+
readonly timeout?: number;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Session-level options shared by all client constructors.
|
|
87
|
+
*/
|
|
88
|
+
interface HttpClientOptions {
|
|
89
|
+
/** Headers sent with every request (merged before per-request headers). */
|
|
90
|
+
readonly headers?: Record<string, string>;
|
|
91
|
+
/** Default timeout in milliseconds applied to every request (default: 30 000). */
|
|
92
|
+
readonly timeout?: number;
|
|
93
|
+
/**
|
|
94
|
+
* undici Dispatcher to use for the entire session.
|
|
95
|
+
*
|
|
96
|
+
* You can pass any `Dispatcher` subclass:
|
|
97
|
+
* - `new undici.Agent(opts)` - connection-pool tuning
|
|
98
|
+
* - `new undici.Pool(origin, opts)` - per-origin pool
|
|
99
|
+
* - `new undici.Client(origin, opts)` - single connection
|
|
100
|
+
* - `new undici.ProxyAgent(proxyUrl)` - HTTP proxy
|
|
101
|
+
* - `new undici.MockAgent()` - in-process mocking
|
|
102
|
+
*
|
|
103
|
+
* When omitted the process-global dispatcher (`getGlobalDispatcher()`)
|
|
104
|
+
* is used, which is undici's default `Agent`.
|
|
105
|
+
*/
|
|
106
|
+
readonly dispatcher?: Dispatcher$1;
|
|
107
|
+
/** Maximum buffered response body size in bytes (default: 32 MiB). */
|
|
108
|
+
readonly maximumResponseBodySize?: number;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Holds the session-level options and exposes the convenience wrappers
|
|
112
|
+
* (`get`, `post`, `delete`) that delegate to the abstract `request` method.
|
|
113
|
+
*
|
|
114
|
+
* Concrete subclasses only need to implement `request()` and `stream()`.
|
|
115
|
+
*/
|
|
116
|
+
declare abstract class BaseUndiciClient implements IHttpClient {
|
|
117
|
+
/** Default headers merged into every outgoing request. */
|
|
118
|
+
protected readonly defaultHeaders: Record<string, string>;
|
|
119
|
+
/** Session-level request timeout in milliseconds. */
|
|
120
|
+
protected readonly defaultTimeout: number;
|
|
121
|
+
/**
|
|
122
|
+
* Shared undici Dispatcher. May be an Agent, Pool, Client, ProxyAgent, etc.
|
|
123
|
+
* Defaults to undici's process-global agent when not specified.
|
|
124
|
+
*/
|
|
125
|
+
protected readonly dispatcher: Dispatcher$1;
|
|
126
|
+
protected readonly maximumResponseBodySize: number;
|
|
127
|
+
constructor(options?: HttpClientOptions);
|
|
128
|
+
get(url: string, options?: RequestOptions): Promise<HttpResponse>;
|
|
129
|
+
post(url: string, options?: RequestOptions): Promise<HttpResponse>;
|
|
130
|
+
delete(url: string, options?: RequestOptions): Promise<HttpResponse>;
|
|
131
|
+
abstract request(method: HttpMethod, url: string, options?: RequestOptions): Promise<HttpResponse>;
|
|
132
|
+
abstract stream(method: HttpMethod, url: string, options?: RequestOptions): Promise<StreamResult>;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* HTTP client backed by `undici.request()`.
|
|
136
|
+
*
|
|
137
|
+
* `undici.request` is the recommended high-level API for most use-cases.
|
|
138
|
+
* It returns a Promise that resolves with `{ statusCode, headers, body }`
|
|
139
|
+
* where `body` is an undici `BodyReadable` (a Node `Readable` subclass).
|
|
140
|
+
*
|
|
141
|
+
* For buffered responses (`request()`) we call `body.text()` to collect the
|
|
142
|
+
* full response. For streaming responses (`stream()`) we return `body`
|
|
143
|
+
* directly as the `StreamResult.body` Readable, giving the caller zero-copy
|
|
144
|
+
* access to the response stream.
|
|
145
|
+
*
|
|
146
|
+
*/
|
|
147
|
+
declare class RequestHttpClient extends BaseUndiciClient {
|
|
148
|
+
/**
|
|
149
|
+
* Buffered request - collects the entire response body as a string.
|
|
150
|
+
*
|
|
151
|
+
* Timeout is implemented via undici's built-in `headersTimeout` /
|
|
152
|
+
* `bodyTimeout` options rather than an external `setTimeout`.
|
|
153
|
+
*/
|
|
154
|
+
request(method: HttpMethod, url: string, options?: RequestOptions): Promise<HttpResponse>;
|
|
155
|
+
/**
|
|
156
|
+
* Streaming request - returns the response body `Readable` without
|
|
157
|
+
* buffering. Used by SSE and long-polling transports.
|
|
158
|
+
*
|
|
159
|
+
* The `abort()` method destroys the underlying socket and the body stream.
|
|
160
|
+
*/
|
|
161
|
+
stream(method: HttpMethod, url: string, options?: RequestOptions): Promise<StreamResult>;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* HTTP client backed by `undici.fetch()`.
|
|
165
|
+
*
|
|
166
|
+
* `undici.fetch` is undici's WHATWG-compatible Fetch implementation.
|
|
167
|
+
* It accepts the same options as the browser `fetch()` API, plus an
|
|
168
|
+
* undici-specific `dispatcher` field for custom transport control.
|
|
169
|
+
*
|
|
170
|
+
* Useful when you need browser API compatibility (e.g., tests that run in
|
|
171
|
+
* both Node and a browser-like environment) or when consuming WHATWG `Response`
|
|
172
|
+
* helpers such as `res.json()` / `res.formData()`.
|
|
173
|
+
*
|
|
174
|
+
* For `stream()` we convert the WHATWG `ReadableStream<Uint8Array>` body to a
|
|
175
|
+
* Node.js `Readable` via `Readable.fromWeb()` (Node 17+).
|
|
176
|
+
*/
|
|
177
|
+
declare class FetchHttpClient extends BaseUndiciClient {
|
|
178
|
+
request(method: HttpMethod, url: string, options?: RequestOptions): Promise<HttpResponse>;
|
|
179
|
+
stream(method: HttpMethod, url: string, options?: RequestOptions): Promise<StreamResult>;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* HTTP client backed by `undici.stream()`.
|
|
183
|
+
*
|
|
184
|
+
* `undici.stream` uses a *factory callback* pattern: you supply a function
|
|
185
|
+
* that receives `{ statusCode, headers, body }` and must return a
|
|
186
|
+
* `Writable` to which the response body is piped.
|
|
187
|
+
*
|
|
188
|
+
* This makes it ideal when you want to pipe response bytes directly to a
|
|
189
|
+
* destination (e.g., a file, a transform, or a compression stream) without
|
|
190
|
+
* ever holding the entire response in memory.
|
|
191
|
+
*
|
|
192
|
+
* For buffered `request()` we use a `PassThrough` as the sink and collect
|
|
193
|
+
* its output. For streaming `stream()` we expose the PassThrough's
|
|
194
|
+
* readable side as `StreamResult.body`.
|
|
195
|
+
*/
|
|
196
|
+
declare class StreamHttpClient extends BaseUndiciClient {
|
|
197
|
+
request(method: HttpMethod, url: string, options?: RequestOptions): Promise<HttpResponse>;
|
|
198
|
+
stream(method: HttpMethod, url: string, options?: RequestOptions): Promise<StreamResult>;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* HTTP client backed by `undici.pipeline()`.
|
|
202
|
+
*
|
|
203
|
+
* `undici.pipeline` returns a `stream.Duplex`:
|
|
204
|
+
* - **Writable side**: the request body (write / pipe into it).
|
|
205
|
+
* - **Readable side**: whatever your handler function *returns*.
|
|
206
|
+
*
|
|
207
|
+
* The handler receives `{ statusCode, headers, body }` and must return a
|
|
208
|
+
* `Readable`. Whatever that readable emits becomes the duplex's output.
|
|
209
|
+
*
|
|
210
|
+
* Typical use: response transformation pipelines
|
|
211
|
+
* `pipeline(url, opts, ({ body }) => body.pipe(gunzip()))`
|
|
212
|
+
*
|
|
213
|
+
* For `request()` we return the raw body from the handler, collect the duplex
|
|
214
|
+
* output into a buffer, and resolve with the buffered string.
|
|
215
|
+
*
|
|
216
|
+
* For `stream()` we return the raw body from the handler and give the caller
|
|
217
|
+
* the duplex's readable side directly - zero extra buffering.
|
|
218
|
+
*/
|
|
219
|
+
declare class PipelineHttpClient extends BaseUndiciClient {
|
|
220
|
+
request(method: HttpMethod, url: string, options?: RequestOptions): Promise<HttpResponse>;
|
|
221
|
+
stream(method: HttpMethod, url: string, options?: RequestOptions): Promise<StreamResult>;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* HTTP client backed by `Dispatcher#dispatch()`.
|
|
225
|
+
*
|
|
226
|
+
* `dispatch` is the *lowest-level* undici API. It exposes the full
|
|
227
|
+
* request/response lifecycle as a handler interface (undici 8+):
|
|
228
|
+
*
|
|
229
|
+
* onRequestStart → request is about to be sent; receives DispatchController
|
|
230
|
+
* onResponseStart → response status + headers received
|
|
231
|
+
* onResponseData → response body chunk
|
|
232
|
+
* onResponseEnd → response fully consumed
|
|
233
|
+
* onResponseError → error at any stage
|
|
234
|
+
*
|
|
235
|
+
* This gives you maximum control: you can abort mid-stream, transform
|
|
236
|
+
* chunks on the fly, or implement custom back-pressure logic.
|
|
237
|
+
*
|
|
238
|
+
* Unlike the other clients, `DispatchHttpClient` *requires* a `Dispatcher`
|
|
239
|
+
* (an `Agent`, `Pool`, or `Client` instance). If none is provided the
|
|
240
|
+
* process-global agent is used.
|
|
241
|
+
*
|
|
242
|
+
* Note: `dispatcher.dispatch()` needs the URL split into `origin` + `path`
|
|
243
|
+
* (for `Agent` / `Pool`) or just `path` (for `Client` whose origin is
|
|
244
|
+
* already bound). We always pass `origin` for maximum compatibility.
|
|
245
|
+
*/
|
|
246
|
+
declare class DispatchHttpClient extends BaseUndiciClient {
|
|
247
|
+
request(method: HttpMethod, url: string, options?: RequestOptions): Promise<HttpResponse>;
|
|
248
|
+
stream(method: HttpMethod, url: string, options?: RequestOptions): Promise<StreamResult>;
|
|
249
|
+
}
|
|
250
|
+
//#endregion
|
|
251
|
+
//#region src/messages.d.ts
|
|
252
|
+
declare const __invocationIdBrand: unique symbol;
|
|
253
|
+
/**
|
|
254
|
+
* Opaque wrapper around `string` for invocation IDs.
|
|
255
|
+
* Prevents mixing arbitrary strings with IDs at the type level.
|
|
256
|
+
*/
|
|
257
|
+
type InvocationId = string & {
|
|
258
|
+
readonly [__invocationIdBrand]: void;
|
|
259
|
+
};
|
|
260
|
+
/** Cast a plain string to an InvocationId (only used inside the library). */
|
|
261
|
+
declare function toInvocationId(s: string): InvocationId;
|
|
262
|
+
/** Optional headers that may appear on any hub message. */
|
|
263
|
+
type MessageHeaders = Readonly<Record<string, string>>;
|
|
264
|
+
interface BaseMessage {
|
|
265
|
+
readonly headers?: MessageHeaders;
|
|
266
|
+
}
|
|
267
|
+
type MT = typeof MessageType;
|
|
268
|
+
/** Type 1 - Server→Client or Client→Server method call. */
|
|
269
|
+
interface InvocationMessage extends BaseMessage {
|
|
270
|
+
readonly type: MT['Invocation'];
|
|
271
|
+
/** Absent on fire-and-forget invocations. */
|
|
272
|
+
readonly invocationId?: InvocationId;
|
|
273
|
+
readonly target: string;
|
|
274
|
+
readonly arguments: readonly unknown[];
|
|
275
|
+
readonly streamIds?: readonly string[];
|
|
276
|
+
}
|
|
277
|
+
/** Type 2 - One item from a server-streaming method. */
|
|
278
|
+
interface StreamItemMessage extends BaseMessage {
|
|
279
|
+
readonly type: MT['StreamItem'];
|
|
280
|
+
readonly invocationId: InvocationId;
|
|
281
|
+
readonly item: unknown;
|
|
282
|
+
}
|
|
283
|
+
/** Type 3 - Terminal result or error for an invocation / stream. */
|
|
284
|
+
interface CompletionMessage extends BaseMessage {
|
|
285
|
+
readonly type: MT['Completion'];
|
|
286
|
+
readonly invocationId: InvocationId;
|
|
287
|
+
readonly error?: string;
|
|
288
|
+
readonly result?: unknown;
|
|
289
|
+
}
|
|
290
|
+
/** Type 4 - Client initiates a server-streaming call. */
|
|
291
|
+
interface StreamInvocationMessage extends BaseMessage {
|
|
292
|
+
readonly type: MT['StreamInvocation'];
|
|
293
|
+
readonly invocationId: InvocationId;
|
|
294
|
+
readonly target: string;
|
|
295
|
+
readonly arguments: readonly unknown[];
|
|
296
|
+
readonly streamIds?: readonly string[];
|
|
297
|
+
}
|
|
298
|
+
/** Type 5 - Client cancels an outstanding server stream. */
|
|
299
|
+
interface CancelInvocationMessage extends BaseMessage {
|
|
300
|
+
readonly type: MT['CancelInvocation'];
|
|
301
|
+
readonly invocationId: InvocationId;
|
|
302
|
+
}
|
|
303
|
+
/** Type 6 - Keep-alive ping; expects no response from the other side. */
|
|
304
|
+
interface PingMessage extends BaseMessage {
|
|
305
|
+
readonly type: MT['Ping'];
|
|
306
|
+
}
|
|
307
|
+
/** Type 7 - Graceful close notification from the server. */
|
|
308
|
+
interface CloseMessage extends BaseMessage {
|
|
309
|
+
readonly type: MT['Close'];
|
|
310
|
+
readonly error?: string;
|
|
311
|
+
readonly allowReconnect?: boolean;
|
|
312
|
+
}
|
|
313
|
+
/** Exhaustive discriminated union of all SignalR hub protocol messages. */
|
|
314
|
+
type HubMessage = InvocationMessage | StreamItemMessage | CompletionMessage | StreamInvocationMessage | CancelInvocationMessage | PingMessage | CloseMessage;
|
|
315
|
+
/**
|
|
316
|
+
* Asserts a code path is unreachable at compile time.
|
|
317
|
+
* Use at the `default` branch of a `switch` over `HubMessage['type']`.
|
|
318
|
+
*/
|
|
319
|
+
declare function assertNever(_x: never, label?: string): never;
|
|
320
|
+
declare function isInvocationMessage(msg: HubMessage): msg is InvocationMessage;
|
|
321
|
+
declare function isStreamItemMessage(msg: HubMessage): msg is StreamItemMessage;
|
|
322
|
+
declare function isCompletionMessage(msg: HubMessage): msg is CompletionMessage;
|
|
323
|
+
declare function isStreamInvocationMessage(msg: HubMessage): msg is StreamInvocationMessage;
|
|
324
|
+
declare function isCancelInvocationMessage(msg: HubMessage): msg is CancelInvocationMessage;
|
|
325
|
+
declare function isPingMessage(msg: HubMessage): msg is PingMessage;
|
|
326
|
+
declare function isCloseMessage(msg: HubMessage): msg is CloseMessage;
|
|
327
|
+
//#endregion
|
|
328
|
+
//#region src/interfaces.d.ts
|
|
329
|
+
/** Minimal logger contract. Implement this to plug in any logging framework. */
|
|
330
|
+
interface ILogger {
|
|
331
|
+
log(logLevel: LogLevel, message: string): void;
|
|
332
|
+
}
|
|
333
|
+
/** Low-level transport abstraction (WebSocket / SSE / LongPolling). */
|
|
334
|
+
interface ITransport {
|
|
335
|
+
/** Human-readable name used in log messages and error reporting. */
|
|
336
|
+
readonly name: string;
|
|
337
|
+
/**
|
|
338
|
+
* Open the transport connection.
|
|
339
|
+
* @param url Fully-qualified URL including any query parameters.
|
|
340
|
+
* @param transferFormat Text or Binary.
|
|
341
|
+
*/
|
|
342
|
+
connect(url: string, transferFormat: TransferFormat): Promise<void>;
|
|
343
|
+
/** Send a message over the open transport. */
|
|
344
|
+
send(data: string | Uint8Array): Promise<void>;
|
|
345
|
+
/** Tear down the connection cleanly. */
|
|
346
|
+
stop(): Promise<void>;
|
|
347
|
+
/** Called by HubConnection whenever data arrives. */
|
|
348
|
+
onreceive: ((data: string | Uint8Array) => void) | null;
|
|
349
|
+
/** Called by HubConnection when the transport is closed (optionally with error). */
|
|
350
|
+
onclose: ((error?: Error) => void) | null;
|
|
351
|
+
}
|
|
352
|
+
/** Wire-protocol codec used by a HubConnection. */
|
|
353
|
+
interface IHubProtocol {
|
|
354
|
+
readonly name: string;
|
|
355
|
+
readonly version: number;
|
|
356
|
+
readonly transferFormat: TransferFormat;
|
|
357
|
+
/**
|
|
358
|
+
* Decode raw bytes/string into zero or more hub messages.
|
|
359
|
+
* Implementations must handle partial/buffered inputs gracefully.
|
|
360
|
+
*/
|
|
361
|
+
parseMessages(input: string | ArrayBuffer, logger: ILogger): HubMessage[];
|
|
362
|
+
/** Encode a single hub message to its wire representation. */
|
|
363
|
+
writeMessage(message: HubMessage): string | ArrayBuffer;
|
|
364
|
+
}
|
|
365
|
+
/** Context passed to the retry policy on each reconnect attempt. */
|
|
366
|
+
interface RetryContext {
|
|
367
|
+
readonly previousRetryCount: number;
|
|
368
|
+
readonly elapsedMilliseconds: number;
|
|
369
|
+
readonly retryReason: Error | null;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Controls the automatic-reconnect delay strategy.
|
|
373
|
+
* Return `null` to stop retrying.
|
|
374
|
+
*/
|
|
375
|
+
interface IRetryPolicy {
|
|
376
|
+
nextRetryDelayInMilliseconds(retryContext: RetryContext): number | null;
|
|
377
|
+
}
|
|
378
|
+
/** Observer passed to `IStreamResult.subscribe`. */
|
|
379
|
+
interface IStreamSubscriber<T> {
|
|
380
|
+
readonly next?: (value: T) => void;
|
|
381
|
+
readonly error?: (err: Error) => void;
|
|
382
|
+
readonly complete?: () => void;
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* A handle returned by `subscribe` that lets the caller cancel the stream.
|
|
386
|
+
* Implements `Symbol.dispose` for use with the `using` keyword (TS 5.2+).
|
|
387
|
+
*/
|
|
388
|
+
interface ISubscription {
|
|
389
|
+
dispose(): void;
|
|
390
|
+
/** Enables `using subscription = connection.stream(...).subscribe(...)` */
|
|
391
|
+
[Symbol.dispose](): void;
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* A running server-streaming invocation. It supports one subscriber.
|
|
395
|
+
*/
|
|
396
|
+
interface IStreamResult<T> {
|
|
397
|
+
subscribe(subscriber: IStreamSubscriber<T>): ISubscription;
|
|
398
|
+
}
|
|
399
|
+
/** Shape of the /negotiate response from an ASP.NET Core SignalR server. */
|
|
400
|
+
interface NegotiateResponse {
|
|
401
|
+
readonly connectionId?: string;
|
|
402
|
+
readonly connectionToken?: string;
|
|
403
|
+
readonly negotiateVersion?: number;
|
|
404
|
+
readonly url?: string;
|
|
405
|
+
readonly accessToken?: string;
|
|
406
|
+
readonly error?: string;
|
|
407
|
+
readonly availableTransports?: readonly AvailableTransport[];
|
|
408
|
+
}
|
|
409
|
+
interface AvailableTransport {
|
|
410
|
+
readonly transport: string;
|
|
411
|
+
readonly transferFormats: readonly string[];
|
|
412
|
+
}
|
|
413
|
+
/** Buffered HTTP response shared by all client implementations. */
|
|
414
|
+
interface HttpResponse {
|
|
415
|
+
readonly status: number;
|
|
416
|
+
readonly headers: Readonly<Record<string, string | string[] | undefined>>;
|
|
417
|
+
readonly body: string;
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Result of a non-buffered (streaming) HTTP request.
|
|
421
|
+
*
|
|
422
|
+
* `body` - Node.js Readable carrying the response bytes.
|
|
423
|
+
* The SSE and long-polling transports consume this stream directly.
|
|
424
|
+
*
|
|
425
|
+
* `abort` - Cancels the in-flight request and destroys the body stream.
|
|
426
|
+
* Replaces the former `req.destroy()` pattern.
|
|
427
|
+
*/
|
|
428
|
+
interface StreamResult {
|
|
429
|
+
readonly statusCode: number;
|
|
430
|
+
readonly headers: Readonly<Record<string, string | string[] | undefined>>;
|
|
431
|
+
readonly body: Readable;
|
|
432
|
+
abort(): void;
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Common contract satisfied by all five HTTP client variants
|
|
436
|
+
* (Request, Fetch, Stream, Pipeline, Dispatch).
|
|
437
|
+
*
|
|
438
|
+
* HubConnection depends on this interface so any implementation can be
|
|
439
|
+
* injected via `HubConnectionOptions.httpClient`.
|
|
440
|
+
*/
|
|
441
|
+
interface IHttpClient {
|
|
442
|
+
get(url: string, options?: RequestOptions): Promise<HttpResponse>;
|
|
443
|
+
post(url: string, options?: RequestOptions): Promise<HttpResponse>;
|
|
444
|
+
delete(url: string, options?: RequestOptions): Promise<HttpResponse>;
|
|
445
|
+
request(method: HttpMethod, url: string, options?: RequestOptions): Promise<HttpResponse>;
|
|
446
|
+
stream(method: HttpMethod, url: string, options?: RequestOptions): Promise<StreamResult>;
|
|
447
|
+
}
|
|
448
|
+
//#endregion
|
|
449
|
+
//#region src/hub-connection.d.ts
|
|
450
|
+
interface HubConnectionOptions {
|
|
451
|
+
readonly logger?: ILogger;
|
|
452
|
+
readonly accessTokenFactory?: () => Promise<string | null>;
|
|
453
|
+
/** Bitmask of HttpTransportType flags (default: all transports). */
|
|
454
|
+
readonly transport?: number;
|
|
455
|
+
readonly headers?: Record<string, string>;
|
|
456
|
+
readonly skipNegotiation?: boolean;
|
|
457
|
+
readonly serverTimeoutInMilliseconds?: number;
|
|
458
|
+
readonly keepAliveIntervalInMilliseconds?: number;
|
|
459
|
+
/**
|
|
460
|
+
* Override the SignalR handshake timeout (ms). Defaults to 15 000.
|
|
461
|
+
* Intended for testing; production code should leave this at the default.
|
|
462
|
+
*/
|
|
463
|
+
readonly handshakeTimeoutInMilliseconds?: number;
|
|
464
|
+
readonly reconnectPolicy?: IRetryPolicy | null;
|
|
465
|
+
/**
|
|
466
|
+
* undici Dispatcher shared by all HTTP requests (negotiate, SSE, polling)
|
|
467
|
+
* and the WebSocket upgrade for this connection.
|
|
468
|
+
*
|
|
469
|
+
* Pass an `Agent`, `Pool`, `Client`, `ProxyAgent`, etc. to customise
|
|
470
|
+
* connection pooling, TLS, or proxy routing for the entire SignalR session.
|
|
471
|
+
* When omitted, undici's process-global default agent is used.
|
|
472
|
+
*/
|
|
473
|
+
readonly dispatcher?: Dispatcher;
|
|
474
|
+
/**
|
|
475
|
+
* Custom HTTP client to use for all requests made by this connection
|
|
476
|
+
* (negotiate, SSE body reads, long-polling).
|
|
477
|
+
*
|
|
478
|
+
* When omitted, a `DispatchHttpClient` is created automatically using
|
|
479
|
+
* the `dispatcher` option (if any). Provide this to use a different
|
|
480
|
+
* undici primitive (e.g. `FetchHttpClient`) or to inject a mock in tests.
|
|
481
|
+
*/
|
|
482
|
+
readonly httpClient?: IHttpClient;
|
|
483
|
+
/** Hub wire protocol. Defaults to JSON protocol version 1. */
|
|
484
|
+
readonly protocol?: IHubProtocol;
|
|
485
|
+
/** Maximum accepted transport payload size. Defaults to 32 MiB. */
|
|
486
|
+
readonly maximumReceiveMessageSize?: number;
|
|
487
|
+
/** Internal: close a builder-created dispatcher when the connection ends. */
|
|
488
|
+
readonly ownsDispatcher?: boolean;
|
|
489
|
+
}
|
|
490
|
+
declare class HubConnection {
|
|
491
|
+
#private;
|
|
492
|
+
constructor(url: string, options?: HubConnectionOptions);
|
|
493
|
+
get state(): HubConnectionState;
|
|
494
|
+
get connectionId(): string | null;
|
|
495
|
+
start(): Promise<void>;
|
|
496
|
+
stop(): Promise<void>;
|
|
497
|
+
/**
|
|
498
|
+
* Invoke a hub method and return the server's result.
|
|
499
|
+
*
|
|
500
|
+
* @typeParam T The expected return type. Asserted at runtime - the server
|
|
501
|
+
* decides the actual value.
|
|
502
|
+
*/
|
|
503
|
+
invoke<T = void>(methodName: string, ...args: unknown[]): Promise<T>;
|
|
504
|
+
/**
|
|
505
|
+
* Fire-and-forget hub method invocation.
|
|
506
|
+
* The server does not send a completion message.
|
|
507
|
+
*/
|
|
508
|
+
send(methodName: string, ...args: unknown[]): Promise<void>;
|
|
509
|
+
/**
|
|
510
|
+
* Start a server-streaming invocation immediately.
|
|
511
|
+
* The returned `ISubscription` implements `Symbol.dispose` for `using`.
|
|
512
|
+
*
|
|
513
|
+
* @typeParam T Type of each streamed item.
|
|
514
|
+
*
|
|
515
|
+
* @example
|
|
516
|
+
* ```ts
|
|
517
|
+
* using sub = connection.stream<number>('Counter', 10).subscribe({
|
|
518
|
+
* next: (n) => console.log(n),
|
|
519
|
+
* complete: () => console.log('done'),
|
|
520
|
+
* });
|
|
521
|
+
* ```
|
|
522
|
+
*/
|
|
523
|
+
stream<T = unknown>(methodName: string, ...args: unknown[]): IStreamResult<T>;
|
|
524
|
+
/**
|
|
525
|
+
* Register a handler for a server→client hub method.
|
|
526
|
+
* Multiple handlers for the same method are supported.
|
|
527
|
+
*
|
|
528
|
+
* @typeParam TArgs Tuple of argument types for the hub method.
|
|
529
|
+
*/
|
|
530
|
+
on<TArgs extends unknown[] = unknown[]>(methodName: string, handler: (...args: TArgs) => unknown): void;
|
|
531
|
+
/**
|
|
532
|
+
* Remove a previously registered handler, or all handlers for a method.
|
|
533
|
+
*/
|
|
534
|
+
off(methodName: string, handler?: (...args: unknown[]) => unknown): void;
|
|
535
|
+
onclose(callback: (error?: Error) => void): void;
|
|
536
|
+
onreconnecting(callback: (error?: Error) => void): void;
|
|
537
|
+
onreconnected(callback: (connectionId: string | null) => void): void;
|
|
538
|
+
}
|
|
539
|
+
//#endregion
|
|
540
|
+
//#region src/hub-connection-builder.d.ts
|
|
541
|
+
interface UrlOptions {
|
|
542
|
+
/** Async function returning a Bearer token (or null for unauthenticated). */
|
|
543
|
+
readonly accessTokenFactory?: () => Promise<string | null>;
|
|
544
|
+
/**
|
|
545
|
+
* Bitmask of {@link HttpTransportType} values.
|
|
546
|
+
* Defaults to all three transports if omitted.
|
|
547
|
+
*/
|
|
548
|
+
readonly transport?: number;
|
|
549
|
+
/** Extra HTTP headers appended to every request (negotiate, upgrade, poll…). */
|
|
550
|
+
readonly headers?: Record<string, string>;
|
|
551
|
+
/**
|
|
552
|
+
* Skip the /negotiate step and connect directly via WebSocket.
|
|
553
|
+
* Only valid when transport is exclusively `HttpTransportType.WebSockets`.
|
|
554
|
+
*/
|
|
555
|
+
readonly skipNegotiation?: boolean;
|
|
556
|
+
/** ms before the connection is considered unresponsive (default: 30 000). */
|
|
557
|
+
readonly serverTimeoutInMilliseconds?: number;
|
|
558
|
+
/** ms between keep-alive pings (default: 15 000). */
|
|
559
|
+
readonly keepAliveIntervalInMilliseconds?: number;
|
|
560
|
+
/** ms to wait for the SignalR handshake response (default: 15 000). */
|
|
561
|
+
readonly handshakeTimeoutInMilliseconds?: number;
|
|
562
|
+
/** Maximum accepted transport payload size (default: 32 MiB). */
|
|
563
|
+
readonly maximumReceiveMessageSize?: number;
|
|
564
|
+
}
|
|
565
|
+
declare class HubConnectionBuilder {
|
|
566
|
+
#private;
|
|
567
|
+
withUrl(url: string, options?: UrlOptions): this;
|
|
568
|
+
/**
|
|
569
|
+
* Enable automatic cookie handling for the entire connection session using
|
|
570
|
+
* a `tough-cookie` `CookieJar` and an `@exhumer/undici-cookie-agent` `CookieAgent`.
|
|
571
|
+
*
|
|
572
|
+
* When enabled, the `CookieAgent` wraps every outgoing request - including
|
|
573
|
+
* the `/negotiate` POST, WebSocket upgrade, SSE long-lived GET, and all
|
|
574
|
+
* long-polling requests - so that:
|
|
575
|
+
*
|
|
576
|
+
* 1. `Set-Cookie` headers in the **negotiate response** (and any subsequent
|
|
577
|
+
* response) are stored in the jar automatically.
|
|
578
|
+
* 2. All subsequent requests from the same session include the matching
|
|
579
|
+
* `Cookie` header, exactly as a browser would.
|
|
580
|
+
*
|
|
581
|
+
* @param jar
|
|
582
|
+
* An existing `CookieJar` to use. Pass your own jar when you need to
|
|
583
|
+
* pre-seed cookies (e.g. an auth session cookie obtained before calling
|
|
584
|
+
* `start()`) or inspect the jar after the session ends.
|
|
585
|
+
* When omitted a new, empty jar is created automatically.
|
|
586
|
+
*
|
|
587
|
+
* @throws if {@link withDispatcher} has already been called. To combine a
|
|
588
|
+
* custom dispatcher (e.g. `ProxyAgent`) with cookie support, compose the
|
|
589
|
+
* `cookie` interceptor onto your dispatcher and pass it to `withDispatcher()`:
|
|
590
|
+
*
|
|
591
|
+
* ```ts
|
|
592
|
+
* import { ProxyAgent } from 'undici';
|
|
593
|
+
* import { cookie, CookieJar } from '@exhumer/signalr-client';
|
|
594
|
+
*
|
|
595
|
+
* const jar = new CookieJar();
|
|
596
|
+
* const agent = new ProxyAgent('http://proxy:8080').compose(cookie({ jar }));
|
|
597
|
+
*
|
|
598
|
+
* const conn = new HubConnectionBuilder()
|
|
599
|
+
* .withUrl('https://example.com/hub')
|
|
600
|
+
* .withDispatcher(agent)
|
|
601
|
+
* .build();
|
|
602
|
+
* ```
|
|
603
|
+
*
|
|
604
|
+
* @example
|
|
605
|
+
* ```ts
|
|
606
|
+
* // Automatic jar - no pre-configuration needed
|
|
607
|
+
* const conn = new HubConnectionBuilder()
|
|
608
|
+
* .withUrl('https://example.com/hub')
|
|
609
|
+
* .withCookies()
|
|
610
|
+
* .build();
|
|
611
|
+
*
|
|
612
|
+
* // Pre-seeded jar - inject a session cookie before connecting
|
|
613
|
+
* import { CookieJar } from '@exhumer/signalr-client';
|
|
614
|
+
* const jar = new CookieJar();
|
|
615
|
+
* await jar.setCookie('session=abc123', 'https://example.com');
|
|
616
|
+
*
|
|
617
|
+
* const conn = new HubConnectionBuilder()
|
|
618
|
+
* .withUrl('https://example.com/hub')
|
|
619
|
+
* .withCookies(jar)
|
|
620
|
+
* .build();
|
|
621
|
+
* ```
|
|
622
|
+
*/
|
|
623
|
+
withCookies(jar?: CookieJar$1): this;
|
|
624
|
+
/**
|
|
625
|
+
* Set the undici `Dispatcher` for the entire connection session.
|
|
626
|
+
*
|
|
627
|
+
* The same dispatcher is used for:
|
|
628
|
+
* • the `/negotiate` HTTP POST
|
|
629
|
+
* • the WebSocket upgrade request
|
|
630
|
+
* • SSE long-lived GET and send POSTs
|
|
631
|
+
* • long-polling GETs, POSTs, and DELETE
|
|
632
|
+
*
|
|
633
|
+
* Accepts any `Dispatcher` subclass: `Agent`, `Pool`, `Client`,
|
|
634
|
+
* `ProxyAgent`, `MockAgent`, etc.
|
|
635
|
+
*
|
|
636
|
+
* To combine a custom dispatcher with automatic cookie handling, use
|
|
637
|
+
* `createCookieAgentClass()` to build a cookie-aware variant of your
|
|
638
|
+
* dispatcher and pass that here. Do **not** chain both
|
|
639
|
+
* `withDispatcher()` and `withCookies()` - they are mutually exclusive
|
|
640
|
+
* because `withCookies()` creates its own dispatcher internally.
|
|
641
|
+
*
|
|
642
|
+
* @example
|
|
643
|
+
* ```ts
|
|
644
|
+
* import { ProxyAgent } from 'undici';
|
|
645
|
+
*
|
|
646
|
+
* const conn = new HubConnectionBuilder()
|
|
647
|
+
* .withUrl('https://example.com/hub')
|
|
648
|
+
* .withDispatcher(new ProxyAgent('http://proxy:8080'))
|
|
649
|
+
* .build();
|
|
650
|
+
* ```
|
|
651
|
+
*/
|
|
652
|
+
withDispatcher(dispatcher: Dispatcher): this;
|
|
653
|
+
/**
|
|
654
|
+
* Provide a custom HTTP client implementation.
|
|
655
|
+
*
|
|
656
|
+
* By default `HubConnection` uses `DispatchHttpClient` (undici `dispatch`).
|
|
657
|
+
* Use this to substitute any of the other undici-backed clients, or
|
|
658
|
+
* to inject a mock for testing.
|
|
659
|
+
*
|
|
660
|
+
* @example
|
|
661
|
+
* ```ts
|
|
662
|
+
* import { FetchHttpClient } from '@signalr/client';
|
|
663
|
+
*
|
|
664
|
+
* const conn = new HubConnectionBuilder()
|
|
665
|
+
* .withUrl('https://example.com/hub')
|
|
666
|
+
* .withHttpClient(new FetchHttpClient())
|
|
667
|
+
* .build();
|
|
668
|
+
* ```
|
|
669
|
+
*/
|
|
670
|
+
withHttpClient(httpClient: IHttpClient): this;
|
|
671
|
+
/** Select the hub wire protocol (for example, MessagePack). */
|
|
672
|
+
withHubProtocol(protocol: IHubProtocol): this;
|
|
673
|
+
/**
|
|
674
|
+
* Set the minimum log level or provide a custom logger.
|
|
675
|
+
*
|
|
676
|
+
* @param logLevelOrLogger
|
|
677
|
+
* - `LogLevel` number → uses the built-in ConsoleLogger
|
|
678
|
+
* - `ILogger` object → used as-is
|
|
679
|
+
*/
|
|
680
|
+
configureLogging(logLevelOrLogger: LogLevel | ILogger): this;
|
|
681
|
+
/**
|
|
682
|
+
* Enable automatic reconnection on unexpected disconnections.
|
|
683
|
+
*
|
|
684
|
+
* @overload withAutomaticReconnect()
|
|
685
|
+
* Uses the built-in delay sequence: 0 ms, 2 s, 10 s, 30 s.
|
|
686
|
+
*
|
|
687
|
+
* @overload withAutomaticReconnect(retryDelays: readonly number[])
|
|
688
|
+
* Each element is the wait (ms) before the corresponding retry.
|
|
689
|
+
* Reconnection stops after all delays are exhausted.
|
|
690
|
+
* Uses `NoInfer<number>` so literals are not widened unexpectedly.
|
|
691
|
+
*
|
|
692
|
+
* @overload withAutomaticReconnect(policy: IRetryPolicy)
|
|
693
|
+
* Custom policy. Return `null` from
|
|
694
|
+
* `nextRetryDelayInMilliseconds` to stop retrying.
|
|
695
|
+
*/
|
|
696
|
+
withAutomaticReconnect(): this;
|
|
697
|
+
withAutomaticReconnect(retryDelays: readonly NoInfer<number>[]): this;
|
|
698
|
+
withAutomaticReconnect(policy: IRetryPolicy): this;
|
|
699
|
+
build(): HubConnection;
|
|
700
|
+
}
|
|
701
|
+
declare class DefaultReconnectPolicy implements IRetryPolicy {
|
|
702
|
+
#private;
|
|
703
|
+
constructor(retryDelays?: readonly number[]);
|
|
704
|
+
nextRetryDelayInMilliseconds(context: RetryContext): number | null;
|
|
705
|
+
}
|
|
706
|
+
//#endregion
|
|
707
|
+
//#region src/protocols/json-hub-protocol.d.ts
|
|
708
|
+
declare const HANDSHAKE_REQUEST: string;
|
|
709
|
+
interface HandshakeResponse {
|
|
710
|
+
readonly error?: string;
|
|
711
|
+
readonly minorVersion?: number;
|
|
712
|
+
}
|
|
713
|
+
interface HandshakeParseResult {
|
|
714
|
+
/** Remainder of the input string after the handshake record (may be non-empty). */
|
|
715
|
+
readonly remainder: string;
|
|
716
|
+
}
|
|
717
|
+
/**
|
|
718
|
+
* Parse the first record from `data` as the server handshake response.
|
|
719
|
+
* @throws {Error} if the record separator is missing or the server returned an error.
|
|
720
|
+
*/
|
|
721
|
+
declare function parseHandshakeResponse(data: string): HandshakeParseResult;
|
|
722
|
+
declare class JsonHubProtocol implements IHubProtocol {
|
|
723
|
+
#private;
|
|
724
|
+
readonly name: "json";
|
|
725
|
+
readonly version: 1;
|
|
726
|
+
readonly transferFormat: 1;
|
|
727
|
+
parseMessages(input: string | ArrayBuffer, logger: ILogger): HubMessage[];
|
|
728
|
+
writeMessage(message: HubMessage): string;
|
|
729
|
+
static invocation(invocationId: InvocationId, target: string, args: readonly unknown[], streamIds?: readonly string[]): InvocationMessage;
|
|
730
|
+
/**
|
|
731
|
+
* Fire-and-forget (no `invocationId` → server won't send a Completion).
|
|
732
|
+
*/
|
|
733
|
+
static send(target: string, args: readonly unknown[], streamIds?: readonly string[]): InvocationMessage;
|
|
734
|
+
static streamInvocation(invocationId: InvocationId, target: string, args: readonly unknown[], streamIds?: readonly string[]): StreamInvocationMessage;
|
|
735
|
+
static cancelInvocation(invocationId: InvocationId): CancelInvocationMessage;
|
|
736
|
+
static streamItem(invocationId: InvocationId, item: unknown): StreamItemMessage;
|
|
737
|
+
static completion(invocationId: InvocationId, result: unknown, error: string | null): CompletionMessage;
|
|
738
|
+
static ping(): PingMessage;
|
|
739
|
+
}
|
|
740
|
+
//#endregion
|
|
741
|
+
//#region src/protocols/msgpack-hub-protocol.d.ts
|
|
742
|
+
/**
|
|
743
|
+
* The JSON-formatted handshake request the client sends once the transport
|
|
744
|
+
* is open. The server always responds with JSON ({} on success), regardless
|
|
745
|
+
* of the chosen hub protocol.
|
|
746
|
+
*/
|
|
747
|
+
declare const HANDSHAKE_REQUEST$1: string;
|
|
748
|
+
declare class MsgpackHubProtocol implements IHubProtocol {
|
|
749
|
+
#private;
|
|
750
|
+
readonly name: "messagepack";
|
|
751
|
+
readonly version: 1;
|
|
752
|
+
readonly transferFormat: 2;
|
|
753
|
+
parseMessages(input: string | ArrayBuffer, logger: ILogger): HubMessage[];
|
|
754
|
+
writeMessage(message: HubMessage): ArrayBuffer;
|
|
755
|
+
static invocation(invocationId: InvocationId, target: string, args: readonly unknown[], streamIds?: readonly string[]): InvocationMessage;
|
|
756
|
+
/** Fire-and-forget (no `invocationId`). */
|
|
757
|
+
static send(target: string, args: readonly unknown[], streamIds?: readonly string[]): InvocationMessage;
|
|
758
|
+
static streamInvocation(invocationId: InvocationId, target: string, args: readonly unknown[], streamIds?: readonly string[]): StreamInvocationMessage;
|
|
759
|
+
static cancelInvocation(invocationId: InvocationId): CancelInvocationMessage;
|
|
760
|
+
static streamItem(invocationId: InvocationId, item: unknown): StreamItemMessage;
|
|
761
|
+
static completion(invocationId: InvocationId, result: unknown, error: string | null): CompletionMessage;
|
|
762
|
+
static ping(): PingMessage;
|
|
763
|
+
}
|
|
764
|
+
//#endregion
|
|
765
|
+
//#region src/logger.d.ts
|
|
766
|
+
declare class ConsoleLogger implements ILogger {
|
|
767
|
+
#private;
|
|
768
|
+
constructor(minimumLevel?: LogLevel);
|
|
769
|
+
log(level: LogLevel, message: string): void;
|
|
770
|
+
}
|
|
771
|
+
declare class NullLogger implements ILogger {
|
|
772
|
+
/** Singleton - no state, so one instance is enough. */
|
|
773
|
+
static readonly instance: NullLogger;
|
|
774
|
+
log(_logLevel: LogLevel, _message: string): void;
|
|
775
|
+
}
|
|
776
|
+
//#endregion
|
|
777
|
+
//#region src/errors.d.ts
|
|
778
|
+
/**
|
|
779
|
+
* errors.ts
|
|
780
|
+
*
|
|
781
|
+
* Typed error classes for the SignalR client. Each has a distinct `name`
|
|
782
|
+
* so callers can use `instanceof` or switch on `error.name` to distinguish
|
|
783
|
+
* error categories at runtime.
|
|
784
|
+
*/
|
|
785
|
+
/** Thrown when a hub method invocation fails with a server-side error. */
|
|
786
|
+
declare class HubError extends Error {
|
|
787
|
+
readonly name: "HubError";
|
|
788
|
+
constructor(message: string);
|
|
789
|
+
}
|
|
790
|
+
/** Thrown when an in-flight operation is cancelled (e.g. connection closed). */
|
|
791
|
+
declare class AbortError extends Error {
|
|
792
|
+
readonly name: "AbortError";
|
|
793
|
+
constructor(message?: string);
|
|
794
|
+
}
|
|
795
|
+
/** Thrown on network-level transport failures. */
|
|
796
|
+
declare class TransportError extends Error {
|
|
797
|
+
readonly name: "TransportError";
|
|
798
|
+
readonly statusCode: number | undefined;
|
|
799
|
+
constructor(message: string, statusCode?: number);
|
|
800
|
+
}
|
|
801
|
+
/** Thrown when the SignalR protocol handshake is rejected by the server. */
|
|
802
|
+
declare class HandshakeError extends Error {
|
|
803
|
+
readonly name: "HandshakeError";
|
|
804
|
+
constructor(message: string);
|
|
805
|
+
}
|
|
806
|
+
/** Thrown when no acceptable transport could be negotiated. */
|
|
807
|
+
declare class UnsupportedTransportError extends Error {
|
|
808
|
+
readonly name: "UnsupportedTransportError";
|
|
809
|
+
readonly transport: number | null;
|
|
810
|
+
constructor(message: string, transport: number | null);
|
|
811
|
+
}
|
|
812
|
+
declare function isHubError(e: unknown): e is HubError;
|
|
813
|
+
declare function isAbortError(e: unknown): e is AbortError;
|
|
814
|
+
declare function isTransportError(e: unknown): e is TransportError;
|
|
815
|
+
//#endregion
|
|
816
|
+
//#region src/transports/websocket-transport.d.ts
|
|
817
|
+
declare class WebSocketTransport implements ITransport {
|
|
818
|
+
#private;
|
|
819
|
+
readonly name: "WebSockets";
|
|
820
|
+
onclose: ((error?: Error) => void) | null;
|
|
821
|
+
get onreceive(): ((data: string | Uint8Array) => void) | null;
|
|
822
|
+
set onreceive(handler: ((data: string | Uint8Array) => void) | null);
|
|
823
|
+
/**
|
|
824
|
+
* @param accessTokenFactory Async factory for Bearer tokens, or null.
|
|
825
|
+
* @param logger Logger instance.
|
|
826
|
+
* @param extraHeaders Headers forwarded on every upgrade request.
|
|
827
|
+
* @param dispatcher Optional undici Dispatcher (Agent/Pool/Client/
|
|
828
|
+
* ProxyAgent). When omitted, undici's default
|
|
829
|
+
* global agent is used. Pass the same dispatcher
|
|
830
|
+
* used by your HTTP clients to share the pool.
|
|
831
|
+
*/
|
|
832
|
+
constructor(accessTokenFactory: (() => Promise<string | null>) | null, logger: ILogger, extraHeaders?: Record<string, string>, dispatcher?: Dispatcher$1);
|
|
833
|
+
connect(url: string, _transferFormat: TransferFormat): Promise<void>;
|
|
834
|
+
send(data: string | Uint8Array): Promise<void>;
|
|
835
|
+
stop(): Promise<void>;
|
|
836
|
+
}
|
|
837
|
+
//#endregion
|
|
838
|
+
//#region src/transports/sse-transport.d.ts
|
|
839
|
+
declare class ServerSentEventsTransport implements ITransport {
|
|
840
|
+
#private;
|
|
841
|
+
readonly name: "ServerSentEvents";
|
|
842
|
+
onreceive: ((data: string | Uint8Array) => void) | null;
|
|
843
|
+
onclose: ((error?: Error) => void) | null;
|
|
844
|
+
constructor(httpClient: IHttpClient, accessTokenFactory: (() => Promise<string | null>) | null, logger: ILogger, extraHeaders?: Record<string, string>);
|
|
845
|
+
connect(url: string, transferFormat: TransferFormat): Promise<void>;
|
|
846
|
+
send(data: string | Uint8Array): Promise<void>;
|
|
847
|
+
stop(): Promise<void>;
|
|
848
|
+
}
|
|
849
|
+
//#endregion
|
|
850
|
+
//#region src/transports/long-polling-transport.d.ts
|
|
851
|
+
declare class LongPollingTransport implements ITransport {
|
|
852
|
+
#private;
|
|
853
|
+
readonly name: "LongPolling";
|
|
854
|
+
onreceive: ((data: string | Uint8Array) => void) | null;
|
|
855
|
+
onclose: ((error?: Error) => void) | null;
|
|
856
|
+
constructor(httpClient: IHttpClient, accessTokenFactory: (() => Promise<string | null>) | null, logger: ILogger, extraHeaders?: Record<string, string>);
|
|
857
|
+
connect(url: string, transferFormat: TransferFormat): Promise<void>;
|
|
858
|
+
send(data: string | Uint8Array): Promise<void>;
|
|
859
|
+
stop(): Promise<void>;
|
|
860
|
+
}
|
|
861
|
+
//#endregion
|
|
862
|
+
//#region src/ws-client.d.ts
|
|
863
|
+
declare const enum WebSocketReadyState {
|
|
864
|
+
Connecting = 0,
|
|
865
|
+
Open = 1,
|
|
866
|
+
Closing = 2,
|
|
867
|
+
Closed = 3
|
|
868
|
+
}
|
|
869
|
+
interface WebSocketClient {
|
|
870
|
+
on(event: 'open', listener: () => void): this;
|
|
871
|
+
on(event: 'message', listener: (data: string) => void): this;
|
|
872
|
+
on(event: 'binary', listener: (data: Buffer) => void): this;
|
|
873
|
+
on(event: 'ping', listener: (data: Buffer) => void): this;
|
|
874
|
+
on(event: 'pong', listener: (data: Buffer) => void): this;
|
|
875
|
+
on(event: 'close', listener: () => void): this;
|
|
876
|
+
on(event: 'error', listener: (err: Error) => void): this;
|
|
877
|
+
once(event: 'open', listener: () => void): this;
|
|
878
|
+
once(event: 'message', listener: (data: string) => void): this;
|
|
879
|
+
once(event: 'close', listener: () => void): this;
|
|
880
|
+
once(event: 'error', listener: (err: Error) => void): this;
|
|
881
|
+
emit(event: 'open'): boolean;
|
|
882
|
+
emit(event: 'message', data: string): boolean;
|
|
883
|
+
emit(event: 'binary', data: Buffer): boolean;
|
|
884
|
+
emit(event: 'ping', data: Buffer): boolean;
|
|
885
|
+
emit(event: 'pong', data: Buffer): boolean;
|
|
886
|
+
emit(event: 'close'): boolean;
|
|
887
|
+
emit(event: 'error', err: Error): boolean;
|
|
888
|
+
removeAllListeners(event?: string): this;
|
|
889
|
+
}
|
|
890
|
+
declare class WebSocketClient extends EventEmitter {
|
|
891
|
+
#private;
|
|
892
|
+
get readyState(): WebSocketReadyState;
|
|
893
|
+
/**
|
|
894
|
+
* Open a WebSocket connection.
|
|
895
|
+
* @param url ws:// or wss:// URL
|
|
896
|
+
* @param headers Extra HTTP headers for the upgrade request
|
|
897
|
+
*/
|
|
898
|
+
connect(url: string, headers?: Record<string, string>): Promise<void>;
|
|
899
|
+
/**
|
|
900
|
+
* Send a text or binary message.
|
|
901
|
+
* @throws if the socket is not open.
|
|
902
|
+
*/
|
|
903
|
+
send(data: string | Buffer | Uint8Array): void;
|
|
904
|
+
/**
|
|
905
|
+
* Initiate a clean close handshake.
|
|
906
|
+
* @param code WebSocket close code (default 1000 = Normal Closure)
|
|
907
|
+
* @param reason UTF-8 reason string (max 123 bytes)
|
|
908
|
+
*/
|
|
909
|
+
close(code?: number, reason?: string): void;
|
|
910
|
+
}
|
|
911
|
+
//#endregion
|
|
912
|
+
export { AbortError, type AvailableTransport, type CancelInvocationMessage, type CloseMessage, type CompletionMessage, ConsoleLogger, CookieAgent, CookieJar, DEFAULT_PING_INTERVAL_IN_MS, DEFAULT_SERVER_TIMEOUT_IN_MS, DEFAULT_TIMEOUT_IN_MS, DefaultReconnectPolicy, DispatchHttpClient, DispatchHttpClient as HttpClient, type Dispatcher, FetchHttpClient, HANDSHAKE_REQUEST, HandshakeError, type HandshakeParseResult, type HandshakeResponse, type HttpClientOptions, type HttpMethod, type HttpResponse, HttpTransportType, HubConnection, HubConnectionBuilder, type HubConnectionOptions, HubConnectionState, HubError, type HubMessage, type IHttpClient, type IHubProtocol, type ILogger, type IRetryPolicy, type IStreamResult, type IStreamSubscriber, type ISubscription, type ITransport, type InvocationId, type InvocationMessage, JsonHubProtocol, LogLevel, LongPollingTransport, HANDSHAKE_REQUEST$1 as MSGPACK_HANDSHAKE_REQUEST, type MessageHeaders, MessageType, type MessageTypeValue, MsgpackHubProtocol, NEGOTIATE_VERSION, type NegotiateResponse, NullLogger, type PingMessage, PipelineHttpClient, RECORD_SEPARATOR, RequestHttpClient, type RequestOptions, type RetryContext, ServerSentEventsTransport, StreamHttpClient, type StreamInvocationMessage, type StreamItemMessage, type StreamResult, TransferFormat, TransportError, UnsupportedTransportError, type UrlOptions, WebSocketClient, WebSocketReadyState, WebSocketTransport, assertNever, cookie, isAbortError, isCancelInvocationMessage, isCloseMessage, isCompletionMessage, isHubError, isInvocationMessage, isPingMessage, isStreamInvocationMessage, isStreamItemMessage, isTransportError, parseHandshakeResponse, toInvocationId };
|
|
913
|
+
//# sourceMappingURL=index.d.mts.map
|