@orpc/client 1.14.6 → 2.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +74 -106
  2. package/dist/adapters/fetch/index.d.mts +55 -36
  3. package/dist/adapters/fetch/index.d.ts +55 -36
  4. package/dist/adapters/fetch/index.mjs +50 -28
  5. package/dist/adapters/message-port/index.d.mts +25 -30
  6. package/dist/adapters/message-port/index.d.ts +25 -30
  7. package/dist/adapters/message-port/index.mjs +33 -29
  8. package/dist/adapters/standard/index.d.mts +58 -9
  9. package/dist/adapters/standard/index.d.ts +58 -9
  10. package/dist/adapters/standard/index.mjs +5 -5
  11. package/dist/adapters/websocket/index.d.mts +113 -21
  12. package/dist/adapters/websocket/index.d.ts +113 -21
  13. package/dist/adapters/websocket/index.mjs +95 -37
  14. package/dist/index.d.mts +84 -159
  15. package/dist/index.d.ts +84 -159
  16. package/dist/index.mjs +76 -34
  17. package/dist/plugins/index.d.mts +125 -132
  18. package/dist/plugins/index.d.ts +125 -132
  19. package/dist/plugins/index.mjs +373 -284
  20. package/dist/shared/client.8ug8I-zu.d.mts +167 -0
  21. package/dist/shared/client.8ug8I-zu.d.ts +167 -0
  22. package/dist/shared/client.BdItY5DT.d.mts +111 -0
  23. package/dist/shared/client.BdItY5DT.d.ts +111 -0
  24. package/dist/shared/client.CPF3hX6O.d.ts +96 -0
  25. package/dist/shared/client.Cby_-GGh.d.mts +96 -0
  26. package/dist/shared/client.DMXKFDyV.mjs +343 -0
  27. package/dist/shared/client.DXhchJ84.mjs +174 -0
  28. package/dist/shared/client.Dnfj8jnT.mjs +92 -0
  29. package/package.json +7 -7
  30. package/dist/shared/client.2jUAqzYU.d.ts +0 -45
  31. package/dist/shared/client.B3pNRBih.d.ts +0 -91
  32. package/dist/shared/client.BFAVy68H.d.mts +0 -91
  33. package/dist/shared/client.BLtwTQUg.mjs +0 -40
  34. package/dist/shared/client.CpCa3si8.d.mts +0 -45
  35. package/dist/shared/client.D9eWXdBV.mjs +0 -174
  36. package/dist/shared/client.DLhbktiD.mjs +0 -404
  37. package/dist/shared/client.i2uoJbEp.d.mts +0 -83
  38. package/dist/shared/client.i2uoJbEp.d.ts +0 -83
@@ -1,9 +1,10 @@
1
+ import { C as ClientContext, a as ClientOptions } from '../../shared/client.8ug8I-zu.mjs';
1
2
  import { Value, Promisable } from '@orpc/shared';
2
- import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
3
- import { DecodedRequestMessage } from '@orpc/standard-server-peer';
4
- import { b as ClientContext, c as ClientOptions } from '../../shared/client.i2uoJbEp.mjs';
5
- import { f as StandardLinkClient } from '../../shared/client.CpCa3si8.mjs';
6
- import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.BFAVy68H.mjs';
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';
6
+ import { RPCLinkCodecOptions } from '../standard/index.mjs';
7
+ import '../../shared/client.BdItY5DT.mjs';
7
8
 
8
9
  /**
9
10
  * The message port used by electron in main process
@@ -28,53 +29,47 @@ interface BrowserPortLike {
28
29
  }
29
30
  type SupportedMessagePort = Pick<MessagePort, 'addEventListener' | 'postMessage'> | MessagePortMainLike | BrowserPortLike;
30
31
  /**
31
- * Message port can support [The structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm)
32
+ * Message port can support [The structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm)
32
33
  */
33
34
  type SupportedMessagePortData = any;
34
35
  declare function postMessagePortMessage(port: SupportedMessagePort, data: SupportedMessagePortData, transfer?: any[]): void;
35
36
  declare function onMessagePortMessage(port: SupportedMessagePort, callback: (data: SupportedMessagePortData) => void): void;
36
37
  declare function onMessagePortClose(port: SupportedMessagePort, callback: () => void): void;
37
38
 
