@orpc/client 2.0.0-beta.4 → 2.0.0-beta.41

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 (30) hide show
  1. package/README.md +97 -94
  2. package/dist/adapters/fetch/index.d.mts +16 -33
  3. package/dist/adapters/fetch/index.d.ts +16 -33
  4. package/dist/adapters/fetch/index.mjs +33 -30
  5. package/dist/adapters/message-port/index.d.mts +13 -8
  6. package/dist/adapters/message-port/index.d.ts +13 -8
  7. package/dist/adapters/message-port/index.mjs +27 -17
  8. package/dist/adapters/standard/index.d.mts +9 -10
  9. package/dist/adapters/standard/index.d.ts +9 -10
  10. package/dist/adapters/standard/index.mjs +5 -5
  11. package/dist/adapters/websocket/index.d.mts +33 -18
  12. package/dist/adapters/websocket/index.d.ts +33 -18
  13. package/dist/adapters/websocket/index.mjs +45 -24
  14. package/dist/index.d.mts +62 -61
  15. package/dist/index.d.ts +62 -61
  16. package/dist/index.mjs +47 -54
  17. package/dist/plugins/index.d.mts +174 -13
  18. package/dist/plugins/index.d.ts +174 -13
  19. package/dist/plugins/index.mjs +580 -198
  20. package/dist/shared/{client.BdItY5DT.d.mts → client.BPa_Mmuh.d.mts} +25 -4
  21. package/dist/shared/{client.BdItY5DT.d.ts → client.BPa_Mmuh.d.ts} +25 -4
  22. package/dist/shared/{client.Cby_-GGh.d.mts → client.BjbdW5Rj.d.mts} +2 -2
  23. package/dist/shared/{client.DXhchJ84.mjs → client.Bstqyaro.mjs} +25 -30
  24. package/dist/shared/{client.Dnfj8jnT.mjs → client.DD2eNne_.mjs} +20 -15
  25. package/dist/shared/{client.CPF3hX6O.d.ts → client.DiHfJmHK.d.ts} +2 -2
  26. package/dist/shared/client.DpkGsZt-.mjs +486 -0
  27. package/dist/shared/{client.8ug8I-zu.d.mts → client.Dw9_40WO.d.mts} +57 -16
  28. package/dist/shared/{client.8ug8I-zu.d.ts → client.Dw9_40WO.d.ts} +57 -16
  29. package/package.json +22 -8
  30. package/dist/shared/client.DMXKFDyV.mjs +0 -343
@@ -1,37 +1,37 @@
1
- import { sortPlugins, value, intercept } from '@orpc/shared';
2
- import { toFetchBody, toFetchHeaders, toStandardLazyResponse } from '@standardserver/fetch';
3
- import { S as StandardLink, R as RPCLinkCodec } from '../../shared/client.DXhchJ84.mjs';
4
- import '@standardserver/core';
5
- import '../../shared/client.Dnfj8jnT.mjs';
6
- import '../../shared/client.DMXKFDyV.mjs';
1
+ import { value, once } from '@orpc/shared';
2
+ import { toFetchBody, toFetchHeaders, toStandardLazyResponse } from '@standard-server/fetch';
3
+ import { S as StandardLink, R as RPCLinkCodec } from '../../shared/client.Bstqyaro.mjs';
4
+ import '@standard-server/core';
5
+ import '../../shared/client.DpkGsZt-.mjs';
6
+ import '../../shared/client.DD2eNne_.mjs';
7
7
 
