@orpc/client 0.0.0-next.999d654 → 0.0.0-next.99d5d75

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 (33) hide show
  1. package/README.md +145 -30
  2. package/dist/adapters/fetch/index.d.mts +31 -14
  3. package/dist/adapters/fetch/index.d.ts +31 -14
  4. package/dist/adapters/fetch/index.mjs +27 -16
  5. package/dist/adapters/message-port/index.d.mts +80 -0
  6. package/dist/adapters/message-port/index.d.ts +80 -0
  7. package/dist/adapters/message-port/index.mjs +87 -0
  8. package/dist/adapters/standard/index.d.mts +9 -146
  9. package/dist/adapters/standard/index.d.ts +9 -146
  10. package/dist/adapters/standard/index.mjs +4 -2
  11. package/dist/adapters/websocket/index.d.mts +29 -0
  12. package/dist/adapters/websocket/index.d.ts +29 -0
  13. package/dist/adapters/websocket/index.mjs +47 -0
  14. package/dist/index.d.mts +108 -33
  15. package/dist/index.d.ts +108 -33
  16. package/dist/index.mjs +86 -37
  17. package/dist/plugins/index.d.mts +249 -0
  18. package/dist/plugins/index.d.ts +249 -0
  19. package/dist/plugins/index.mjs +485 -0
  20. package/dist/shared/client.2jUAqzYU.d.ts +45 -0
  21. package/dist/shared/client.B3pNRBih.d.ts +91 -0
  22. package/dist/shared/client.BFAVy68H.d.mts +91 -0
  23. package/dist/shared/client.BLtwTQUg.mjs +40 -0
  24. package/dist/shared/client.C6Bgyn6F.mjs +404 -0
  25. package/dist/shared/client.CPTihQgC.mjs +171 -0
  26. package/dist/shared/client.CpCa3si8.d.mts +45 -0
  27. package/dist/shared/client.i2uoJbEp.d.mts +83 -0
  28. package/dist/shared/client.i2uoJbEp.d.ts +83 -0
  29. package/package.json +23 -8
  30. package/dist/shared/client.D_CzLDyB.d.mts +0 -42
  31. package/dist/shared/client.D_CzLDyB.d.ts +0 -42
  32. package/dist/shared/client.Df5pd75N.mjs +0 -320
  33. package/dist/shared/client.XAn8cDTM.mjs +0 -266
@@ -0,0 +1,87 @@
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.C6Bgyn6F.mjs';
4
+ import '@orpc/standard-server';
5
+ import '../../shared/client.CPTihQgC.mjs';
6
+ import '@orpc/standard-server-fetch';
7
+ import '../../shared/client.BLtwTQUg.mjs';
8
+
9
+ function postMessagePortMessage(port, data, transfer) {
10
+ if (transfer) {
11
+ port.postMessage(data, transfer);
12
+ } else {
13
+ port.postMessage(data);
14
+ }
15
+ }
16
+ function onMessagePortMessage(port, callback) {
17
+ if ("addEventListener" in port) {
18
+ port.addEventListener("message", (event) => {
19
+ callback(event.data);
20
+ });
21
+ } else if ("on" in port) {
22
+ port.on("message", (event) => {
23
+ callback(event?.data);
24
+ });
25
+ } else if ("onMessage" in port) {
26
+ port.onMessage.addListener((data) => {
27
+ callback(data);
28
+ });
29
+ } else {
30
+ throw new Error("Cannot find a addEventListener/on/onMessage method on the port");
31
+ }
32
+ }
33
+ function onMessagePortClose(port, callback) {
34
+ if ("addEventListener" in port) {
35
+ port.addEventListener("close", async () => {
36
+ callback();
37
+ });
38
+ } else if ("on" in port) {
39
+ port.on("close", async () => {
40
+ callback();
41
+ });
42
+ } else if ("onDisconnect" in port) {
43
+ port.onDisconnect.addListener(() => {
44
+ callback();
45
+ });
46
+ } else {
47
+ throw new Error("Cannot find a addEventListener/on/onDisconnect method on the port");
48
+ }
49
+ }
50
+
51
+ class LinkMessagePortClient {
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);
57
+ if (transfer) {
58
+ postMessagePortMessage(options.port, serializeRequestMessage(id, type, payload), transfer);
59
+ } else {
60
+ postMessagePortMessage(options.port, await encodeRequestMessage(id, type, payload));
61
+ }
62
+ });
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));
68
+ }
69
+ });
70
+ onMessagePortClose(options.port, () => {
71
+ this.peer.close();
72
+ });
73
+ }
74
+ async call(request, _options, _path, _input) {
75
+ const response = await this.peer.request(request);
76
+ return { ...response, body: () => Promise.resolve(response.body) };
77
+ }
78
+ }
79
+
80
+ class RPCLink extends StandardRPCLink {
81
+ constructor(options) {
82
+ const linkClient = new LinkMessagePortClient(options);
83
+ super(linkClient, { ...options, url: "http://orpc" });
84
+ }
85
+ }
86
+
87
+ export { LinkMessagePortClient, RPCLink, onMessagePortClose, onMessagePortMessage, postMessagePortMessage };
@@ -1,148 +1,11 @@
1
- import { Value, Interceptor, Segment } from '@orpc/shared';
2
- import { StandardRequest, StandardLazyResponse, StandardHeaders } from '@orpc/standard-server';
3
- import { C as ClientContext, a as ClientOptionsOut, E as EventIteratorReconnectOptions, b as ClientLink } from '../../shared/client.D_CzLDyB.mjs';
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';
4
6
 