38
- interface LinkMessagePortClientOptions {
39
+ type DecodedRequestMessage = ConstructorParameters<typeof ClientPeer>[0] extends (message: infer TMessage) => unknown ? TMessage : never;
40
+ interface MessagePortLinkTransportOptions<_T extends ClientContext> {
39
41
  port: SupportedMessagePort;
40
42
  /**
41
43
  * By default, oRPC serializes request/response messages to string/binary data before sending over message port.
42
- * If needed, you can define the this option to utilize full power of [MessagePort: postMessage() method](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort/postMessage),
44
+ * If needed, define this option to utilize full power of [MessagePort: postMessage() method](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort/postMessage),
43
45
  * such as transferring ownership of objects to the other side or support unserializable objects like `OffscreenCanvas`.
44
46
  *
45
47
  * @remarks
46
48
  * - return null | undefined to disable this feature
47
49
  *
48
50
  * @warning Make sure your message port supports `transfer` before using this feature.
49
- * @example
50
- * ```ts
51
- * experimental_transfer: (message, port) => {
52
- * const transfer = deepFindTransferableObjects(message) // implement your own logic
53
- * return transfer.length ? transfer : null // only enable when needed
54
- * }
55
- * ```
56
- *
57
- * @see {@link https://orpc.dev/docs/adapters/message-port#transfer Message Port Transfer Docs}
58
51
  */
59
52
  experimental_transfer?: Value<Promisable<object[] | null | undefined>, [message: DecodedRequestMessage, port: SupportedMessagePort]>;
53
+ /**
54
+ * Options for encoding peer messages. such as `prefix` for distinguishing messages on the same channel..
55
+ */
56
+ encodePeerMessage?: EncodePeerMessageOptions | undefined;
57
+ /**
58
+ * Options for decoding peer messages, such as `prefix` for distinguishing messages on the same channel.
59
+ */
60
+ decodePeerMessage?: DecodePeerMessageOptions | undefined;
60
61
  }
61
- declare class LinkMessagePortClient<T extends ClientContext> implements StandardLinkClient<T> {
62
+ declare class MessagePortLinkTransport<T extends ClientContext> implements StandardLinkTransport<T> {
62
63
  private readonly peer;
63
- constructor(options: LinkMessagePortClientOptions);
64
- call(request: StandardRequest, _options: ClientOptions<T>, _path: readonly string[], _input: unknown): Promise<StandardLazyResponse>;
64
+ constructor({ port, experimental_transfer, encodePeerMessage: encodePeerMessageOptions, decodePeerMessage: decodePeerMessageOptions }: MessagePortLinkTransportOptions<T>);
65
+ send(standardRequest: StandardRequest, _path: string[], _options: ClientOptions<T>): Promise<StandardLazyResponse>;
65
66
  }
66
67
 
67
- interface RPCLinkOptions<T extends ClientContext> extends Omit<StandardRPCLinkOptions<T>, 'url' | 'method' | 'fallbackMethod' | 'maxUrlLength'>, LinkMessagePortClientOptions {
68
+ interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, MessagePortLinkTransportOptions<T>, RPCLinkCodecOptions<T> {
68
69
  }
69
- /**
70
- * The RPC Link for common message port implementations.
71
- *
72
- * @see {@link https://orpc.dev/docs/client/rpc-link RPC Link Docs}
73
- * @see {@link https://orpc.dev/docs/adapters/message-port Message Port Adapter Docs}
74
- */
75
- declare class RPCLink<T extends ClientContext> extends StandardRPCLink<T> {
70
+ declare class RPCLink<T extends ClientContext> extends StandardLink<T> {
76
71
  constructor(options: RPCLinkOptions<T>);
77
72
  }
78
73
 
79
- export { LinkMessagePortClient, RPCLink, onMessagePortClose, onMessagePortMessage, postMessagePortMessage };
80
- export type { BrowserPortLike, LinkMessagePortClientOptions, MessagePortMainLike, RPCLinkOptions, SupportedMessagePort, SupportedMessagePortData };
74
+ export { MessagePortLinkTransport, RPCLink, onMessagePortClose, onMessagePortMessage, postMessagePortMessage };
75
+ export type { BrowserPortLike, MessagePortLinkTransportOptions, MessagePortMainLike, RPCLinkOptions, SupportedMessagePort, SupportedMessagePortData };
@@ -1,9 +1,10 @@
1
+ import { C as ClientContext, a as ClientOptions } from '../../shared/client.8ug8I-zu.js';
1
2
  import { Value, Promisable } from '@orpc/shared';
2
- import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
3
- import { DecodedRequestMessage } from '@orpc/standard-server-peer';
4
- import { b as ClientContext, c as ClientOptions } from '../../shared/client.i2uoJbEp.js';
5
- import { f as StandardLinkClient } from '../../shared/client.2jUAqzYU.js';
6
- import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.B3pNRBih.js';
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';
6
+ import { RPCLinkCodecOptions } from '../standard/index.js';
7
+ import '../../shared/client.BdItY5DT.js';
7
8
 
8
9
  /**
9
10
  * The message port used by electron in main process
@@ -28,53 +29,47 @@ interface BrowserPortLike {
28
29
  }
29
30
  type SupportedMessagePort = Pick<MessagePort, 'addEventListener' | 'postMessage'> | MessagePortMainLike | BrowserPortLike;
30
31
  /**
31
- * Message port can support [The structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm)
32
+ * Message port can support [The structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm)
32
33
  */
33
34
  type SupportedMessagePortData = any;
34
35
  declare function postMessagePortMessage(port: SupportedMessagePort, data: SupportedMessagePortData, transfer?: any[]): void;
35
36
  declare function onMessagePortMessage(port: SupportedMessagePort, callback: (data: SupportedMessagePortData) => void): void;
36
37
  declare function onMessagePortClose(port: SupportedMessagePort, callback: () => void): void;
37
38
 
38
- interface LinkMessagePortClientOptions {
39
+ type DecodedRequestMessage = ConstructorParameters<typeof ClientPeer>[0] extends (message: infer TMessage) => unknown ? TMessage : never;
40
+ interface MessagePortLinkTransportOptions<_T extends ClientContext> {
39
41
  port: SupportedMessagePort;
40
42
  /**
41
43
  * By default, oRPC serializes request/response messages to string/binary data before sending over message port.
42
- * If needed, you can define the this option to utilize full power of [MessagePort: postMessage() method](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort/postMessage),
44
+ * If needed, define this option to utilize full power of [MessagePort: postMessage() method](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort/postMessage),
43
45
  * such as transferring ownership of objects to the other side or support unserializable objects like `OffscreenCanvas`.
44
46
  *
45
47
  * @remarks
46
48
  * - return null | undefined to disable this feature
47
49
  *
48
50
  * @warning Make sure your message port supports `transfer` before using this feature.
49
- * @example
50
- * ```ts
51
- * experimental_transfer: (message, port) => {
52
- * const transfer = deepFindTransferableObjects(message) // implement your own logic
53
- * return transfer.length ? transfer : null // only enable when needed
54
- * }
55
- * ```
56
- *
57
- * @see {@link https://orpc.dev/docs/adapters/message-port#transfer Message Port Transfer Docs}
58
51
  */
59
52
  experimental_transfer?: Value<Promisable<object[] | null | undefined>, [message: DecodedRequestMessage, port: SupportedMessagePort]>;
53
+ /**
54
+ * Options for encoding peer messages. such as `prefix` for distinguishing messages on the same channel..
55
+ */
56
+ encodePeerMessage?: EncodePeerMessageOptions | undefined;
57
+ /**
58
+ * Options for decoding peer messages, such as `prefix` for distinguishing messages on the same channel.
59
+ */
60
+ decodePeerMessage?: DecodePeerMessageOptions | undefined;
60
61
  }
61
- declare class LinkMessagePortClient<T extends ClientContext> implements StandardLinkClient<T> {
62
+ declare class MessagePortLinkTransport<T extends ClientContext> implements StandardLinkTransport<T> {
62
63
  private readonly peer;
63
- constructor(options: LinkMessagePortClientOptions);
64
- call(request: StandardRequest, _options: ClientOptions<T>, _path: readonly string[], _input: unknown): Promise<StandardLazyResponse>;
64
+ constructor({ port, experimental_transfer, encodePeerMessage: encodePeerMessageOptions, decodePeerMessage: decodePeerMessageOptions }: MessagePortLinkTransportOptions<T>);
65
+ send(standardRequest: StandardRequest, _path: string[], _options: ClientOptions<T>): Promise<StandardLazyResponse>;
65
66
  }
66
67
 
67
- interface RPCLinkOptions<T extends ClientContext> extends Omit<StandardRPCLinkOptions<T>, 'url' | 'method' | 'fallbackMethod' | 'maxUrlLength'>, LinkMessagePortClientOptions {
68
+ interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, MessagePortLinkTransportOptions<T>, RPCLinkCodecOptions<T> {
68
69
  }
69
- /**
70
- * The RPC Link for common message port implementations.
71
- *
72
- * @see {@link https://orpc.dev/docs/client/rpc-link RPC Link Docs}
73
- * @see {@link https://orpc.dev/docs/adapters/message-port Message Port Adapter Docs}
74
- */
75
- declare class RPCLink<T extends ClientContext> extends StandardRPCLink<T> {
70
+ declare class RPCLink<T extends ClientContext> extends StandardLink<T> {
76
71
  constructor(options: RPCLinkOptions<T>);
77
72
  }
78
73
 
79
- export { LinkMessagePortClient, RPCLink, onMessagePortClose, onMessagePortMessage, postMessagePortMessage };
80
- export type { BrowserPortLike, LinkMessagePortClientOptions, MessagePortMainLike, RPCLinkOptions, SupportedMessagePort, SupportedMessagePortData };
74
+ export { MessagePortLinkTransport, RPCLink, onMessagePortClose, onMessagePortMessage, postMessagePortMessage };
75
+ export type { BrowserPortLike, MessagePortLinkTransportOptions, MessagePortMainLike, RPCLinkOptions, SupportedMessagePort, SupportedMessagePortData };
@@ -1,10 +1,10 @@
1
- import { value, isObject } from '@orpc/shared';
2
- import { experimental_ClientPeerWithoutCodec, serializeRequestMessage, encodeRequestMessage, deserializeResponseMessage, decodeResponseMessage } from '@orpc/standard-server-peer';
3
- import { c as StandardRPCLink } from '../../shared/client.DLhbktiD.mjs';
4
- import '@orpc/standard-server';
5
- import '../../shared/client.D9eWXdBV.mjs';
6
- import '@orpc/standard-server-fetch';
7
- import '../../shared/client.BLtwTQUg.mjs';
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';
8
8
 
9
9
  function postMessagePortMessage(port, data, transfer) {
10
10
  if (transfer) {
@@ -32,11 +32,11 @@ function onMessagePortMessage(port, callback) {
32
32
  }
33
33
  function onMessagePortClose(port, callback) {
34
34
  if ("addEventListener" in port) {
35
- port.addEventListener("close", async () => {
35
+ port.addEventListener("close", () => {
36
36
  callback();
37
37
  });
38
38
  } else if ("on" in port) {
39
- port.on("close", async () => {
39
+ port.on("close", () => {
40
40
  callback();
41
41
  });
42
42
  } else if ("onDisconnect" in port) {
@@ -48,40 +48,44 @@ function onMessagePortClose(port, callback) {
48
48
  }
49
49
  }
50
50
 
51
- class LinkMessagePortClient {
51
+ class MessagePortLinkTransport {
52
52
  peer;
53
- constructor(options) {
54
- this.peer = new experimental_ClientPeerWithoutCodec(async (message) => {
55
- const [id, type, payload] = message;
56
- const transfer = await value(options.experimental_transfer, message, options.port);
53
+ constructor({ port, experimental_transfer, encodePeerMessage: encodePeerMessageOptions, decodePeerMessage: decodePeerMessageOptions }) {
54
+ this.peer = new ClientPeer(async (message) => {
55
+ const transfer = await value(experimental_transfer, message, port);
57
56
  if (transfer) {
58
- postMessagePortMessage(options.port, serializeRequestMessage(id, type, payload), transfer);
57
+ postMessagePortMessage(port, message, transfer);
59
58
  } else {
60
- postMessagePortMessage(options.port, await encodeRequestMessage(id, type, payload));
59
+ postMessagePortMessage(port, await encodePeerMessage(message, encodePeerMessageOptions));
61
60
  }
62
61
  });
63
- onMessagePortMessage(options.port, async (message) => {
64
- if (isObject(message)) {
65
- await this.peer.message(deserializeResponseMessage(message));
66
- } else {
67
- await this.peer.message(await decodeResponseMessage(message));
62
+ onMessagePortMessage(port, async (message) => {
63
+ if (isPlainObject(message)) {
64
+ await this.peer.message(message);
65
+ return;
66
+ }
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);
68
71
  }
69
72
  });
70
- onMessagePortClose(options.port, () => {
73
+ onMessagePortClose(port, () => {
71
74
  this.peer.close();
72
75
  });
73
76
  }
74
- async call(request, _options, _path, _input) {
75
- const response = await this.peer.request(request);
76
- return { ...response, body: () => Promise.resolve(response.body) };
77
+ async send(standardRequest, _path, _options) {
78
+ const standardResponse = await this.peer.request(standardRequest);
79
+ return standardResponse;
77
80
  }
78
81
  }
79
82
 
80
- class RPCLink extends StandardRPCLink {
83
+ class RPCLink extends StandardLink {
81
84
  constructor(options) {
82
- const linkClient = new LinkMessagePortClient(options);
83
- super(linkClient, { ...options, url: "http://orpc" });
85
+ const codec = new RPCLinkCodec(options);
86
+ const transport = new MessagePortLinkTransport(options);
87
+ super(codec, transport, options);
84
88
  }
85
89
  }
86
90
 
87
- export { LinkMessagePortClient, RPCLink, onMessagePortClose, onMessagePortMessage, postMessagePortMessage };
91
+ export { MessagePortLinkTransport, RPCLink, onMessagePortClose, onMessagePortMessage, postMessagePortMessage };
@@ -1,11 +1,60 @@
1
- export { C as CompositeStandardLinkPlugin, d as StandardLink, f as StandardLinkClient, S as StandardLinkClientInterceptorOptions, e as StandardLinkCodec, c as StandardLinkInterceptorOptions, b as StandardLinkOptions, a as StandardLinkPlugin } from '../../shared/client.CpCa3si8.mjs';
2
- export { S as STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES, c as StandardRPCCustomJsonSerializer, b as StandardRPCJsonSerialized, a as StandardRPCJsonSerializedMetaItem, e as StandardRPCJsonSerializer, d as StandardRPCJsonSerializerOptions, g as StandardRPCLink, i as StandardRPCLinkCodec, h as StandardRPCLinkCodecOptions, f as StandardRPCLinkOptions, j as StandardRPCSerializer } from '../../shared/client.BFAVy68H.mjs';
3
- import { StandardHeaders } from '@orpc/standard-server';
4
- import { H as HTTPPath } from '../../shared/client.i2uoJbEp.mjs';
5
- import '@orpc/shared';
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
+ import { C as ClientContext, a as ClientOptions } from '../../shared/client.8ug8I-zu.mjs';
6
+ import { e as RPCSerializer } from '../../shared/client.BdItY5DT.mjs';
6
7
 
7
- declare function toHttpPath(path: readonly string[]): HTTPPath;
8
- declare function toStandardHeaders(headers: Headers | StandardHeaders): StandardHeaders;
9
- declare function getMalformedResponseErrorCode(status: number): string;
8
+ interface RPCLinkCodecOptions<T extends ClientContext> {
9
+ /**
10
+ * Base url for all requests (without origin). Should match with handler's prefix.
11
+ *
12
+ * @example '/rpc?base=1'
13
+ *
14
+ * @default '/'
15
+ */
16
+ url?: Value<Promisable<StandardUrl>, [options: ClientOptions<T>, path: string[], input: unknown]>;
17
+ /**
18
+ * The maximum length of the URL.
19
+ *
20
+ * If the URL exceeds this length, the codec should use the `fallbackMethod` to send the request with the payload in the body instead of the URL.
21
+ *
22
+ * @default 2083
23
+ */
24
+ maxUrlLength?: Value<Promisable<number>, [options: ClientOptions<T>, path: string[], input: unknown]>;
25
+ /**
26
+ * The method used to make the request.
27
+ *
28
+ * @default 'POST'
29
+ */
30
+ method?: Value<Promisable<'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'>, [options: ClientOptions<T>, path: string[], input: unknown]>;
31
+ /**
32
+ * The method to use when the payload cannot safely pass to the server with method return from method function.
33
+ * GET is not allowed, it's very dangerous.
34
+ *
35
+ * @default 'POST'
36
+ */
37
+ fallbackMethod?: 'POST' | 'PUT' | 'PATCH' | 'DELETE';
38
+ /**
39
+ * Inject headers to the request.
40
+ */
41
+ headers?: Value<Promisable<StandardHeaders | Headers>, [options: ClientOptions<T>, path: string[], input: unknown]>;
42
+ /**
43
+ * Override the default RPC serializer.
44
+ */
45
+ serializer?: Pick<RPCSerializer, keyof RPCSerializer>;
46
+ }
47
+ declare class RPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
48
+ private readonly baseUrl;
49
+ private readonly maxUrlLength;
50
+ private readonly fallbackMethod;
51
+ private readonly expectedMethod;
52
+ private readonly headers;
53
+ private readonly serializer;
54
+ constructor(options: RPCLinkCodecOptions<T>);
55
+ encodeInput(input: unknown, path: string[], options: ClientOptions<T>): Promise<StandardRequest>;
56
+ decodeResponse(response: StandardLazyResponse): Promise<StandardLinkCodecDecodedResponse>;
57
+ }
10
58
 
11
- export { getMalformedResponseErrorCode, toHttpPath, toStandardHeaders };
59
+ export { RPCLinkCodec, StandardLinkCodec, StandardLinkCodecDecodedResponse };
60
+ export type { RPCLinkCodecOptions };
@@ -1,11 +1,60 @@
1
- export { C as CompositeStandardLinkPlugin, d as StandardLink, f as StandardLinkClient, S as StandardLinkClientInterceptorOptions, e as StandardLinkCodec, c as StandardLinkInterceptorOptions, b as StandardLinkOptions, a as StandardLinkPlugin } from '../../shared/client.2jUAqzYU.js';
2
- export { S as STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES, c as StandardRPCCustomJsonSerializer, b as StandardRPCJsonSerialized, a as StandardRPCJsonSerializedMetaItem, e as StandardRPCJsonSerializer, d as StandardRPCJsonSerializerOptions, g as StandardRPCLink, i as StandardRPCLinkCodec, h as StandardRPCLinkCodecOptions, f as StandardRPCLinkOptions, j as StandardRPCSerializer } from '../../shared/client.B3pNRBih.js';
3
- import { StandardHeaders } from '@orpc/standard-server';
4
- import { H as HTTPPath } from '../../shared/client.i2uoJbEp.js';
5
- import '@orpc/shared';
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
+ import { C as ClientContext, a as ClientOptions } from '../../shared/client.8ug8I-zu.js';
6
+ import { e as RPCSerializer } from '../../shared/client.BdItY5DT.js';
6
7
 
7
- declare function toHttpPath(path: readonly string[]): HTTPPath;
8
- declare function toStandardHeaders(headers: Headers | StandardHeaders): StandardHeaders;
9
- declare function getMalformedResponseErrorCode(status: number): string;
8
+ interface RPCLinkCodecOptions<T extends ClientContext> {
9
+ /**
10
+ * Base url for all requests (without origin). Should match with handler's prefix.
11
+ *
12
+ * @example '/rpc?base=1'
13
+ *
14
+ * @default '/'
15
+ */
16
+ url?: Value<Promisable<StandardUrl>, [options: ClientOptions<T>, path: string[], input: unknown]>;
17
+ /**
18
+ * The maximum length of the URL.
19
+ *
20
+ * If the URL exceeds this length, the codec should use the `fallbackMethod` to send the request with the payload in the body instead of the URL.
21
+ *
22
+ * @default 2083
23
+ */
24
+ maxUrlLength?: Value<Promisable<number>, [options: ClientOptions<T>, path: string[], input: unknown]>;
25
+ /**
26
+ * The method used to make the request.
27
+ *
28
+ * @default 'POST'
29
+ */
30
+ method?: Value<Promisable<'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'>, [options: ClientOptions<T>, path: string[], input: unknown]>;
31
+ /**
32
+ * The method to use when the payload cannot safely pass to the server with method return from method function.
33
+ * GET is not allowed, it's very dangerous.
34
+ *
35
+ * @default 'POST'
36
+ */
37
+ fallbackMethod?: 'POST' | 'PUT' | 'PATCH' | 'DELETE';
38
+ /**
39
+ * Inject headers to the request.
40
+ */
41
+ headers?: Value<Promisable<StandardHeaders | Headers>, [options: ClientOptions<T>, path: string[], input: unknown]>;
42
+ /**
43
+ * Override the default RPC serializer.
44
+ */
45
+ serializer?: Pick<RPCSerializer, keyof RPCSerializer>;
46
+ }
47
+ declare class RPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
48
+ private readonly baseUrl;
49
+ private readonly maxUrlLength;
50
+ private readonly fallbackMethod;
51
+ private readonly expectedMethod;
52
+ private readonly headers;
53
+ private readonly serializer;
54
+ constructor(options: RPCLinkCodecOptions<T>);
55
+ encodeInput(input: unknown, path: string[], options: ClientOptions<T>): Promise<StandardRequest>;
56
+ decodeResponse(response: StandardLazyResponse): Promise<StandardLinkCodecDecodedResponse>;
57
+ }
10
58
 
11
- export { getMalformedResponseErrorCode, toHttpPath, toStandardHeaders };
59
+ export { RPCLinkCodec, StandardLinkCodec, StandardLinkCodecDecodedResponse };
60
+ export type { RPCLinkCodecOptions };
@@ -1,6 +1,6 @@
1
- export { C as CompositeStandardLinkPlugin, a as STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES, S as StandardLink, b as StandardRPCJsonSerializer, c as StandardRPCLink, d as StandardRPCLinkCodec, e as StandardRPCSerializer, g as getMalformedResponseErrorCode, t as toHttpPath, f as toStandardHeaders } from '../../shared/client.DLhbktiD.mjs';
1
+ export { C as CompositeStandardLinkPlugin, R as RPCLinkCodec, S as StandardLink } from '../../shared/client.DXhchJ84.mjs';
2
2
  import '@orpc/shared';
3
- import '@orpc/standard-server';
4
- import '../../shared/client.D9eWXdBV.mjs';
5
- import '@orpc/standard-server-fetch';
6
- import '../../shared/client.BLtwTQUg.mjs';
3
+ import '@standardserver/core';
4
+ import '@standardserver/fetch';
5
+ import '../../shared/client.Dnfj8jnT.mjs';
6
+ import '../../shared/client.DMXKFDyV.mjs';
@@ -1,29 +1,121 @@
1
- import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
2
- import { b as ClientContext, c as ClientOptions } from '../../shared/client.i2uoJbEp.mjs';
3
- import { f as StandardLinkClient } from '../../shared/client.CpCa3si8.mjs';
4
- import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.BFAVy68H.mjs';
5
- import '@orpc/shared';
1
+ import { C as ClientContext, a as ClientOptions } from '../../shared/client.8ug8I-zu.mjs';
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';
6
+ import { RPCLinkCodecOptions } from '../standard/index.mjs';
7
+ import '../../shared/client.BdItY5DT.mjs';
6
8
 
7
- interface LinkWebsocketClientOptions {
8
- websocket: Pick<WebSocket, 'addEventListener' | 'removeEventListener' | 'send' | 'readyState'>;
9
+ type WebSocketLike = Pick<WebSocket, 'addEventListener' | 'removeEventListener' | 'send' | 'readyState'>;
10
+ interface WebsocketLinkTransportAttemptInfo {
11
+ /**
12
+ * Total number of connection attempts for this transport's lifetime.
13
+ * Starts at 1 on the first attempt, increments on every subsequent
14
+ * attempt, and never resets.
15
+ */
16
+ totalAttempt: number;
17
+ /**
18
+ * Attempt number within the current (re)connect cycle.
19
+ * Starts at 1, increments on each consecutive failure, and resets to 1
20
+ * once a connection succeeds. Use this for backoff calculations.
21
+ */
22
+ attempt: number;
9
23
  }
10
- declare class LinkWebsocketClient<T extends ClientContext> implements StandardLinkClient<T> {
11
- private readonly peer;
12
- constructor(options: LinkWebsocketClientOptions);
13
- call(request: StandardRequest, _options: ClientOptions<T>, _path: readonly string[], _input: unknown): Promise<StandardLazyResponse>;
24
+ interface WebsocketLinkTransportReconnectOptions {
25
+ /**
26
+ * Whether to automatically reconnect when the connection is lost.
27
+ *
28
+ * @default false
29
+ */
30
+ enabled: boolean;
31
+ /**
32
+ * Delay before a (re)connect attempt, in milliseconds.
33
+ *
34
+ * @default info => info.attempt === 1 ? 0 : 2_000
35
+ */
36
+ delay?: undefined | ((info: WebsocketLinkTransportAttemptInfo) => number);
37
+ /**
38
+ * Maximum number of consecutive failed attempts before giving up.
39
+ * When exceeded, `getConnectedPeer` throws instead of retrying.
40
+ * Should greater than 1
41
+ *
42
+ * @default Infinity
43
+ */
44
+ maxAttempt?: undefined | number;
45
+ /**
46
+ * Whether to proactively reconnect right after the socket closes,
47
+ * rather than waiting for the next call to trigger reconnection.
48
+ * Reduces latency for the next request.
49
+ *
50
+ * @default { enabled: false }
51
+ */
52
+ onClose?: undefined | {
53
+ /**
54
+ * Whether to proactively reconnect right after the socket closes,
55
+ * rather than waiting for the next call to trigger reconnection.
56
+ * Reduces latency for the next request.
57
+ *
58
+ * @default false
59
+ */
60
+ enabled: boolean;
61
+ /**
62
+ * Delay before reconnecting after the socket closes, in milliseconds.
63
+ *
64
+ * @default 0
65
+ */
66
+ delay?: number;
67
+ };
68
+ }
69
+ interface WebsocketLinkTransportOptions<_T extends ClientContext> {
70
+ /**
71
+ * Returns a WebSocket instance for peer communication.
72
+ * Can be async for lazy resolution.
73
+ */
74
+ connect: (info: WebsocketLinkTransportAttemptInfo) => Promisable<WebSocketLike>;
75
+ /**
76
+ * Whether to connect immediately on initialization, instead of waiting
77
+ * for the first call. Reduces latency for the first request.
78
+ *
79
+ * @default false
80
+ */
81
+ connectOnInit?: undefined | boolean;
82
+ /**
83
+ * Reconnection behavior when the connection is lost.
84
+ *
85
+ * @default { enabled: false }
86
+ */
87
+ reconnect?: undefined | WebsocketLinkTransportReconnectOptions;
88
+ /**
89
+ * Options for encoding peer messages. such as `prefix` for distinguishing messages on the same channel..
90
+ */
91
+ encodePeerMessage?: EncodePeerMessageOptions | undefined;
92
+ /**
93
+ * Options for decoding peer messages. such as `prefix` for distinguishing messages on the same channel..
94
+ */
95
+ decodePeerMessage?: DecodePeerMessageOptions | undefined;
96
+ }
97
+ declare class WebsocketLinkTransport<T extends ClientContext> implements StandardLinkTransport<T> {
98
+ private readonly connect;
99
+ private readonly reconnectEnabled;
100
+ private readonly reconnectDelay;
101
+ private readonly reconnectMaxAttempt;
102
+ private readonly reconnectOnCloseEnabled;
103
+ private readonly reconnectOnCloseDelay;
104
+ private readonly encodePeerMessageOptions;
105
+ private readonly decodePeerMessageOptions;
106
+ constructor(options: WebsocketLinkTransportOptions<T>);
107
+ send(standardRequest: StandardRequest, _path: string[], _options: ClientOptions<T>): Promise<StandardLazyResponse>;
108
+ private totalAttempt;
109
+ private attempt;
110
+ private current;
111
+ private getConnectedPeer;
14
112
  }
15
113
 
16
- interface RPCLinkOptions<T extends ClientContext> extends Omit<StandardRPCLinkOptions<T>, 'url' | 'method' | 'fallbackMethod' | 'maxUrlLength'>, LinkWebsocketClientOptions {
114
+ interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, WebsocketLinkTransportOptions<T>, RPCLinkCodecOptions<T> {
17
115
  }
18
- /**
19
- * The RPC Link communicates with the server using the RPC protocol over WebSocket.
20
- *
21
- * @see {@link https://orpc.dev/docs/client/rpc-link RPC Link Docs}
22
- * @see {@link https://orpc.dev/docs/adapters/websocket WebSocket Adapter Docs}
23
- */
24
- declare class RPCLink<T extends ClientContext> extends StandardRPCLink<T> {
116
+ declare class RPCLink<T extends ClientContext> extends StandardLink<T> {
25
117
  constructor(options: RPCLinkOptions<T>);
26
118
  }
27
119
 
28
- export { LinkWebsocketClient, RPCLink };
29
- export type { LinkWebsocketClientOptions, RPCLinkOptions };
120
+ export { RPCLink, WebsocketLinkTransport };
121
+ export type { RPCLinkOptions, WebSocketLike, WebsocketLinkTransportAttemptInfo, WebsocketLinkTransportOptions, WebsocketLinkTransportReconnectOptions };