8
- class CompositeFetchLinkTransportPlugin {
9
- constructor(plugins = []) {
10
- this.plugins = plugins;
11
- this.plugins = sortPlugins(plugins);
12
- }
13
- name = "~composite/fetch-link-transport";
14
- initFetchLinkTransportOptions(options) {
15
- for (const plugin of this.plugins) {
16
- if (plugin.initFetchLinkTransportOptions) {
17
- options = plugin.initFetchLinkTransportOptions(options);
8
+ const GET_SUPPORTED_DUPLEX_MODE = once(() => {
9
+ try {
10
+ let duplex;
11
+ void new Request(
12
+ "https://example.com",
13
+ {
14
+ method: "POST",
15
+ body: new ReadableStream(),
16
+ get duplex() {
17
+ duplex = "half";
18
+ return "half";
19
+ }
18
20
  }
19
- }
20
- return options;
21
+ );
22
+ return duplex;
23
+ } catch {
24
+ return void 0;
21
25
  }
22
- }
23
-
26
+ });
24
27
  class FetchLinkTransport {
25
28
  origin;
26
29
  fetch;
27
30
  toFetchRequestOptions;
28
- fetchInterceptors;
29
31
  constructor(options) {
30
- options = new CompositeFetchLinkTransportPlugin(options.plugins).initFetchLinkTransportOptions(options);
31
32
  this.origin = options.origin;
32
- this.fetch = options.fetch ?? globalThis.fetch.bind(globalThis);
33
+ this.fetch = options.fetch ?? ((url, init) => globalThis.fetch(url, init));
33
34
  this.toFetchRequestOptions = options.toFetchRequest;
34
- this.fetchInterceptors = options.fetchInterceptors;
35
35
  }
36
36
  async send(standardRequest, path, options) {
37
37
  let origin = await value(this.origin, options, path);
@@ -47,11 +47,14 @@ class FetchLinkTransport {
47
47
  signal: options.signal,
48
48
  redirect: "manual"
49
49
  };
50
- const response = await intercept(
51
- this.fetchInterceptors,
52
- { ...options, url, path, init },
53
- ({ url: url2, path: path2, init: init2, ...options2 }) => this.fetch(url2, init2, options2, path2)
54
- );
50
+ if (body instanceof ReadableStream) {
51
+ const duplex = GET_SUPPORTED_DUPLEX_MODE();
52
+ if (duplex !== void 0) {
53
+ init.duplex = duplex;
54
+ }
55
+ }
56
+ const fetch = this.fetch;
57
+ const response = await fetch(url, init, options, path);
55
58
  const standardResponse = toStandardLazyResponse(response);
56
59
  return standardResponse;
57
60
  }
@@ -65,4 +68,4 @@ class RPCLink extends StandardLink {
65
68
  }
66
69
  }
67
70
 
68
- export { CompositeFetchLinkTransportPlugin, FetchLinkTransport, RPCLink };
71
+ export { FetchLinkTransport, RPCLink };
@@ -1,10 +1,10 @@
1
- import { C as ClientContext, a as ClientOptions } from '../../shared/client.8ug8I-zu.mjs';
1
+ import { ClientContext, ClientOptions } from '../../index.mjs';
2
2
  import { Value, Promisable } from '@orpc/shared';
3
- import { StandardRequest, StandardLazyResponse } from '@standardserver/core';
4
- import { ClientPeer, EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standardserver/peer';
5
- import { S as StandardLinkTransport, a as StandardLink, b as StandardLinkOptions } from '../../shared/client.Cby_-GGh.mjs';
3
+ import { StandardRequest, StandardLazyResponse } from '@standard-server/core';
4
+ import { ClientPeer, EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standard-server/peer';
5
+ import { StandardLinkTransport, StandardLink, StandardLinkOptions } from '../standard/index.mjs';
6
6
  import { RPCLinkCodecOptions } from '../standard/index.mjs';
7
- import '../../shared/client.BdItY5DT.mjs';
7
+ import '../../shared/client.BPa_Mmuh.mjs';
8
8
 
9
9
  /**
10
10
  * The message port used by electron in main process
@@ -45,9 +45,8 @@ interface MessagePortLinkTransportOptions<_T extends ClientContext> {
45
45
  * such as transferring ownership of objects to the other side or support unserializable objects like `OffscreenCanvas`.
46
46
  *
47
47
  * @remarks
48
- * - return null | undefined to disable this feature
49
- *
50
- * @warning Make sure your message port supports `transfer` before using this feature.
48
+ * **Note**: Returning `null` or `undefined` disables this feature.
49
+ * **Warning**: Make sure your message port supports `transfer` before using this feature.
51
50
  */
52
51
  experimental_transfer?: Value<Promisable<object[] | null | undefined>, [message: DecodedRequestMessage, port: SupportedMessagePort]>;
53
52
  /**
@@ -67,6 +66,12 @@ declare class MessagePortLinkTransport<T extends ClientContext> implements Stand
67
66
 
68
67
  interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, MessagePortLinkTransportOptions<T>, RPCLinkCodecOptions<T> {
69
68
  }
69
+ /**
70
+ * Client link that communicates with an RPC Handler over a Message Port
71
+ * (e.g. workers, iframes, browser extensions, Electron).
72
+ *
73
+ * @see {@link https://orpc.dev/docs/adapters/message-port | Message Port Adapter}
74
+ */
70
75
  declare class RPCLink<T extends ClientContext> extends StandardLink<T> {
71
76
  constructor(options: RPCLinkOptions<T>);
72
77
  }
@@ -1,10 +1,10 @@
1
- import { C as ClientContext, a as ClientOptions } from '../../shared/client.8ug8I-zu.js';
1
+ import { ClientContext, ClientOptions } from '../../index.js';
2
2
  import { Value, Promisable } from '@orpc/shared';
3
- import { StandardRequest, StandardLazyResponse } from '@standardserver/core';
4
- import { ClientPeer, EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standardserver/peer';
5
- import { S as StandardLinkTransport, a as StandardLink, b as StandardLinkOptions } from '../../shared/client.CPF3hX6O.js';
3
+ import { StandardRequest, StandardLazyResponse } from '@standard-server/core';
4
+ import { ClientPeer, EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standard-server/peer';
5
+ import { StandardLinkTransport, StandardLink, StandardLinkOptions } from '../standard/index.js';
6
6
  import { RPCLinkCodecOptions } from '../standard/index.js';
7
- import '../../shared/client.BdItY5DT.js';
7
+ import '../../shared/client.BPa_Mmuh.js';
8
8
 
9
9
  /**
10
10
  * The message port used by electron in main process
@@ -45,9 +45,8 @@ interface MessagePortLinkTransportOptions<_T extends ClientContext> {
45
45
  * such as transferring ownership of objects to the other side or support unserializable objects like `OffscreenCanvas`.
46
46
  *
47
47
  * @remarks
48
- * - return null | undefined to disable this feature
49
- *
50
- * @warning Make sure your message port supports `transfer` before using this feature.
48
+ * **Note**: Returning `null` or `undefined` disables this feature.
49
+ * **Warning**: Make sure your message port supports `transfer` before using this feature.
51
50
  */
52
51
  experimental_transfer?: Value<Promisable<object[] | null | undefined>, [message: DecodedRequestMessage, port: SupportedMessagePort]>;
53
52
  /**
@@ -67,6 +66,12 @@ declare class MessagePortLinkTransport<T extends ClientContext> implements Stand
67
66
 
68
67
  interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, MessagePortLinkTransportOptions<T>, RPCLinkCodecOptions<T> {
69
68
  }
69
+ /**
70
+ * Client link that communicates with an RPC Handler over a Message Port
71
+ * (e.g. workers, iframes, browser extensions, Electron).
72
+ *
73
+ * @see {@link https://orpc.dev/docs/adapters/message-port | Message Port Adapter}
74
+ */
70
75
  declare class RPCLink<T extends ClientContext> extends StandardLink<T> {
71
76
  constructor(options: RPCLinkOptions<T>);
72
77
  }
@@ -1,10 +1,10 @@
1
- import { value, isPlainObject, toStringOrBytes } from '@orpc/shared';
2
- import { ClientPeer, encodePeerMessage, decodePeerMessage, isServerPeerSendMessage } from '@standardserver/peer';
3
- import { S as StandardLink, R as RPCLinkCodec } from '../../shared/client.DXhchJ84.mjs';
4
- import '@standardserver/core';
5
- import '@standardserver/fetch';
6
- import '../../shared/client.Dnfj8jnT.mjs';
7
- import '../../shared/client.DMXKFDyV.mjs';
1
+ import { value, AbortError } from '@orpc/shared';
2
+ import { ClientPeer, encodePeerMessage, decodePeerMessage, isServerPeerSendMessage, isPeerMessage } from '@standard-server/peer';
3
+ import { S as StandardLink, R as RPCLinkCodec } from '../../shared/client.Bstqyaro.mjs';
4
+ import '@standard-server/core';
5
+ import '@standard-server/fetch';
6
+ import '../../shared/client.DpkGsZt-.mjs';
7
+ import '../../shared/client.DD2eNne_.mjs';
8
8
 
9
9
  function postMessagePortMessage(port, data, transfer) {
10
10
  if (transfer) {
@@ -51,7 +51,11 @@ function onMessagePortClose(port, callback) {
51
51
  class MessagePortLinkTransport {
52
52
  peer;
53
53
  constructor({ port, experimental_transfer, encodePeerMessage: encodePeerMessageOptions, decodePeerMessage: decodePeerMessageOptions }) {
54
+ let closeReason;
54
55
  this.peer = new ClientPeer(async (message) => {
56
+ if (closeReason) {
57
+ throw closeReason;
58
+ }
55
59
  const transfer = await value(experimental_transfer, message, port);
56
60
  if (transfer) {
57
61
  postMessagePortMessage(port, message, transfer);
@@ -59,19 +63,25 @@ class MessagePortLinkTransport {
59
63
  postMessagePortMessage(port, await encodePeerMessage(message, encodePeerMessageOptions));
60
64
  }
61
65
  });
62
- onMessagePortMessage(port, async (message) => {
63
- if (isPlainObject(message)) {
64
- await this.peer.message(message);
65
- return;
66
+ onMessagePortMessage(port, async (data) => {
67
+ let peerMessage;
68
+ if (typeof data === "string" || data instanceof Uint8Array) {
69
+ const result = decodePeerMessage(data, decodePeerMessageOptions);
70
+ if (result.matched && isServerPeerSendMessage(result.message)) {
71
+ peerMessage = result.message;
72
+ }
73
+ } else if (isPeerMessage(data) && isServerPeerSendMessage(data)) {
74
+ peerMessage = data;
66
75
  }
67
- const encodedMessage = await toStringOrBytes(message);
68
- const result = decodePeerMessage(encodedMessage, decodePeerMessageOptions);
69
- if (result.matched && isServerPeerSendMessage(result.message)) {
70
- await this.peer.message(result.message);
76
+ if (peerMessage === void 0) {
77
+ return { matched: false };
71
78
  }
79
+ await this.peer.message(peerMessage);
80
+ return { matched: true };
72
81
  });
73
- onMessagePortClose(port, () => {
74
- this.peer.close();
82
+ onMessagePortClose(port, async () => {
83
+ closeReason = new AbortError("MessagePort closed");
84
+ await this.peer.close(closeReason);
75
85
  });
76
86
  }
77
87
  async send(standardRequest, _path, _options) {
@@ -1,10 +1,9 @@
1
- import { f as StandardLinkCodec, g as StandardLinkCodecDecodedResponse } from '../../shared/client.Cby_-GGh.mjs';
2
- export { C as CompositeStandardLinkPlugin, a as StandardLink, h as StandardLinkInterceptor, e as StandardLinkInterceptorOptions, b as StandardLinkOptions, c as StandardLinkPlugin, S as StandardLinkTransport, i as StandardLinkTransportInterceptor, d as StandardLinkTransportInterceptorOptions } from '../../shared/client.Cby_-GGh.mjs';
3
- import { Value, Promisable } from '@orpc/shared';
4
- import { StandardUrl, StandardHeaders, StandardRequest, StandardLazyResponse } from '@standardserver/core';
5
- export { StandardBody, StandardBodyHint, StandardHeaders, StandardLazyRequest, StandardLazyResponse, StandardMethod, StandardRequest, StandardResponse, StandardUrl } from '@standardserver/core';
6
- import { C as ClientContext, a as ClientOptions } from '../../shared/client.8ug8I-zu.mjs';
7
- import { e as RPCSerializer } from '../../shared/client.BdItY5DT.mjs';
1
+ import { f as StandardLinkCodec, g as StandardLinkCodecDecodedResponse } from '../../shared/client.BjbdW5Rj.mjs';
2
+ export { C as CompositeStandardLinkPlugin, a as StandardLink, h as StandardLinkInterceptor, e as StandardLinkInterceptorOptions, b as StandardLinkOptions, c as StandardLinkPlugin, S as StandardLinkTransport, i as StandardLinkTransportInterceptor, d as StandardLinkTransportInterceptorOptions } from '../../shared/client.BjbdW5Rj.mjs';
3
+ import { Value, Promisable, Public } from '@orpc/shared';
4
+ import { StandardUrl, StandardHeaders, StandardRequest, StandardLazyResponse } from '@standard-server/core';
5
+ import { ClientContext, ClientOptions } from '../../index.mjs';
6
+ import { RPCSerializer } from '../../index.mjs';
8
7
 
9
8
  interface RPCLinkCodecOptions<T extends ClientContext> {
10
9
  /**
@@ -28,14 +27,14 @@ interface RPCLinkCodecOptions<T extends ClientContext> {
28
27
  *
29
28
  * @default 'POST'
30
29
  */
31
- method?: Value<Promisable<'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'>, [options: ClientOptions<T>, path: string[], input: unknown]>;
30
+ method?: Value<Promisable<'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'QUERY'>, [options: ClientOptions<T>, path: string[], input: unknown]>;
32
31
  /**
33
32
  * The method to use when the payload cannot safely pass to the server with method return from method function.
34
33
  * GET is not allowed, it's very dangerous.
35
34
  *
36
35
  * @default 'POST'
37
36
  */
38
- fallbackMethod?: 'POST' | 'PUT' | 'PATCH' | 'DELETE';
37
+ fallbackMethod?: 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'QUERY';
39
38
  /**
40
39
  * Inject headers to the request.
41
40
  */
@@ -43,7 +42,7 @@ interface RPCLinkCodecOptions<T extends ClientContext> {
43
42
  /**
44
43
  * Override the default RPC serializer.
45
44
  */
46
- serializer?: Pick<RPCSerializer, keyof RPCSerializer>;
45
+ serializer?: Public<RPCSerializer>;
47
46
  }
48
47
  declare class RPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
49
48
  private readonly baseUrl;
@@ -1,10 +1,9 @@
1
- import { f as StandardLinkCodec, g as StandardLinkCodecDecodedResponse } from '../../shared/client.CPF3hX6O.js';
2
- export { C as CompositeStandardLinkPlugin, a as StandardLink, h as StandardLinkInterceptor, e as StandardLinkInterceptorOptions, b as StandardLinkOptions, c as StandardLinkPlugin, S as StandardLinkTransport, i as StandardLinkTransportInterceptor, d as StandardLinkTransportInterceptorOptions } from '../../shared/client.CPF3hX6O.js';
3
- import { Value, Promisable } from '@orpc/shared';
4
- import { StandardUrl, StandardHeaders, StandardRequest, StandardLazyResponse } from '@standardserver/core';
5
- export { StandardBody, StandardBodyHint, StandardHeaders, StandardLazyRequest, StandardLazyResponse, StandardMethod, StandardRequest, StandardResponse, StandardUrl } from '@standardserver/core';
6
- import { C as ClientContext, a as ClientOptions } from '../../shared/client.8ug8I-zu.js';
7
- import { e as RPCSerializer } from '../../shared/client.BdItY5DT.js';
1
+ import { f as StandardLinkCodec, g as StandardLinkCodecDecodedResponse } from '../../shared/client.DiHfJmHK.js';
2
+ export { C as CompositeStandardLinkPlugin, a as StandardLink, h as StandardLinkInterceptor, e as StandardLinkInterceptorOptions, b as StandardLinkOptions, c as StandardLinkPlugin, S as StandardLinkTransport, i as StandardLinkTransportInterceptor, d as StandardLinkTransportInterceptorOptions } from '../../shared/client.DiHfJmHK.js';
3
+ import { Value, Promisable, Public } from '@orpc/shared';
4
+ import { StandardUrl, StandardHeaders, StandardRequest, StandardLazyResponse } from '@standard-server/core';
5
+ import { ClientContext, ClientOptions } from '../../index.js';
6
+ import { RPCSerializer } from '../../index.js';
8
7
 
9
8
  interface RPCLinkCodecOptions<T extends ClientContext> {
10
9
  /**
@@ -28,14 +27,14 @@ interface RPCLinkCodecOptions<T extends ClientContext> {
28
27
  *
29
28
  * @default 'POST'
30
29
  */
31
- method?: Value<Promisable<'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'>, [options: ClientOptions<T>, path: string[], input: unknown]>;
30
+ method?: Value<Promisable<'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'QUERY'>, [options: ClientOptions<T>, path: string[], input: unknown]>;
32
31
  /**
33
32
  * The method to use when the payload cannot safely pass to the server with method return from method function.
34
33
  * GET is not allowed, it's very dangerous.
35
34
  *
36
35
  * @default 'POST'
37
36
  */
38
- fallbackMethod?: 'POST' | 'PUT' | 'PATCH' | 'DELETE';
37
+ fallbackMethod?: 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'QUERY';
39
38
  /**
40
39
  * Inject headers to the request.
41
40
  */
@@ -43,7 +42,7 @@ interface RPCLinkCodecOptions<T extends ClientContext> {
43
42
  /**
44
43
  * Override the default RPC serializer.
45
44
  */
46
- serializer?: Pick<RPCSerializer, keyof RPCSerializer>;
45
+ serializer?: Public<RPCSerializer>;
47
46
  }
48
47
  declare class RPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
49
48
  private readonly baseUrl;
@@ -1,6 +1,6 @@
1
- export { C as CompositeStandardLinkPlugin, R as RPCLinkCodec, S as StandardLink } from '../../shared/client.DXhchJ84.mjs';
1
+ export { C as CompositeStandardLinkPlugin, R as RPCLinkCodec, S as StandardLink } from '../../shared/client.Bstqyaro.mjs';
2
2
  import '@orpc/shared';
3
- import '@standardserver/core';
4
- import '@standardserver/fetch';
5
- import '../../shared/client.Dnfj8jnT.mjs';
6
- import '../../shared/client.DMXKFDyV.mjs';
3
+ import '@standard-server/core';
4
+ import '@standard-server/fetch';
5
+ import '../../shared/client.DpkGsZt-.mjs';
6
+ import '../../shared/client.DD2eNne_.mjs';
@@ -1,13 +1,13 @@
1
- import { C as ClientContext, a as ClientOptions } from '../../shared/client.8ug8I-zu.mjs';
1
+ import { ClientContext, ClientOptions } from '../../index.mjs';
2
2
  import { Promisable } from '@orpc/shared';
3
- import { StandardRequest, StandardLazyResponse } from '@standardserver/core';
4
- import { EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standardserver/peer';
5
- import { S as StandardLinkTransport, a as StandardLink, b as StandardLinkOptions } from '../../shared/client.Cby_-GGh.mjs';
3
+ import { StandardRequest, StandardLazyResponse } from '@standard-server/core';
4
+ import { EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standard-server/peer';
5
+ import { StandardLinkTransport, StandardLink, StandardLinkOptions } from '../standard/index.mjs';
6
6
  import { RPCLinkCodecOptions } from '../standard/index.mjs';
7
- import '../../shared/client.BdItY5DT.mjs';
7
+ import '../../shared/client.BPa_Mmuh.mjs';
8
8
 
9
9
  type WebSocketLike = Pick<WebSocket, 'addEventListener' | 'removeEventListener' | 'send' | 'readyState'>;
10
- interface WebsocketLinkTransportAttemptInfo {
10
+ interface WebSocketLinkTransportAttemptInfo {
11
11
  /**
12
12
  * Total number of connection attempts for this transport's lifetime.
13
13
  * Starts at 1 on the first attempt, increments on every subsequent
@@ -17,11 +17,11 @@ interface WebsocketLinkTransportAttemptInfo {
17
17
  /**
18
18
  * Attempt number within the current (re)connect cycle.
19
19
  * Starts at 1, increments on each consecutive failure, and resets to 1
20
- * once a connection succeeds. Use this for backoff calculations.
20
+ * once a connection succeeds or the cycle gives up. Use this for backoff calculations.
21
21
  */
22
22
  attempt: number;
23
23
  }
24
- interface WebsocketLinkTransportReconnectOptions {
24
+ interface WebSocketLinkTransportReconnectOptions {
25
25
  /**
26
26
  * Whether to automatically reconnect when the connection is lost.
27
27
  *
@@ -33,15 +33,24 @@ interface WebsocketLinkTransportReconnectOptions {
33
33
  *
34
34
  * @default info => info.attempt === 1 ? 0 : 2_000
35
35
  */
36
- delay?: undefined | ((info: WebsocketLinkTransportAttemptInfo) => number);
36
+ delay?: undefined | ((info: WebSocketLinkTransportAttemptInfo) => number);
37
37
  /**
38
38
  * Maximum number of consecutive failed attempts before giving up.
39
- * When exceeded, `getConnectedPeer` throws instead of retrying.
39
+ * When reached, calls waiting for the connection fail, and the next
40
+ * call starts a new reconnect cycle.
40
41
  * Should greater than 1
41
42
  *
42
43
  * @default Infinity
43
44
  */
44
45
  maxAttempt?: undefined | number;
46
+ /**
47
+ * Maximum number of connection attempts over the transport's lifetime,
48
+ * successful ones included (see `totalAttempt`).
49
+ * When reached, calls that need a new connection fail instead of connecting.
50
+ *
51
+ * @default Infinity
52
+ */
53
+ maxTotalAttempt?: undefined | number;
45
54
  /**
46
55
  * Whether to proactively reconnect right after the socket closes,
47
56
  * rather than waiting for the next call to trigger reconnection.
@@ -66,12 +75,12 @@ interface WebsocketLinkTransportReconnectOptions {
66
75
  delay?: number;
67
76
  };
68
77
  }
69
- interface WebsocketLinkTransportOptions<_T extends ClientContext> {
78
+ interface WebSocketLinkTransportOptions<_T extends ClientContext> {
70
79
  /**
71
80
  * Returns a WebSocket instance for peer communication.
72
81
  * Can be async for lazy resolution.
73
82
  */
74
- connect: (info: WebsocketLinkTransportAttemptInfo) => Promisable<WebSocketLike>;
83
+ connect: (info: WebSocketLinkTransportAttemptInfo) => Promisable<WebSocketLike>;
75
84
  /**
76
85
  * Whether to connect immediately on initialization, instead of waiting
77
86
  * for the first call. Reduces latency for the first request.
@@ -84,7 +93,7 @@ interface WebsocketLinkTransportOptions<_T extends ClientContext> {
84
93
  *
85
94
  * @default { enabled: false }
86
95
  */
87
- reconnect?: undefined | WebsocketLinkTransportReconnectOptions;
96
+ reconnect?: undefined | WebSocketLinkTransportReconnectOptions;
88
97
  /**
89
98
  * Options for encoding peer messages. such as `prefix` for distinguishing messages on the same channel..
90
99
  */
@@ -94,16 +103,17 @@ interface WebsocketLinkTransportOptions<_T extends ClientContext> {
94
103
  */
95
104
  decodePeerMessage?: DecodePeerMessageOptions | undefined;
96
105
  }
97
- declare class WebsocketLinkTransport<T extends ClientContext> implements StandardLinkTransport<T> {
106
+ declare class WebSocketLinkTransport<T extends ClientContext> implements StandardLinkTransport<T> {
98
107
  private readonly connect;
99
108
  private readonly reconnectEnabled;
100
109
  private readonly reconnectDelay;
101
110
  private readonly reconnectMaxAttempt;
111
+ private readonly reconnectMaxTotalAttempt;
102
112
  private readonly reconnectOnCloseEnabled;
103
113
  private readonly reconnectOnCloseDelay;
104
114
  private readonly encodePeerMessageOptions;
105
115
  private readonly decodePeerMessageOptions;
106
- constructor(options: WebsocketLinkTransportOptions<T>);
116
+ constructor(options: WebSocketLinkTransportOptions<T>);
107
117
  send(standardRequest: StandardRequest, _path: string[], _options: ClientOptions<T>): Promise<StandardLazyResponse>;
108
118
  private totalAttempt;
109
119
  private attempt;
@@ -111,11 +121,16 @@ declare class WebsocketLinkTransport<T extends ClientContext> implements Standar
111
121
  private getConnectedPeer;
112
122
  }
113
123
 
114
- interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, WebsocketLinkTransportOptions<T>, RPCLinkCodecOptions<T> {
124
+ interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, WebSocketLinkTransportOptions<T>, RPCLinkCodecOptions<T> {
115
125
  }
126
+ /**
127
+ * Client link that communicates with an RPC Handler over a WebSocket connection.
128
+ *
129
+ * @see {@link https://orpc.dev/docs/adapters/websocket | WebSocket Adapters}
130
+ */
116
131
  declare class RPCLink<T extends ClientContext> extends StandardLink<T> {
117
132
  constructor(options: RPCLinkOptions<T>);
118
133
  }
119
134
 
120
- export { RPCLink, WebsocketLinkTransport };
121
- export type { RPCLinkOptions, WebSocketLike, WebsocketLinkTransportAttemptInfo, WebsocketLinkTransportOptions, WebsocketLinkTransportReconnectOptions };
135
+ export { RPCLink, WebSocketLinkTransport };
136
+ export type { RPCLinkOptions, WebSocketLike, WebSocketLinkTransportAttemptInfo, WebSocketLinkTransportOptions, WebSocketLinkTransportReconnectOptions };
@@ -1,13 +1,13 @@
1
- import { C as ClientContext, a as ClientOptions } from '../../shared/client.8ug8I-zu.js';
1
+ import { ClientContext, ClientOptions } from '../../index.js';
2
2
  import { Promisable } from '@orpc/shared';
3
- import { StandardRequest, StandardLazyResponse } from '@standardserver/core';
4
- import { EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standardserver/peer';
5
- import { S as StandardLinkTransport, a as StandardLink, b as StandardLinkOptions } from '../../shared/client.CPF3hX6O.js';
3
+ import { StandardRequest, StandardLazyResponse } from '@standard-server/core';
4
+ import { EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standard-server/peer';
5
+ import { StandardLinkTransport, StandardLink, StandardLinkOptions } from '../standard/index.js';
6
6
  import { RPCLinkCodecOptions } from '../standard/index.js';
7
- import '../../shared/client.BdItY5DT.js';
7
+ import '../../shared/client.BPa_Mmuh.js';
8
8
 
9
9
  type WebSocketLike = Pick<WebSocket, 'addEventListener' | 'removeEventListener' | 'send' | 'readyState'>;
10
- interface WebsocketLinkTransportAttemptInfo {
10
+ interface WebSocketLinkTransportAttemptInfo {
11
11
  /**
12
12
  * Total number of connection attempts for this transport's lifetime.
13
13
  * Starts at 1 on the first attempt, increments on every subsequent
@@ -17,11 +17,11 @@ interface WebsocketLinkTransportAttemptInfo {
17
17
  /**
18
18
  * Attempt number within the current (re)connect cycle.
19
19
  * Starts at 1, increments on each consecutive failure, and resets to 1
20
- * once a connection succeeds. Use this for backoff calculations.
20
+ * once a connection succeeds or the cycle gives up. Use this for backoff calculations.
21
21
  */
22
22
  attempt: number;
23
23
  }
24
- interface WebsocketLinkTransportReconnectOptions {
24
+ interface WebSocketLinkTransportReconnectOptions {
25
25
  /**
26
26
  * Whether to automatically reconnect when the connection is lost.
27
27
  *
@@ -33,15 +33,24 @@ interface WebsocketLinkTransportReconnectOptions {
33
33
  *
34
34
  * @default info => info.attempt === 1 ? 0 : 2_000
35
35
  */
36
- delay?: undefined | ((info: WebsocketLinkTransportAttemptInfo) => number);
36
+ delay?: undefined | ((info: WebSocketLinkTransportAttemptInfo) => number);
37
37
  /**
38
38
  * Maximum number of consecutive failed attempts before giving up.
39
- * When exceeded, `getConnectedPeer` throws instead of retrying.
39
+ * When reached, calls waiting for the connection fail, and the next
40
+ * call starts a new reconnect cycle.
40
41
  * Should greater than 1
41
42
  *
42
43
  * @default Infinity
43
44
  */
44
45
  maxAttempt?: undefined | number;
46
+ /**
47
+ * Maximum number of connection attempts over the transport's lifetime,
48
+ * successful ones included (see `totalAttempt`).
49
+ * When reached, calls that need a new connection fail instead of connecting.
50
+ *
51
+ * @default Infinity
52
+ */
53
+ maxTotalAttempt?: undefined | number;
45
54
  /**
46
55
  * Whether to proactively reconnect right after the socket closes,
47
56
  * rather than waiting for the next call to trigger reconnection.
@@ -66,12 +75,12 @@ interface WebsocketLinkTransportReconnectOptions {
66
75
  delay?: number;
67
76
  };
68
77
  }
69
- interface WebsocketLinkTransportOptions<_T extends ClientContext> {
78
+ interface WebSocketLinkTransportOptions<_T extends ClientContext> {
70
79
  /**
71
80
  * Returns a WebSocket instance for peer communication.
72
81
  * Can be async for lazy resolution.
73
82
  */
74
- connect: (info: WebsocketLinkTransportAttemptInfo) => Promisable<WebSocketLike>;
83
+ connect: (info: WebSocketLinkTransportAttemptInfo) => Promisable<WebSocketLike>;
75
84
  /**
76
85
  * Whether to connect immediately on initialization, instead of waiting
77
86
  * for the first call. Reduces latency for the first request.
@@ -84,7 +93,7 @@ interface WebsocketLinkTransportOptions<_T extends ClientContext> {
84
93
  *
85
94
  * @default { enabled: false }
86
95
  */
87
- reconnect?: undefined | WebsocketLinkTransportReconnectOptions;
96
+ reconnect?: undefined | WebSocketLinkTransportReconnectOptions;
88
97
  /**
89
98
  * Options for encoding peer messages. such as `prefix` for distinguishing messages on the same channel..
90
99
  */
@@ -94,16 +103,17 @@ interface WebsocketLinkTransportOptions<_T extends ClientContext> {
94
103
  */
95
104
  decodePeerMessage?: DecodePeerMessageOptions | undefined;
96
105
  }
97
- declare class WebsocketLinkTransport<T extends ClientContext> implements StandardLinkTransport<T> {
106
+ declare class WebSocketLinkTransport<T extends ClientContext> implements StandardLinkTransport<T> {
98
107
  private readonly connect;
99
108
  private readonly reconnectEnabled;
100
109
  private readonly reconnectDelay;
101
110
  private readonly reconnectMaxAttempt;
111
+ private readonly reconnectMaxTotalAttempt;
102
112
  private readonly reconnectOnCloseEnabled;
103
113
  private readonly reconnectOnCloseDelay;
104
114
  private readonly encodePeerMessageOptions;
105
115
  private readonly decodePeerMessageOptions;
106
- constructor(options: WebsocketLinkTransportOptions<T>);
116
+ constructor(options: WebSocketLinkTransportOptions<T>);
107
117
  send(standardRequest: StandardRequest, _path: string[], _options: ClientOptions<T>): Promise<StandardLazyResponse>;
108
118
  private totalAttempt;
109
119
  private attempt;
@@ -111,11 +121,16 @@ declare class WebsocketLinkTransport<T extends ClientContext> implements Standar
111
121
  private getConnectedPeer;
112
122
  }
113
123
 
114
- interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, WebsocketLinkTransportOptions<T>, RPCLinkCodecOptions<T> {
124
+ interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, WebSocketLinkTransportOptions<T>, RPCLinkCodecOptions<T> {
115
125
  }
126
+ /**
127
+ * Client link that communicates with an RPC Handler over a WebSocket connection.
128
+ *
129
+ * @see {@link https://orpc.dev/docs/adapters/websocket | WebSocket Adapters}
130
+ */
116
131
  declare class RPCLink<T extends ClientContext> extends StandardLink<T> {
117
132
  constructor(options: RPCLinkOptions<T>);
118
133
  }
119
134
 
120
- export { RPCLink, WebsocketLinkTransport };
121
- export type { RPCLinkOptions, WebSocketLike, WebsocketLinkTransportAttemptInfo, WebsocketLinkTransportOptions, WebsocketLinkTransportReconnectOptions };
135
+ export { RPCLink, WebSocketLinkTransport };
136
+ export type { RPCLinkOptions, WebSocketLike, WebSocketLinkTransportAttemptInfo, WebSocketLinkTransportOptions, WebSocketLinkTransportReconnectOptions };