5
- interface StandardLinkCodec<T extends ClientContext> {
6
- encode(path: readonly string[], input: unknown, options: ClientOptionsOut<any>): Promise<StandardRequest>;
7
- decode(response: StandardLazyResponse, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<unknown>;
8
- }
9
- interface StandardLinkClient<T extends ClientContext> {
10
- call(request: StandardRequest, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
11
- }
7
+ declare function toHttpPath(path: readonly string[]): HTTPPath;
8
+ declare function toStandardHeaders(headers: Headers | StandardHeaders): StandardHeaders;
9
+ declare function getMalformedResponseErrorCode(status: number): string;
12
10
 
13
- declare class InvalidEventIteratorRetryResponse extends Error {
14
- }
15
- interface StandardLinkOptions<T extends ClientContext> {
16
- /**
17
- * Maximum number of retry attempts for event iterator errors before throwing.
18
- *
19
- * @default 5
20
- */
21
- eventIteratorMaxRetries?: Value<number, [
22
- reconnectOptions: EventIteratorReconnectOptions,
23
- options: ClientOptionsOut<T>,
24
- path: readonly string[],
25
- input: unknown
26
- ]>;
27
- /**
28
- * Delay (in ms) before retrying an event iterator call.
29
- *
30
- * @default (o) => o.lastRetry ?? (1000 * 2 ** o.retryTimes)
31
- */
32
- eventIteratorRetryDelay?: Value<number, [
33
- reconnectOptions: EventIteratorReconnectOptions,
34
- options: ClientOptionsOut<T>,
35
- path: readonly string[],
36
- input: unknown
37
- ]>;
38
- /**
39
- * Function to determine if an error is retryable.
40
- *
41
- * @default true
42
- */
43
- eventIteratorShouldRetry?: Value<boolean, [
44
- reconnectOptions: EventIteratorReconnectOptions,
45
- options: ClientOptionsOut<T>,
46
- path: readonly string[],
47
- input: unknown
48
- ]>;
49
- interceptors?: Interceptor<{
50
- path: readonly string[];
51
- input: unknown;
52
- options: ClientOptionsOut<T>;
53
- }, unknown, unknown>[];
54
- clientInterceptors?: Interceptor<{
55
- request: StandardRequest;
56
- }, StandardLazyResponse, unknown>[];
57
- }
58
- declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
59
- #private;
60
- readonly codec: StandardLinkCodec<T>;
61
- readonly sender: StandardLinkClient<T>;
62
- private readonly eventIteratorMaxRetries;
63
- private readonly eventIteratorRetryDelay;
64
- private readonly eventIteratorShouldRetry;
65
- private readonly interceptors;
66
- private readonly clientInterceptors;
67
- constructor(codec: StandardLinkCodec<T>, sender: StandardLinkClient<T>, options: StandardLinkOptions<T>);
68
- call(path: readonly string[], input: unknown, options: ClientOptionsOut<T>): Promise<unknown>;
69
- }
70
-
71
- type RPCJsonSerializedMeta = [
72
- 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7,
73
- Segment[]
74
- ][];
75
- type RPCJsonSerialized = [json: unknown, meta: RPCJsonSerializedMeta, maps: Segment[][], blobs: Blob[]];
76
- declare class RPCJsonSerializer {
77
- serialize(data: unknown, segments?: Segment[], meta?: RPCJsonSerializedMeta, maps?: Segment[][], blobs?: Blob[]): RPCJsonSerialized;
78
- deserialize(json: unknown, meta: RPCJsonSerializedMeta): unknown;
79
- deserialize(json: unknown, meta: RPCJsonSerializedMeta, maps: Segment[][], getBlob: (index: number) => Blob): unknown;
80
- }
81
-
82
- declare class RPCSerializer {
83
- #private;
84
- private readonly jsonSerializer;
85
- constructor(jsonSerializer?: RPCJsonSerializer);
86
- serialize(data: unknown): unknown;
87
- deserialize(data: unknown): unknown;
88
- }
89
-
90
- type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
91
- interface StandardRPCLinkCodecOptions<T extends ClientContext> {
92
- /**
93
- * Base url for all requests.
94
- */
95
- url: Value<string | URL, [
96
- options: ClientOptionsOut<T>,
97
- path: readonly string[],
98
- input: unknown
99
- ]>;
100
- /**
101
- * The maximum length of the URL.
102
- *
103
- * @default 2083
104
- */
105
- maxUrlLength?: Value<number, [
106
- options: ClientOptionsOut<T>,
107
- path: readonly string[],
108
- input: unknown
109
- ]>;
110
- /**
111
- * The method used to make the request.
112
- *
113
- * @default 'POST'
114
- */
115
- method?: Value<HTTPMethod, [
116
- options: ClientOptionsOut<T>,
117
- path: readonly string[],
118
- input: unknown
119
- ]>;
120
- /**
121
- * The method to use when the payload cannot safely pass to the server with method return from method function.
122
- * GET is not allowed, it's very dangerous.
123
- *
124
- * @default 'POST'
125
- */
126
- fallbackMethod?: Exclude<HTTPMethod, 'GET'>;
127
- /**
128
- * Inject headers to the request.
129
- */
130
- headers?: Value<StandardHeaders, [
131
- options: ClientOptionsOut<T>,
132
- path: readonly string[],
133
- input: unknown
134
- ]>;
135
- }
136
- declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
137
- private readonly serializer;
138
- private readonly baseUrl;
139
- private readonly maxUrlLength;
140
- private readonly fallbackMethod;
141
- private readonly expectedMethod;
142
- private readonly headers;
143
- constructor(serializer: RPCSerializer, options: StandardRPCLinkCodecOptions<T>);
144
- encode(path: readonly string[], input: unknown, options: ClientOptionsOut<any>): Promise<StandardRequest>;
145
- decode(response: StandardLazyResponse): Promise<unknown>;
146
- }
147
-
148
- export { InvalidEventIteratorRetryResponse, type RPCJsonSerialized, type RPCJsonSerializedMeta, RPCJsonSerializer, RPCSerializer, StandardLink, type StandardLinkClient, type StandardLinkCodec, type StandardLinkOptions, StandardRPCLinkCodec, type StandardRPCLinkCodecOptions };
11
+ export { getMalformedResponseErrorCode, toHttpPath, toStandardHeaders };
@@ -1,148 +1,11 @@
1
- import { Value, Interceptor, Segment } from '@orpc/shared';
2
- import { StandardRequest, StandardLazyResponse, StandardHeaders } from '@orpc/standard-server';
3
- import { C as ClientContext, a as ClientOptionsOut, E as EventIteratorReconnectOptions, b as ClientLink } from '../../shared/client.D_CzLDyB.js';
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';
4
6
 
