@orpc/client 2.0.0-beta.49 → 2.0.0-beta.50

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.
Files changed (75) hide show
  1. package/dist/adapters/fetch/index.d.ts +3 -2
  2. package/dist/adapters/fetch/index.js +2 -2
  3. package/dist/adapters/fetch/rpc-link.d.ts +8 -8
  4. package/dist/adapters/fetch/rpc-link.js +16 -13
  5. package/dist/adapters/fetch/transport.d.ts +29 -31
  6. package/dist/adapters/fetch/transport.js +49 -63
  7. package/dist/adapters/message-port/index.d.ts +4 -3
  8. package/dist/adapters/message-port/index.js +3 -3
  9. package/dist/adapters/message-port/message-port.d.ts +13 -13
  10. package/dist/adapters/message-port/message-port.js +35 -53
  11. package/dist/adapters/message-port/rpc-link.d.ts +8 -8
  12. package/dist/adapters/message-port/rpc-link.js +17 -14
  13. package/dist/adapters/message-port/transport.d.ts +31 -34
  14. package/dist/adapters/message-port/transport.js +38 -52
  15. package/dist/adapters/standard/codec.d.ts +10 -10
  16. package/dist/adapters/standard/index.d.ts +6 -5
  17. package/dist/adapters/standard/index.js +2 -4
  18. package/dist/adapters/standard/link.d.ts +31 -31
  19. package/dist/adapters/standard/link.js +101 -85
  20. package/dist/adapters/standard/plugin.d.ts +25 -31
  21. package/dist/adapters/standard/plugin.js +14 -16
  22. package/dist/adapters/standard/rpc-link-codec.d.ts +53 -60
  23. package/dist/adapters/standard/rpc-link-codec.js +98 -102
  24. package/dist/adapters/standard/transport.d.ts +7 -7
  25. package/dist/adapters/websocket/index.d.ts +3 -2
  26. package/dist/adapters/websocket/index.js +2 -2
  27. package/dist/adapters/websocket/rpc-link.d.ts +8 -8
  28. package/dist/adapters/websocket/rpc-link.js +16 -13
  29. package/dist/adapters/websocket/transport.d.ts +101 -100
  30. package/dist/adapters/websocket/transport.js +102 -130
  31. package/dist/async-iterator-object.d.ts +2 -2
  32. package/dist/async-iterator-object.js +27 -28
  33. package/dist/client-safe.d.ts +4 -6
  34. package/dist/client-safe.js +29 -34
  35. package/dist/client.d.ts +24 -26
  36. package/dist/client.js +35 -37
  37. package/dist/consts.d.ts +1 -1
  38. package/dist/consts.js +18 -41
  39. package/dist/dynamic-link.d.ts +6 -6
  40. package/dist/dynamic-link.js +16 -16
  41. package/dist/error-utils.d.ts +3 -4
  42. package/dist/error-utils.js +47 -51
  43. package/dist/error.d.ts +79 -79
  44. package/dist/error.js +154 -166
  45. package/dist/index.d.ts +14 -53
  46. package/dist/index.js +12 -40
  47. package/dist/plugins/batch.d.ts +122 -155
  48. package/dist/plugins/batch.js +320 -391
  49. package/dist/plugins/cookie-jar.d.ts +64 -61
  50. package/dist/plugins/cookie-jar.js +208 -245
  51. package/dist/plugins/dedupe.d.ts +49 -53
  52. package/dist/plugins/dedupe.js +168 -211
  53. package/dist/plugins/index.d.ts +9 -28
  54. package/dist/plugins/index.js +8 -23
  55. package/dist/plugins/request-compression.d.ts +38 -35
  56. package/dist/plugins/request-compression.js +131 -177
  57. package/dist/plugins/response-compression.d.ts +21 -18
  58. package/dist/plugins/response-compression.js +64 -88
  59. package/dist/plugins/retry-after.d.ts +31 -38
  60. package/dist/plugins/retry-after.js +60 -85
  61. package/dist/plugins/retry.d.ts +55 -55
  62. package/dist/plugins/retry.js +118 -137
  63. package/dist/plugins/timeout.d.ts +19 -17
  64. package/dist/plugins/timeout.js +41 -36
  65. package/dist/rpc-json-serializer.d.ts +84 -84
  66. package/dist/rpc-json-serializer.js +338 -383
  67. package/dist/rpc-serializer.d.ts +20 -21
  68. package/dist/rpc-serializer.js +97 -125
  69. package/dist/types.d.ts +19 -31
  70. package/dist/utils.d.ts +18 -29
  71. package/dist/utils.js +63 -47
  72. package/package.json +5 -5
  73. package/dist/adapters/standard/codec.js +0 -1
  74. package/dist/adapters/standard/transport.js +0 -1
  75. package/dist/types.js +0 -1
