@orpc/client 1.14.6 → 2.0.0-beta.10

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 +78 -107
  2. package/dist/adapters/fetch/index.d.mts +54 -35
  3. package/dist/adapters/fetch/index.d.ts +54 -35
  4. package/dist/adapters/fetch/index.mjs +49 -27
  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 +59 -9
  9. package/dist/adapters/standard/index.d.ts +59 -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.BN52ep3E.mjs +174 -0
  23. package/dist/shared/client.BdItY5DT.d.mts +111 -0
  24. package/dist/shared/client.BdItY5DT.d.ts +111 -0
  25. package/dist/shared/client.CPF3hX6O.d.ts +96 -0
  26. package/dist/shared/client.Cby_-GGh.d.mts +96 -0
  27. package/dist/shared/client.D3TIIok6.mjs +343 -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,46 +1,68 @@
1
- import { toArray, intercept } from '@orpc/shared';
2
- import { toFetchRequest, toStandardLazyResponse } from '@orpc/standard-server-fetch';
3
- import { C as CompositeStandardLinkPlugin, c as StandardRPCLink } from '../../shared/client.DLhbktiD.mjs';
4
- import '@orpc/standard-server';
5
- import '../../shared/client.D9eWXdBV.mjs';
6
- import '../../shared/client.BLtwTQUg.mjs';
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.BN52ep3E.mjs';
4
+ import '@standardserver/core';
5
+ import '../../shared/client.Dnfj8jnT.mjs';
6
+ import '../../shared/client.D3TIIok6.mjs';
7
7
 
8
- class CompositeLinkFetchPlugin extends CompositeStandardLinkPlugin {
9
- initRuntimeAdapter(options) {
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) {
10
15
  for (const plugin of this.plugins) {
11
- plugin.initRuntimeAdapter?.(options);
16
+ if (plugin.initFetchLinkTransportOptions) {
17
+ options = plugin.initFetchLinkTransportOptions(options);
18
+ }
12
19
  }
20
+ return options;
13
21
  }
14
22
  }
15
23
 
