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