@@ -1,104 +1,100 @@
1
- import { isAsyncIteratorObject, pathToHttpPath, stringifyJSON, value } from '@orpc/shared';
2
- import { mergeStandardHeaders, parseStandardUrl } from '@standard-server/core';
3
- import { toStandardHeaders } from '@standard-server/fetch';
4
- import { createORPCErrorFromJson, isORPCErrorJson } from '../../error-utils.js';
5
- import { MalformedResponseError, ResponseError } from '../../error.js';
6
- import { RPCSerializer } from '../../rpc-serializer.js';
7
- const END_SLASH_REGEX = /\/$/;
8
- export class RPCLinkCodec {
9
- baseUrl;
10
- maxUrlLength;
11
- fallbackMethod;
12
- expectedMethod;
13
- headers;
14
- serializer;
15
- constructor(options) {
16
- this.baseUrl = options.url ?? '/';
17
- this.maxUrlLength = options.maxUrlLength ?? 2083;
18
- this.fallbackMethod = options.fallbackMethod ?? 'POST';
19
- this.expectedMethod = options.method ?? this.fallbackMethod;
20
- this.headers = options.headers ?? {};
21
- this.serializer = options.serializer ?? new RPCSerializer();
22
- }
23
- async encodeInput(input, path, options) {
24
- let headers = toResolvedStandardHeaders(await value(this.headers, options, path, input));
25
- if (options.lastEventId !== undefined) {
26
- headers = mergeStandardHeaders(headers, { 'last-event-id': options.lastEventId });
27
- }
28
- const expectedMethod = await value(this.expectedMethod, options, path, input);
29
- const baseUrl = await value(this.baseUrl, options, path, input);
30
- const [pathname, search, hash] = parseStandardUrl(baseUrl);
31
- const newPathname = `${pathname.replace(END_SLASH_REGEX, '')}${pathToHttpPath(path)}`;
32
- const serialized = this.serializer.serialize(input);
33
- if (expectedMethod === 'GET' &&
34
- !(serialized instanceof Blob) &&
35
- !(serialized instanceof ReadableStream) &&
36
- !(serialized instanceof FormData) &&
37
- !isAsyncIteratorObject(serialized)) {
38
- const maxUrlLength = await value(this.maxUrlLength, options, path, input);
39
- const mergedSearch = new URLSearchParams(search);
40
- mergedSearch.append('data', stringifyJSON(serialized) ?? '');
41
- const url = `${newPathname}?${mergedSearch}${hash ?? ''}`;
42
- if (url.length <= maxUrlLength) {
43
- return {
44
- body: undefined,
45
- method: expectedMethod,
46
- headers,
47
- url,
48
- signal: options.signal,
49
- };
50
- }
51
- }
52
- const url = `${newPathname}${search ?? ''}${hash ?? ''}`;
53
- return {
54
- url,
55
- method: expectedMethod === 'GET' ? this.fallbackMethod : expectedMethod,
56
- headers,
57
- body: serialized,
58
- signal: options.signal,
59
- };
60
- }
61
- async decodeResponse(response) {
62
- const isOk = response.status < 400;
63
- const body = await response.resolveBody();
64
- const deserialized = await (async () => {
65
- try {
66
- return this.serializer.deserialize(body);
67
- }
68
- catch (cause) {
69
- throw new MalformedResponseError({
70
- message: isOk ? 'Invalid RPC response format.' : undefined,
71
- response: { status: response.status, headers: response.headers, body },
72
- cause,
73
- });
74
- }
75
- })();
76
- if (!isOk) {
77
- if (isORPCErrorJson(deserialized)) {
78
- return {
79
- kind: 'error',
80
- error: createORPCErrorFromJson(deserialized, {
81
- cause: new ResponseError({
82
- response: { status: response.status, headers: response.headers, body },
83
- }),
84
- }),
85
- };
86
- }
87
- throw new MalformedResponseError({
88
- response: { headers: response.headers, status: response.status, body },
89
- });
90
- }
91
- return { kind: 'output', output: deserialized };
92
- }
93
- }
1
+ import { MalformedResponseError, ResponseError } from "../../error.js";
2
+ import { createORPCErrorFromJson, isORPCErrorJson } from "../../error-utils.js";
3
+ import { RPCSerializer } from "../../rpc-serializer.js";
4
+ import { isAsyncIteratorObject, mergeHttpPath, pathToHttpPath, stringifyJSON, value } from "@orpc/shared";
5
+ import { mergeStandardHeaders, parseStandardUrl } from "@standard-server/core";
6
+ import { toStandardHeaders } from "@standard-server/fetch";
7
+ // src/adapters/standard/rpc-link-codec.ts
8
+ var RPCLinkCodec = class {
9
+ baseUrl;
10
+ maxUrlLength;
11
+ fallbackMethod;
12
+ expectedMethod;
13
+ headers;
14
+ serializer;
15
+ constructor(options) {
16
+ this.baseUrl = options.url ?? "/";
17
+ this.maxUrlLength = options.maxUrlLength ?? 2083;
18
+ this.fallbackMethod = options.fallbackMethod ?? "POST";
19
+ this.expectedMethod = options.method ?? this.fallbackMethod;
20
+ this.headers = options.headers ?? {};
21
+ this.serializer = options.serializer ?? new RPCSerializer();
22
+ }
23
+ async encodeInput(input, path, options) {
24
+ let headers = toResolvedStandardHeaders(await value(this.headers, options, path, input));
25
+ if (options.lastEventId !== void 0) headers = mergeStandardHeaders(headers, { "last-event-id": options.lastEventId });
26
+ const expectedMethod = await value(this.expectedMethod, options, path, input);
27
+ const baseUrl = await value(this.baseUrl, options, path, input);
28
+ const [pathname, search, hash] = parseStandardUrl(baseUrl);
29
+ const newPathname = mergeHttpPath(pathname, pathToHttpPath(path));
30
+ const serialized = this.serializer.serialize(input);
31
+ if (expectedMethod === "GET" && !(serialized instanceof Blob) && !(serialized instanceof ReadableStream) && !(serialized instanceof FormData) && !isAsyncIteratorObject(serialized)) {
32
+ const maxUrlLength = await value(this.maxUrlLength, options, path, input);
33
+ const mergedSearch = new URLSearchParams(search);
34
+ mergedSearch.append("data", stringifyJSON(serialized) ?? "");
35
+ const url = `${newPathname}?${mergedSearch}${hash ?? ""}`;
36
+ if (url.length <= maxUrlLength) return {
37
+ body: void 0,
38
+ method: expectedMethod,
39
+ headers,
40
+ url,
41
+ signal: options.signal
42
+ };
43
+ }
44
+ return {
45
+ url: `${newPathname}${search ?? ""}${hash ?? ""}`,
46
+ method: expectedMethod === "GET" ? this.fallbackMethod : expectedMethod,
47
+ headers,
48
+ body: serialized,
49
+ signal: options.signal
50
+ };
51
+ }
52
+ async decodeResponse(response) {
53
+ const isOk = response.status < 400;
54
+ const body = await response.resolveBody();
55
+ const deserialized = await (async () => {
56
+ try {
57
+ return this.serializer.deserialize(body);
58
+ } catch (cause) {
59
+ throw new MalformedResponseError({
60
+ message: isOk ? "Invalid RPC response format." : void 0,
61
+ response: {
62
+ status: response.status,
63
+ headers: response.headers,
64
+ body
65
+ },
66
+ cause
67
+ });
68
+ }
69
+ })();
70
+ if (!isOk) {
71
+ if (isORPCErrorJson(deserialized)) return {
72
+ kind: "error",
73
+ error: createORPCErrorFromJson(deserialized, { cause: new ResponseError({ response: {
74
+ status: response.status,
75
+ headers: response.headers,
76
+ body
77
+ } }) })
78
+ };
79
+ throw new MalformedResponseError({ response: {
80
+ headers: response.headers,
81
+ status: response.status,
82
+ body
83
+ } });
84
+ }
85
+ return {
86
+ kind: "output",
87
+ output: deserialized
88
+ };
89
+ }
90
+ };
94
91
  function toResolvedStandardHeaders(headers) {
95
- /**
96
- * Headers class might not be available in some environments,
97
- * so we check for the existence of `forEach` and `get`
98
- * methods to determine if it's a Headers instance.
99
- */
100
- if (typeof headers.forEach === 'function') {
101
- return toStandardHeaders(headers);
102
- }
103
- return headers;
92
+ /**
93
+ * Headers class might not be available in some environments,
94
+ * so we check for the existence of `forEach` and `get`
95
+ * methods to determine if it's a Headers instance.
96
+ */
97
+ if (typeof headers.forEach === "function") return toStandardHeaders(headers);
98
+ return headers;
104
99
  }