5
- interface StandardLinkCodec<T extends ClientContext> {
6
- encode(path: readonly string[], input: unknown, options: ClientOptionsOut<any>): Promise<StandardRequest>;
7
- decode(response: StandardLazyResponse, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<unknown>;
8
- }
9
- interface StandardLinkClient<T extends ClientContext> {
10
- call(request: StandardRequest, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
11
- }
7
+ declare function toHttpPath(path: readonly string[]): HTTPPath;
8
+ declare function toStandardHeaders(headers: Headers | StandardHeaders): StandardHeaders;
9
+ declare function getMalformedResponseErrorCode(status: number): string;
12
10
 
13
- declare class InvalidEventIteratorRetryResponse extends Error {
14
- }
15
- interface StandardLinkOptions<T extends ClientContext> {
16
- /**
17
- * Maximum number of retry attempts for event iterator errors before throwing.
18
- *
19
- * @default 5
20
- */
21
- eventIteratorMaxRetries?: Value<number, [
22
- reconnectOptions: EventIteratorReconnectOptions,
23
- options: ClientOptionsOut<T>,
24
- path: readonly string[],
25
- input: unknown
26
- ]>;
27
- /**
28
- * Delay (in ms) before retrying an event iterator call.
29
- *
30
- * @default (o) => o.lastRetry ?? (1000 * 2 ** o.retryTimes)
31
- */
32
- eventIteratorRetryDelay?: Value<number, [
33
- reconnectOptions: EventIteratorReconnectOptions,
34
- options: ClientOptionsOut<T>,
35
- path: readonly string[],
36
- input: unknown
37
- ]>;
38
- /**
39
- * Function to determine if an error is retryable.
40
- *
41
- * @default true
42
- */
43
- eventIteratorShouldRetry?: Value<boolean, [
44
- reconnectOptions: EventIteratorReconnectOptions,
45
- options: ClientOptionsOut<T>,
46
- path: readonly string[],
47
- input: unknown
48
- ]>;
49
- interceptors?: Interceptor<{
50
- path: readonly string[];
51
- input: unknown;
52
- options: ClientOptionsOut<T>;
53
- }, unknown, unknown>[];
54
- clientInterceptors?: Interceptor<{
55
- request: StandardRequest;
56
- }, StandardLazyResponse, unknown>[];
57
- }
58
- declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
59
- #private;
60
- readonly codec: StandardLinkCodec<T>;
61
- readonly sender: StandardLinkClient<T>;
62
- private readonly eventIteratorMaxRetries;
63
- private readonly eventIteratorRetryDelay;
64
- private readonly eventIteratorShouldRetry;
65
- private readonly interceptors;
66
- private readonly clientInterceptors;
67
- constructor(codec: StandardLinkCodec<T>, sender: StandardLinkClient<T>, options: StandardLinkOptions<T>);
68
- call(path: readonly string[], input: unknown, options: ClientOptionsOut<T>): Promise<unknown>;
69
- }
70
-
71
- type RPCJsonSerializedMeta = [
72
- 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7,
73
- Segment[]
74
- ][];
75
- type RPCJsonSerialized = [json: unknown, meta: RPCJsonSerializedMeta, maps: Segment[][], blobs: Blob[]];
76
- declare class RPCJsonSerializer {
77
- serialize(data: unknown, segments?: Segment[], meta?: RPCJsonSerializedMeta, maps?: Segment[][], blobs?: Blob[]): RPCJsonSerialized;
78
- deserialize(json: unknown, meta: RPCJsonSerializedMeta): unknown;
79
- deserialize(json: unknown, meta: RPCJsonSerializedMeta, maps: Segment[][], getBlob: (index: number) => Blob): unknown;
80
- }
81
-
82
- declare class RPCSerializer {
83
- #private;
84
- private readonly jsonSerializer;
85
- constructor(jsonSerializer?: RPCJsonSerializer);
86
- serialize(data: unknown): unknown;
87
- deserialize(data: unknown): unknown;
88
- }
89
-
90
- type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
91
- interface StandardRPCLinkCodecOptions<T extends ClientContext> {
92
- /**
93
- * Base url for all requests.
94
- */
95
- url: Value<string | URL, [
96
- options: ClientOptionsOut<T>,
97
- path: readonly string[],
98
- input: unknown
99
- ]>;
100
- /**
101
- * The maximum length of the URL.
102
- *
103
- * @default 2083
104
- */
105
- maxUrlLength?: Value<number, [
106
- options: ClientOptionsOut<T>,
107
- path: readonly string[],
108
- input: unknown
109
- ]>;
110
- /**
111
- * The method used to make the request.
112
- *
113
- * @default 'POST'
114
- */
115
- method?: Value<HTTPMethod, [
116
- options: ClientOptionsOut<T>,
117
- path: readonly string[],
118
- input: unknown
119
- ]>;
120
- /**
121
- * The method to use when the payload cannot safely pass to the server with method return from method function.
122
- * GET is not allowed, it's very dangerous.
123
- *
124
- * @default 'POST'
125
- */
126
- fallbackMethod?: Exclude<HTTPMethod, 'GET'>;
127
- /**
128
- * Inject headers to the request.
129
- */
130
- headers?: Value<StandardHeaders, [
131
- options: ClientOptionsOut<T>,
132
- path: readonly string[],
133
- input: unknown
134
- ]>;
135
- }
136
- declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
137
- private readonly serializer;
138
- private readonly baseUrl;
139
- private readonly maxUrlLength;
140
- private readonly fallbackMethod;
141
- private readonly expectedMethod;
142
- private readonly headers;
143
- constructor(serializer: RPCSerializer, options: StandardRPCLinkCodecOptions<T>);
144
- encode(path: readonly string[], input: unknown, options: ClientOptionsOut<any>): Promise<StandardRequest>;
145
- decode(response: StandardLazyResponse): Promise<unknown>;
146
- }
147
-
148
- export { InvalidEventIteratorRetryResponse, type RPCJsonSerialized, type RPCJsonSerializedMeta, RPCJsonSerializer, RPCSerializer, StandardLink, type StandardLinkClient, type StandardLinkCodec, type StandardLinkOptions, StandardRPCLinkCodec, type StandardRPCLinkCodecOptions };
11
+ export { getMalformedResponseErrorCode, toHttpPath, toStandardHeaders };
@@ -1,4 +1,6 @@
1
- export { I as InvalidEventIteratorRetryResponse, R as RPCJsonSerializer, b as RPCSerializer, S as StandardLink, a as StandardRPCLinkCodec } from '../../shared/client.Df5pd75N.mjs';
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.C6Bgyn6F.mjs';
2
2
  import '@orpc/shared';