16
- class LinkFetchClient {
24
+ class FetchLinkTransport {
25
+ origin;
17
26
  fetch;
18
27
  toFetchRequestOptions;
19
- adapterInterceptors;
28
+ fetchInterceptors;
20
29
  constructor(options) {
21
- const plugin = new CompositeLinkFetchPlugin(options.plugins);
22
- plugin.initRuntimeAdapter(options);
30
+ options = new CompositeFetchLinkTransportPlugin(options.plugins).initFetchLinkTransportOptions(options);
31
+ this.origin = options.origin;
23
32
  this.fetch = options.fetch ?? globalThis.fetch.bind(globalThis);
24
- this.toFetchRequestOptions = options;
25
- this.adapterInterceptors = toArray(options.adapterInterceptors);
33
+ this.toFetchRequestOptions = options.toFetchRequest;
34
+ this.fetchInterceptors = options.fetchInterceptors;
26
35
  }
27
- async call(standardRequest, options, path, input) {
28
- const request = toFetchRequest(standardRequest, this.toFetchRequestOptions);
29
- const fetchResponse = await intercept(
30
- this.adapterInterceptors,
31
- { ...options, request, path, input, init: { redirect: "manual" } },
32
- ({ request: request2, path: path2, input: input2, init, ...options2 }) => this.fetch(request2, init, options2, path2, input2)
36
+ async send(standardRequest, path, options) {
37
+ let origin = await value(this.origin, options, path);
38
+ if (origin?.endsWith("/")) {
39
+ origin = origin.slice(0, -1);
40
+ }
41
+ const url = `${origin ?? ""}${standardRequest.url}`;
42
+ const [body, standardHeaders] = toFetchBody(standardRequest.body, standardRequest.headers, this.toFetchRequestOptions);
43
+ const init = {
44
+ body,
45
+ headers: toFetchHeaders(standardHeaders),
46
+ method: standardRequest.method,
47
+ signal: options.signal,
48
+ redirect: "manual"
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)
33
54
  );
34
- const lazyResponse = toStandardLazyResponse(fetchResponse, { signal: request.signal });
35
- return lazyResponse;
55
+ const standardResponse = toStandardLazyResponse(response);
56
+ return standardResponse;
36
57
  }
37
58
  }
38
59
 
39
- class RPCLink extends StandardRPCLink {
60
+ class RPCLink extends StandardLink {
40
61
  constructor(options) {
41
- const linkClient = new LinkFetchClient(options);
42
- super(linkClient, options);
62
+ const codec = new RPCLinkCodec(options);
63
+ const transport = new FetchLinkTransport(options);
64
+ super(codec, transport, options);
43
65
  }
44
66
  }
45
67
 
46
- export { LinkFetchClient, RPCLink };
68
+ export { CompositeFetchLinkTransportPlugin, FetchLinkTransport, RPCLink };
@@ -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.BN52ep3E.mjs';
4
+ import '@standardserver/core';
5
+ import '@standardserver/fetch';
6
+ import '../../shared/client.Dnfj8jnT.mjs';
7
+ import '../../shared/client.D3TIIok6.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,61 @@
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
+ 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';
6
8
 
7
- declare function toHttpPath(path: readonly string[]): HTTPPath;
8
- declare function toStandardHeaders(headers: Headers | StandardHeaders): StandardHeaders;
9
- declare function getMalformedResponseErrorCode(status: number): string;
9
+ interface RPCLinkCodecOptions<T extends ClientContext> {
10
+ /**
11
+ * Base url for all requests (without origin). Should match with handler's prefix.
12
+ *
13
+ * @example '/rpc?base=1'
14
+ *
15
+ * @default '/'
16
+ */
17
+ url?: Value<Promisable<StandardUrl>, [options: ClientOptions<T>, path: string[], input: unknown]>;
18
+ /**
19
+ * The maximum length of the URL.
20
+ *
21
+ * 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.
22
+ *
23
+ * @default 2083
24
+ */
25
+ maxUrlLength?: Value<Promisable<number>, [options: ClientOptions<T>, path: string[], input: unknown]>;
26
+ /**
27
+ * The method used to make the request.
28
+ *
29
+ * @default 'POST'
30
+ */
31
+ method?: Value<Promisable<'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'>, [options: ClientOptions<T>, path: string[], input: unknown]>;
32
+ /**
33
+ * The method to use when the payload cannot safely pass to the server with method return from method function.
34
+ * GET is not allowed, it's very dangerous.
35
+ *
36
+ * @default 'POST'
37
+ */
38
+ fallbackMethod?: 'POST' | 'PUT' | 'PATCH' | 'DELETE';
39
+ /**
40
+ * Inject headers to the request.
41
+ */
42
+ headers?: Value<Promisable<StandardHeaders | Headers>, [options: ClientOptions<T>, path: string[], input: unknown]>;
43
+ /**
44
+ * Override the default RPC serializer.
45
+ */
46
+ serializer?: Pick<RPCSerializer, keyof RPCSerializer>;
47
+ }
48
+ declare class RPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
49
+ private readonly baseUrl;
50
+ private readonly maxUrlLength;
51
+ private readonly fallbackMethod;
52
+ private readonly expectedMethod;
53
+ private readonly headers;
54
+ private readonly serializer;
55
+ constructor(options: RPCLinkCodecOptions<T>);
56
+ encodeInput(input: unknown, path: string[], options: ClientOptions<T>): Promise<StandardRequest>;
57
+ decodeResponse(response: StandardLazyResponse): Promise<StandardLinkCodecDecodedResponse>;
58
+ }
10
59
 
11
- export { getMalformedResponseErrorCode, toHttpPath, toStandardHeaders };
60
+ export { RPCLinkCodec, StandardLinkCodec, StandardLinkCodecDecodedResponse };
61
+ export type { RPCLinkCodecOptions };
@@ -1,11 +1,61 @@
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
+ 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';
6
8
 
7
- declare function toHttpPath(path: readonly string[]): HTTPPath;
8
- declare function toStandardHeaders(headers: Headers | StandardHeaders): StandardHeaders;
9
- declare function getMalformedResponseErrorCode(status: number): string;
9
+ interface RPCLinkCodecOptions<T extends ClientContext> {
10
+ /**
11
+ * Base url for all requests (without origin). Should match with handler's prefix.
12
+ *
13
+ * @example '/rpc?base=1'
14
+ *
15
+ * @default '/'
16
+ */
17
+ url?: Value<Promisable<StandardUrl>, [options: ClientOptions<T>, path: string[], input: unknown]>;
18
+ /**
19
+ * The maximum length of the URL.
20
+ *
21
+ * 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.
22
+ *
23
+ * @default 2083
24
+ */
25
+ maxUrlLength?: Value<Promisable<number>, [options: ClientOptions<T>, path: string[], input: unknown]>;
26
+ /**
27
+ * The method used to make the request.
28
+ *
29
+ * @default 'POST'
30
+ */
31
+ method?: Value<Promisable<'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'>, [options: ClientOptions<T>, path: string[], input: unknown]>;
32
+ /**
33
+ * The method to use when the payload cannot safely pass to the server with method return from method function.
34
+ * GET is not allowed, it's very dangerous.
35
+ *
36
+ * @default 'POST'
37
+ */
38
+ fallbackMethod?: 'POST' | 'PUT' | 'PATCH' | 'DELETE';
39
+ /**
40
+ * Inject headers to the request.
41
+ */
42
+ headers?: Value<Promisable<StandardHeaders | Headers>, [options: ClientOptions<T>, path: string[], input: unknown]>;
43
+ /**
44
+ * Override the default RPC serializer.
45
+ */
46
+ serializer?: Pick<RPCSerializer, keyof RPCSerializer>;
47
+ }
48
+ declare class RPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
49
+ private readonly baseUrl;
50
+ private readonly maxUrlLength;
51
+ private readonly fallbackMethod;
52
+ private readonly expectedMethod;
53
+ private readonly headers;
54
+ private readonly serializer;
55
+ constructor(options: RPCLinkCodecOptions<T>);
56
+ encodeInput(input: unknown, path: string[], options: ClientOptions<T>): Promise<StandardRequest>;
57
+ decodeResponse(response: StandardLazyResponse): Promise<StandardLinkCodecDecodedResponse>;
58
+ }
10
59
 
11
- export { getMalformedResponseErrorCode, toHttpPath, toStandardHeaders };
60
+ export { RPCLinkCodec, StandardLinkCodec, StandardLinkCodecDecodedResponse };
61
+ 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.BN52ep3E.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.D3TIIok6.mjs';