100
+ export { RPCLinkCodec };
@@ -1,5 +1,5 @@
1
- import type { StandardLazyResponse, StandardRequest } from '@standard-server/core';
2
- import type { ClientContext, ClientOptions } from '../../types.ts';
1
+ import { ClientContext, ClientOptions } from "../../types.js";
2
+ import { StandardLazyResponse, StandardRequest } from "@standard-server/core";
3
3
  /**
4
4
  * Handles the transport layer for sending requests and receiving responses.
5
5
  *
@@ -7,8 +7,8 @@ import type { ClientContext, ClientOptions } from '../../types.ts';
7
7
  * such as HTTP fetch, WebSocket, or other transport mechanisms.
8
8
  */
9
9
  export interface StandardLinkTransport<T extends ClientContext> {
10
- /**
11
- * @throws Transport-level errors (network failures, timeouts, etc.)
12
- */
13
- send(request: StandardRequest, path: string[], options: ClientOptions<T>): Promise<StandardLazyResponse>;
14
- }
10
+ /**
11
+ * @throws Transport-level errors (network failures, timeouts, etc.)
12
+ */
13
+ send(request: StandardRequest, path: string[], options: ClientOptions<T>): Promise<StandardLazyResponse>;
14
+ }
@@ -1,2 +1,3 @@
1
- export * from './rpc-link.ts';
2
- export * from './transport.ts';
1
+ import { RPCLink, RPCLinkOptions } from "./rpc-link.js";
2
+ import { WebSocketLike, WebSocketLinkTransport, WebSocketLinkTransportAttemptInfo, WebSocketLinkTransportOptions, WebSocketLinkTransportReconnectOnCloseOptions, WebSocketLinkTransportReconnectOptions } from "./transport.js";
3
+ export { RPCLink, RPCLinkOptions, WebSocketLike, WebSocketLinkTransport, WebSocketLinkTransportAttemptInfo, WebSocketLinkTransportOptions, WebSocketLinkTransportReconnectOnCloseOptions, WebSocketLinkTransportReconnectOptions };
@@ -1,2 +1,2 @@
1
- export * from './rpc-link.js';
2
- export * from './transport.js';
1
+ export { RPCLink } from "./rpc-link.js";
2
+ export { WebSocketLinkTransport } from "./transport.js";
@@ -1,14 +1,14 @@
1
- import type { ClientContext } from '../../types.ts';
2
- import type { RPCLinkCodecOptions, StandardLinkOptions } from '../standard/index.ts';
3
- import { StandardLink } from '../standard/index.ts';
4
- import type { WebSocketLinkTransportOptions } from './transport.ts';
5
- export interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, WebSocketLinkTransportOptions<T>, RPCLinkCodecOptions<T> {
6
- }
1
+ import { ClientContext } from "../../types.js";
2
+ import { StandardLink, StandardLinkOptions } from "../standard/link.js";
3
+ import { RPCLinkCodecOptions } from "../standard/rpc-link-codec.js";
4
+ import "../standard/index.js";
5
+ import { WebSocketLinkTransportOptions } from "./transport.js";
6
+ export interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, WebSocketLinkTransportOptions<T>, RPCLinkCodecOptions<T> {}
7
7
  /**
8
8
  * Client link that communicates with an RPC Handler over a WebSocket connection.
9
9
  *
10
10
  * @see {@link https://orpc.dev/docs/adapters/websocket | WebSocket Adapters}
11
11
  */