3
- import '../../shared/client.XAn8cDTM.mjs';
4
3
  import '@orpc/standard-server';
4
+ import '../../shared/client.CPTihQgC.mjs';
5
+ import '@orpc/standard-server-fetch';
6
+ import '../../shared/client.BLtwTQUg.mjs';
@@ -0,0 +1,29 @@
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';
6
+
7
+ interface LinkWebsocketClientOptions {
8
+ websocket: Pick<WebSocket, 'addEventListener' | 'send' | 'readyState'>;
9
+ }
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>;
14
+ }
15
+
16
+ interface RPCLinkOptions<T extends ClientContext> extends Omit<StandardRPCLinkOptions<T>, 'url' | 'method' | 'fallbackMethod' | 'maxUrlLength'>, LinkWebsocketClientOptions {
17
+ }
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> {
25
+ constructor(options: RPCLinkOptions<T>);
26
+ }
27
+
28
+ export { LinkWebsocketClient, RPCLink };
29
+ export type { LinkWebsocketClientOptions, RPCLinkOptions };
@@ -0,0 +1,29 @@
1
+ import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
2
+ import { b as ClientContext, c as ClientOptions } from '../../shared/client.i2uoJbEp.js';
3
+ import { f as StandardLinkClient } from '../../shared/client.2jUAqzYU.js';
4
+ import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.B3pNRBih.js';
5
+ import '@orpc/shared';
6
+
7
+ interface LinkWebsocketClientOptions {
8
+ websocket: Pick<WebSocket, 'addEventListener' | 'send' | 'readyState'>;
9
+ }
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>;
14
+ }
15
+
16
+ interface RPCLinkOptions<T extends ClientContext> extends Omit<StandardRPCLinkOptions<T>, 'url' | 'method' | 'fallbackMethod' | 'maxUrlLength'>, LinkWebsocketClientOptions {
17
+ }
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> {
25
+ constructor(options: RPCLinkOptions<T>);
26
+ }
27
+
28
+ export { LinkWebsocketClient, RPCLink };
29
+ export type { LinkWebsocketClientOptions, RPCLinkOptions };
@@ -0,0 +1,47 @@
1
+ import { readAsBuffer } from '@orpc/shared';
2
+ import { ClientPeer } from '@orpc/standard-server-peer';
3
+ import { c as StandardRPCLink } from '../../shared/client.C6Bgyn6F.mjs';
4
+ import '@orpc/standard-server';
5
+ import '../../shared/client.CPTihQgC.mjs';
6
+ import '@orpc/standard-server-fetch';
7
+ import '../../shared/client.BLtwTQUg.mjs';
8
+
9
+ const WEBSOCKET_CONNECTING = 0;
10
+ class LinkWebsocketClient {
11
+ peer;
12
+ constructor(options) {
13
+ const untilOpen = new Promise((resolve) => {
14
+ if (options.websocket.readyState === WEBSOCKET_CONNECTING) {
15
+ options.websocket.addEventListener("open", () => {
16
+ resolve();
17
+ }, { once: true });
18
+ } else {
19
+ resolve();
20
+ }
21
+ });
22
+ this.peer = new ClientPeer(async (message) => {
23
+ await untilOpen;
24
+ return options.websocket.send(message);
25
+ });
26
+ options.websocket.addEventListener("message", async (event) => {
27
+ const message = event.data instanceof Blob ? await readAsBuffer(event.data) : event.data;
28
+ this.peer.message(message);
29
+ });
30
+ options.websocket.addEventListener("close", () => {
31
+ this.peer.close();
32
+ });
33
+ }
34
+ async call(request, _options, _path, _input) {
35
+ const response = await this.peer.request(request);
36
+ return { ...response, body: () => Promise.resolve(response.body) };
37
+ }
38
+ }
39
+
40
+ class RPCLink extends StandardRPCLink {
41
+ constructor(options) {
42
+ const linkClient = new LinkWebsocketClient(options);
43
+ super(linkClient, { ...options, url: "http://orpc" });
44
+ }
45
+ }
46
+
47
+ export { LinkWebsocketClient, RPCLink };