12
12
  export declare class RPCLink<T extends ClientContext> extends StandardLink<T> {
13
- constructor(options: RPCLinkOptions<T>);
14
- }
13
+ constructor(options: RPCLinkOptions<T>);
14
+ }
@@ -1,14 +1,17 @@
1
- import { RPCLinkCodec, StandardLink } from '../standard/index.js';
2
- import { WebSocketLinkTransport } from './transport.js';
1
+ import { RPCLinkCodec } from "../standard/rpc-link-codec.js";
2
+ import { StandardLink } from "../standard/link.js";
3
+ import { WebSocketLinkTransport } from "./transport.js";
4
+ // src/adapters/websocket/rpc-link.ts
3
5
  /**
4
- * Client link that communicates with an RPC Handler over a WebSocket connection.
5
- *
6
- * @see {@link https://orpc.dev/docs/adapters/websocket | WebSocket Adapters}
7
- */
8
- export class RPCLink extends StandardLink {
9
- constructor(options) {
10
- const codec = new RPCLinkCodec(options);
11
- const transport = new WebSocketLinkTransport(options);
12
- super(codec, transport, options);
13
- }
14
- }
6
+ * Client link that communicates with an RPC Handler over a WebSocket connection.
7
+ *
8
+ * @see {@link https://orpc.dev/docs/adapters/websocket | WebSocket Adapters}
9
+ */
10
+ var RPCLink = class extends StandardLink {
11
+ constructor(options) {
12
+ const codec = new RPCLinkCodec(options);
13
+ const transport = new WebSocketLinkTransport(options);
14
+ super(codec, transport, options);
15
+ }
16
+ };
17
+ export { RPCLink };
@@ -1,115 +1,116 @@
1
- import type { Promisable } from '@orpc/shared';
2
- import type { StandardLazyResponse, StandardRequest } from '@standard-server/core';
3
- import type { DecodePeerMessageOptions, EncodePeerMessageOptions } from '@standard-server/peer';
4
- import type { ClientContext, ClientOptions } from '../../types.ts';
5
- import type { StandardLinkTransport } from '../standard/index.ts';
6
- export type WebSocketLike = Pick<WebSocket, 'addEventListener' | 'removeEventListener' | 'send' | 'readyState'>;
1
+ import { ClientContext, ClientOptions } from "../../types.js";
2
+ import { StandardLinkTransport } from "../standard/transport.js";
3
+ import "../standard/index.js";
4
+ import { Promisable } from "@orpc/shared";
5
+ import { StandardLazyResponse, StandardRequest } from "@standard-server/core";
6
+ import { DecodePeerMessageOptions, EncodePeerMessageOptions } from "@standard-server/peer";
7
+ export type WebSocketLike = Pick<WebSocket, "addEventListener" | "removeEventListener" | "send" | "readyState">;
7
8
  export interface WebSocketLinkTransportAttemptInfo {
8
- /**
9
- * Total number of connection attempts for this transport's lifetime.
10
- * Starts at 1 on the first attempt, increments on every subsequent
11
- * attempt, and never resets.
12
- */
13
- totalAttempt: number;
14
- /**
15
- * Attempt number within the current (re)connect cycle.
16
- * Starts at 1, increments on each consecutive failure, and resets to 1
17
- * once a connection succeeds or the cycle gives up. Use this for backoff calculations.
18
- */
19
- attempt: number;
9
+ /**
10
+ * Total number of connection attempts for this transport's lifetime.
11
+ * Starts at 1 on the first attempt, increments on every subsequent
12
+ * attempt, and never resets.
13
+ */
14
+ totalAttempt: number;
15
+ /**
16
+ * Attempt number within the current (re)connect cycle.
17
+ * Starts at 1, increments on each consecutive failure, and resets to 1
18
+ * once a connection succeeds or the cycle gives up. Use this for backoff calculations.
19
+ */
20
+ attempt: number;
20
21
  }
21
22
  /**
22
23
  * Reconnection behavior when the connection is lost. Passing it enables reconnection.
23
24
  */
24
25
  export interface WebSocketLinkTransportReconnectOptions {
25
- /**
26
- * Delay before a (re)connect attempt, in milliseconds.
27
- *
28
- * @default info => info.attempt === 1 ? 0 : 2_000
29
- */
30
- delay?: ((info: WebSocketLinkTransportAttemptInfo) => number) | undefined;
31
- /**
32
- * Maximum number of consecutive failed attempts before giving up.
33
- * When reached, calls waiting for the connection fail, and the next
34
- * call starts a new reconnect cycle.
35
- * Should greater than 1
36
- *
37
- * @default Infinity
38
- */
39
- maxAttempt?: number | undefined;
40
- /**
41
- * Maximum number of connection attempts over the transport's lifetime,
42
- * successful ones included (see `totalAttempt`).
43
- * When reached, calls that need a new connection fail instead of connecting.
44
- *
45
- * @default Infinity
46
- */
47
- maxTotalAttempt?: number | undefined;
48
- /**
49
- * Whether to proactively reconnect right after the socket closes,
50
- * rather than waiting for the next call to trigger reconnection.
51
- * Reduces latency for the next request.
52
- *
53
- * `true` enables it, {@link WebSocketLinkTransportReconnectOnCloseOptions} enables and customizes it.
54
- *
55
- * @default false
56
- */
57
- onClose?: boolean | WebSocketLinkTransportReconnectOnCloseOptions | undefined;
26
+ /**
27
+ * Delay before a (re)connect attempt, in milliseconds.
28
+ *
29
+ * @default info => info.attempt === 1 ? 0 : 2_000
30
+ */
31
+ delay?: ((info: WebSocketLinkTransportAttemptInfo) => number) | undefined;
32
+ /**
33
+ * Maximum number of consecutive failed attempts before giving up.
34
+ * When reached, calls waiting for the connection fail, and the next
35
+ * call starts a new reconnect cycle.
36
+ * Should greater than 1
37
+ *
38
+ * @default Infinity
39
+ */
40
+ maxAttempt?: number | undefined;
41
+ /**
42
+ * Maximum number of connection attempts over the transport's lifetime,
43
+ * successful ones included (see `totalAttempt`).
44
+ * When reached, calls that need a new connection fail instead of connecting.
45
+ *
46
+ * @default Infinity
47
+ */
48
+ maxTotalAttempt?: number | undefined;
49
+ /**
50
+ * Whether to proactively reconnect right after the socket closes,
51
+ * rather than waiting for the next call to trigger reconnection.
52
+ * Reduces latency for the next request.
53
+ *
54
+ * `true` enables it, {@link WebSocketLinkTransportReconnectOnCloseOptions} enables and customizes it.
55
+ *
56
+ * @default false
57
+ */
58
+ onClose?: boolean | WebSocketLinkTransportReconnectOnCloseOptions | undefined;
58
59
  }
59
60
  /**
60
61
  * Proactive reconnection right after the socket closes. Passing it enables it.
61
62
  */
62
63
  export interface WebSocketLinkTransportReconnectOnCloseOptions {
63
- /**
64
- * Delay before reconnecting after the socket closes, in milliseconds.
65
- *
66
- * @default 0
67
- */
68
- delay?: number | undefined;
64
+ /**
65
+ * Delay before reconnecting after the socket closes, in milliseconds.
66
+ *
67
+ * @default 0
68
+ */
69
+ delay?: number | undefined;
69
70
  }
70
71
  export interface WebSocketLinkTransportOptions<_T extends ClientContext> {
71
- /**
72
- * Returns a WebSocket instance for peer communication.
73
- * Can be async for lazy resolution.
74
- */
75
- connect: (info: WebSocketLinkTransportAttemptInfo) => Promisable<WebSocketLike>;
76
- /**
77
- * Whether to connect immediately on initialization, instead of waiting
78
- * for the first call. Reduces latency for the first request.
79
- *
80
- * @default false
81
- */
82
- connectOnInit?: boolean | undefined;
83
- /**
84
- * Reconnection when the connection is lost. `true` enables it,
85
- * {@link WebSocketLinkTransportReconnectOptions} enables and customizes it.
86
- *
87
- * @default false
88
- */
89
- reconnect?: boolean | WebSocketLinkTransportReconnectOptions | undefined;
90
- /**
91
- * Options for encoding peer messages. such as `prefix` for distinguishing messages on the same channel..
92
- */
93
- encodePeerMessage?: EncodePeerMessageOptions | undefined;
94
- /**
95
- * Options for decoding peer messages. such as `prefix` for distinguishing messages on the same channel..
96
- */
97
- decodePeerMessage?: DecodePeerMessageOptions | undefined;
72
+ /**
73
+ * Returns a WebSocket instance for peer communication.
74
+ * Can be async for lazy resolution.
75
+ */
76
+ connect: (info: WebSocketLinkTransportAttemptInfo) => Promisable<WebSocketLike>;
77
+ /**
78
+ * Whether to connect immediately on initialization, instead of waiting
79
+ * for the first call. Reduces latency for the first request.
80
+ *
81
+ * @default false
82
+ */
83
+ connectOnInit?: boolean | undefined;
84
+ /**
85
+ * Reconnection when the connection is lost. `true` enables it,
86
+ * {@link WebSocketLinkTransportReconnectOptions} enables and customizes it.
87
+ *
88
+ * @default false
89
+ */
90
+ reconnect?: boolean | WebSocketLinkTransportReconnectOptions | undefined;
91
+ /**
92
+ * Options for encoding peer messages. such as `prefix` for distinguishing messages on the same channel..
93
+ */
94
+ encodePeerMessage?: EncodePeerMessageOptions | undefined;
95
+ /**
96
+ * Options for decoding peer messages. such as `prefix` for distinguishing messages on the same channel..
97
+ */
98
+ decodePeerMessage?: DecodePeerMessageOptions | undefined;
98
99
  }
99
100
  export declare class WebSocketLinkTransport<T extends ClientContext> implements StandardLinkTransport<T> {
100
- private readonly connect;
101
- private readonly reconnectEnabled;
102
- private readonly reconnectDelay;
103
- private readonly reconnectMaxAttempt;
104
- private readonly reconnectMaxTotalAttempt;
105
- private readonly reconnectOnCloseEnabled;
106
- private readonly reconnectOnCloseDelay;
107
- private readonly encodePeerMessageOptions;
108
- private readonly decodePeerMessageOptions;
109
- constructor(options: WebSocketLinkTransportOptions<T>);
110
- send(standardRequest: StandardRequest, _path: string[], _options: ClientOptions<T>): Promise<StandardLazyResponse>;
111
- private totalAttempt;
112
- private attempt;
113
- private current;
114
- private getConnectedPeer;
115
- }
101
+ private readonly connect;
102
+ private readonly reconnectEnabled;
103
+ private readonly reconnectDelay;
104
+ private readonly reconnectMaxAttempt;
105
+ private readonly reconnectMaxTotalAttempt;
106
+ private readonly reconnectOnCloseEnabled;
107
+ private readonly reconnectOnCloseDelay;
108
+ private readonly encodePeerMessageOptions;
109
+ private readonly decodePeerMessageOptions;
110
+ constructor(options: WebSocketLinkTransportOptions<T>);
111
+ send(standardRequest: StandardRequest, _path: string[], _options: ClientOptions<T>): Promise<StandardLazyResponse>;
112
+ private totalAttempt;
113
+ private attempt;
114
+ private current;
115
+ private getConnectedPeer;
116
+ }