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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/dist/adapters/fetch/index.d.ts +3 -2
  2. package/dist/adapters/fetch/index.js +2 -2
  3. package/dist/adapters/fetch/rpc-link.d.ts +8 -8
  4. package/dist/adapters/fetch/rpc-link.js +16 -13
  5. package/dist/adapters/fetch/transport.d.ts +29 -31
  6. package/dist/adapters/fetch/transport.js +49 -63
  7. package/dist/adapters/message-port/index.d.ts +4 -3
  8. package/dist/adapters/message-port/index.js +3 -3
  9. package/dist/adapters/message-port/message-port.d.ts +13 -13
  10. package/dist/adapters/message-port/message-port.js +35 -53
  11. package/dist/adapters/message-port/rpc-link.d.ts +8 -8
  12. package/dist/adapters/message-port/rpc-link.js +17 -14
  13. package/dist/adapters/message-port/transport.d.ts +31 -34
  14. package/dist/adapters/message-port/transport.js +38 -52
  15. package/dist/adapters/standard/codec.d.ts +10 -10
  16. package/dist/adapters/standard/index.d.ts +6 -5
  17. package/dist/adapters/standard/index.js +2 -4
  18. package/dist/adapters/standard/link.d.ts +31 -31
  19. package/dist/adapters/standard/link.js +101 -85
  20. package/dist/adapters/standard/plugin.d.ts +25 -31
  21. package/dist/adapters/standard/plugin.js +14 -16
  22. package/dist/adapters/standard/rpc-link-codec.d.ts +53 -60
  23. package/dist/adapters/standard/rpc-link-codec.js +98 -102
  24. package/dist/adapters/standard/transport.d.ts +7 -7
  25. package/dist/adapters/websocket/index.d.ts +3 -2
  26. package/dist/adapters/websocket/index.js +2 -2
  27. package/dist/adapters/websocket/rpc-link.d.ts +8 -8
  28. package/dist/adapters/websocket/rpc-link.js +16 -13
  29. package/dist/adapters/websocket/transport.d.ts +101 -100
  30. package/dist/adapters/websocket/transport.js +102 -130
  31. package/dist/async-iterator-object.d.ts +2 -2
  32. package/dist/async-iterator-object.js +27 -28
  33. package/dist/client-safe.d.ts +4 -6
  34. package/dist/client-safe.js +29 -34
  35. package/dist/client.d.ts +24 -26
  36. package/dist/client.js +35 -37
  37. package/dist/consts.d.ts +1 -1
  38. package/dist/consts.js +18 -41
  39. package/dist/dynamic-link.d.ts +6 -6
  40. package/dist/dynamic-link.js +16 -16
  41. package/dist/error-utils.d.ts +3 -4
  42. package/dist/error-utils.js +47 -51
  43. package/dist/error.d.ts +79 -79
  44. package/dist/error.js +154 -166
  45. package/dist/index.d.ts +14 -53
  46. package/dist/index.js +12 -40
  47. package/dist/plugins/batch.d.ts +122 -155
  48. package/dist/plugins/batch.js +320 -391
  49. package/dist/plugins/cookie-jar.d.ts +64 -61
  50. package/dist/plugins/cookie-jar.js +208 -245
  51. package/dist/plugins/dedupe.d.ts +49 -53
  52. package/dist/plugins/dedupe.js +168 -211
  53. package/dist/plugins/index.d.ts +9 -28
  54. package/dist/plugins/index.js +8 -23
  55. package/dist/plugins/request-compression.d.ts +38 -35
  56. package/dist/plugins/request-compression.js +131 -177
  57. package/dist/plugins/response-compression.d.ts +21 -18
  58. package/dist/plugins/response-compression.js +64 -88
  59. package/dist/plugins/retry-after.d.ts +31 -38
  60. package/dist/plugins/retry-after.js +60 -85
  61. package/dist/plugins/retry.d.ts +55 -55
  62. package/dist/plugins/retry.js +118 -137
  63. package/dist/plugins/timeout.d.ts +19 -17
  64. package/dist/plugins/timeout.js +41 -36
  65. package/dist/rpc-json-serializer.d.ts +84 -84
  66. package/dist/rpc-json-serializer.js +338 -383
  67. package/dist/rpc-serializer.d.ts +20 -21
  68. package/dist/rpc-serializer.js +97 -125
  69. package/dist/types.d.ts +19 -31
  70. package/dist/utils.d.ts +18 -29
  71. package/dist/utils.js +63 -47
  72. package/package.json +5 -5
  73. package/dist/adapters/standard/codec.js +0 -1
  74. package/dist/adapters/standard/transport.js +0 -1
  75. package/dist/types.js +0 -1
@@ -1,2 +1,3 @@
1
- export * from './rpc-link.ts';
2
- export * from './transport.ts';
1
+ import { RPCLink, RPCLinkOptions } from "./rpc-link.js";
2
+ import { FetchLinkTransport, FetchLinkTransportOptions } from "./transport.js";
3
+ export { FetchLinkTransport, FetchLinkTransportOptions, RPCLink, RPCLinkOptions };
@@ -1,2 +1,2 @@
1
- export * from './rpc-link.js';
2
- export * from './transport.js';
1
+ export { RPCLink } from "./rpc-link.js";
2
+ export { FetchLinkTransport } from "./transport.js";
@@ -1,14 +1,14 @@
1
- import type { ClientContext } from '../../types.ts';
2
- import type { RPCLinkCodecOptions, StandardLinkOptions } from '../standard/index.ts';
3
- import { StandardLink } from '../standard/index.ts';
4
- import type { FetchLinkTransportOptions } from './transport.ts';
5
- export interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, FetchLinkTransportOptions<T>, RPCLinkCodecOptions<T> {
6
- }
1
+ import { ClientContext } from "../../types.js";
2
+ import { StandardLink, StandardLinkOptions } from "../standard/link.js";
3
+ import { RPCLinkCodecOptions } from "../standard/rpc-link-codec.js";
4
+ import "../standard/index.js";
5
+ import { FetchLinkTransportOptions } from "./transport.js";
6
+ export interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, FetchLinkTransportOptions<T>, RPCLinkCodecOptions<T> {}
7
7
  /**
8
8
  * Client link that communicates with an RPC Handler over the Fetch API (HTTP).
9
9
  *
10
10
  * @see {@link https://orpc.dev/docs/adapters/fetch-api | Fetch API Adapter}
11
11
  */
12
12
  export declare class RPCLink<T extends ClientContext> extends StandardLink<T> {
13
- constructor(options: RPCLinkOptions<T>);
14
- }
13
+ constructor(options: RPCLinkOptions<T>);
14
+ }
@@ -1,14 +1,17 @@
1
- import { RPCLinkCodec, StandardLink } from '../standard/index.js';
2
- import { FetchLinkTransport } from './transport.js';
1
+ import { RPCLinkCodec } from "../standard/rpc-link-codec.js";
2
+ import { StandardLink } from "../standard/link.js";
3
+ import { FetchLinkTransport } from "./transport.js";
4
+ // src/adapters/fetch/rpc-link.ts
3
5
  /**
4
- * Client link that communicates with an RPC Handler over the Fetch API (HTTP).
5
- *
6
- * @see {@link https://orpc.dev/docs/adapters/fetch-api | Fetch API Adapter}
7
- */
8
- export class RPCLink extends StandardLink {
9
- constructor(options) {
10
- const codec = new RPCLinkCodec(options);
11
- const transport = new FetchLinkTransport(options);
12
- super(codec, transport, options);
13
- }
14
- }
6
+ * Client link that communicates with an RPC Handler over the Fetch API (HTTP).
7
+ *
8
+ * @see {@link https://orpc.dev/docs/adapters/fetch-api | Fetch API Adapter}
9
+ */
10
+ var RPCLink = class extends StandardLink {
11
+ constructor(options) {
12
+ const codec = new RPCLinkCodec(options);
13
+ const transport = new FetchLinkTransport(options);
14
+ super(codec, transport, options);
15
+ }
16
+ };
17
+ export { RPCLink };
@@ -1,34 +1,32 @@
1
- import type { Promisable, Value } from '@orpc/shared';
2
- import type { StandardLazyResponse, StandardRequest } from '@standard-server/core';
3
- import type { ToFetchBodyOptions } from '@standard-server/fetch';
4
- import type { ClientContext, ClientOptions } from '../../types.ts';
5
- import type { StandardLinkTransport } from '../standard/index.ts';
1
+ import { ClientContext, ClientOptions } from "../../types.js";
2
+ import { StandardLinkTransport } from "../standard/transport.js";
3
+ import "../standard/index.js";
4
+ import { Promisable, Value } from "@orpc/shared";
5
+ import { StandardLazyResponse, StandardRequest } from "@standard-server/core";
6
+ import { ToFetchBodyOptions } from "@standard-server/fetch";
6
7
  export interface FetchLinkTransportOptions<T extends ClientContext> {
7
- /**
8
- * The origin to prepend to all request URLs, useful for CORS requests.
9
- *
10
- * @example 'https://api.example.com'
11
- * @example 'http://localhost:3000'
12
- */
13
- origin?: Value<Promisable<`https://${string}` | `http://${string}` | ({} & string) | undefined>, [
14
- options: ClientOptions<T>,
15
- path: string[]
16
- ]> | undefined;
17
- /**
18
- * Options for how to convert the Standard Request to a Fetch Request, like event stream options, etc.
19
- */
20
- toFetchRequest?: ToFetchBodyOptions | undefined;
21
- /**
22
- * Override the default fetch implementation.
23
- *
24
- * @default (url, init) => globalThis.fetch(url, init)
25
- */
26
- fetch?(url: string, init: RequestInit, options: ClientOptions<T>, path: string[]): Promise<Response>;
8
+ /**
9
+ * The origin to prepend to all request URLs, useful for CORS requests.
10
+ *
11
+ * @example 'https://api.example.com'
12
+ * @example 'http://localhost:3000'
13
+ */
14
+ origin?: Value<Promisable<`https://${string}` | `http://${string}` | ({} & string) | undefined>, [options: ClientOptions<T>, path: string[]]> | undefined;
15
+ /**
16
+ * Options for how to convert the Standard Request to a Fetch Request, like event stream options, etc.
17
+ */
18
+ toFetchRequest?: ToFetchBodyOptions | undefined;
19
+ /**
20
+ * Override the default fetch implementation.
21
+ *
22
+ * @default (url, init) => globalThis.fetch(url, init)
23
+ */
24
+ fetch?(url: string, init: RequestInit, options: ClientOptions<T>, path: string[]): Promise<Response>;
27
25
  }
28
26
  export declare class FetchLinkTransport<T extends ClientContext> implements StandardLinkTransport<T> {
29
- private readonly origin;
30
- private readonly fetch;
31
- private readonly toFetchRequestOptions;
32
- constructor(options: FetchLinkTransportOptions<T>);
33
- send(standardRequest: StandardRequest, path: string[], options: ClientOptions<T>): Promise<StandardLazyResponse>;
34
- }
27
+ private readonly origin;
28
+ private readonly fetch;
29
+ private readonly toFetchRequestOptions;
30
+ constructor(options: FetchLinkTransportOptions<T>);
31
+ send(standardRequest: StandardRequest, path: string[], options: ClientOptions<T>): Promise<StandardLazyResponse>;
32
+ }
@@ -1,65 +1,51 @@
1
- import { once, value } from '@orpc/shared';
2
- import { toFetchBody, toFetchHeaders, toStandardLazyResponse } from '@standard-server/fetch';
1
+ import { once, value } from "@orpc/shared";
2
+ import { toFetchBody, toFetchHeaders, toStandardLazyResponse } from "@standard-server/fetch";
3
+ // src/adapters/fetch/transport.ts
3
4
  const GET_SUPPORTED_DUPLEX_MODE = /* @__PURE__ */ once(() => {
4
- // TODO: Try `duplex: 'full'` when it is widely supported.
5
- try {
6
- let duplex;
7
- void new Request('https://example.com', {
8
- method: 'POST',
9
- body: new ReadableStream(),
10
- get duplex() {
11
- duplex = 'half';
12
- return 'half';
13
- },
14
- });
15
- return duplex;
16
- }
17
- catch {
18
- return undefined;
19
- }
5
+ try {
6
+ let duplex;
7
+ new Request("https://example.com", {
8
+ method: "POST",
9
+ body: new ReadableStream(),
10
+ get duplex() {
11
+ duplex = "half";
12
+ return "half";
13
+ }
14
+ });
15
+ return duplex;
16
+ } catch {
17
+ return;
18
+ }
20
19
  });
21
- export class FetchLinkTransport {
22
- origin;
23
- fetch;
24
- toFetchRequestOptions;
25
- constructor(options) {
26
- this.origin = options.origin;
27
- // Resolve `globalThis.fetch` lazily so interception tools (msw, undici MockAgent, etc.)
28
- // that patch it after this transport is constructed still take effect.
29
- this.fetch = options.fetch ?? ((url, init) => globalThis.fetch(url, init));
30
- this.toFetchRequestOptions = options.toFetchRequest;
31
- }
32
- async send(standardRequest, path, options) {
33
- let origin = await value(this.origin, options, path);
34
- if (origin?.endsWith('/')) {
35
- origin = origin.slice(0, -1);
36
- }
37
- const url = `${origin ?? ''}${standardRequest.url}`;
38
- const [body, standardHeaders] = toFetchBody(standardRequest.body, standardRequest.headers, this.toFetchRequestOptions);
39
- const init = {
40
- body,
41
- headers: toFetchHeaders(standardHeaders),
42
- method: standardRequest.method,
43
- signal: options.signal,
44
- };
45
- if (body instanceof ReadableStream) {
46
- const duplex = GET_SUPPORTED_DUPLEX_MODE();
47
- if (duplex !== undefined) {
48
- init.duplex = duplex;
49
- }
50
- }
51
- // Call without a receiver: browsers throw "Illegal invocation" when native `fetch` is called on a non-global `this`.
52
- const fetch = this.fetch;
53
- const response = await fetch(url, init, options, path);
54
- // Opaque responses (status 0, no headers or body) would otherwise decode as a successful empty output.
55
- // Browsers return them for redirects under `redirect: 'manual'` and for cross-origin `no-cors` requests.
56
- if (response.type === 'opaqueredirect') {
57
- throw new TypeError("Unexpected opaque redirect response: browsers hide redirects under `redirect: 'manual'`.");
58
- }
59
- if (response.type === 'opaque') {
60
- throw new TypeError('Unexpected opaque response: the response is unreadable, likely due to a no-cors request.');
61
- }
62
- const standardResponse = toStandardLazyResponse(response);
63
- return standardResponse;
64
- }
65
- }
20
+ var FetchLinkTransport = class {
21
+ origin;
22
+ fetch;
23
+ toFetchRequestOptions;
24
+ constructor(options) {
25
+ this.origin = options.origin;
26
+ this.fetch = options.fetch ?? ((url, init) => globalThis.fetch(url, init));
27
+ this.toFetchRequestOptions = options.toFetchRequest;
28
+ }
29
+ async send(standardRequest, path, options) {
30
+ let origin = await value(this.origin, options, path);
31
+ if (origin?.endsWith("/")) origin = origin.slice(0, -1);
32
+ const url = `${origin ?? ""}${standardRequest.url}`;
33
+ const [body, standardHeaders] = toFetchBody(standardRequest.body, standardRequest.headers, this.toFetchRequestOptions);
34
+ const init = {
35
+ body,
36
+ headers: toFetchHeaders(standardHeaders),
37
+ method: standardRequest.method,
38
+ signal: options.signal
39
+ };
40
+ if (body instanceof ReadableStream) {
41
+ const duplex = GET_SUPPORTED_DUPLEX_MODE();
42
+ if (duplex !== void 0) init.duplex = duplex;
43
+ }
44
+ const fetch = this.fetch;
45
+ const response = await fetch(url, init, options, path);
46
+ if (response.type === "opaqueredirect") throw new TypeError("Unexpected opaque redirect response: browsers hide redirects under `redirect: 'manual'`.");
47
+ if (response.type === "opaque") throw new TypeError("Unexpected opaque response: the response is unreadable, likely due to a no-cors request.");
48
+ return toStandardLazyResponse(response);
49
+ }
50
+ };
51
+ export { FetchLinkTransport };
@@ -1,3 +1,4 @@
1
- export * from './message-port.ts';
2
- export * from './rpc-link.ts';
3
- export * from './transport.ts';
1
+ import { BrowserPortLike, MessagePortMainLike, SupportedMessagePort, SupportedMessagePortData, onMessagePortClose, onMessagePortMessage, postMessagePortMessage } from "./message-port.js";
2
+ import { RPCLink, RPCLinkOptions } from "./rpc-link.js";
3
+ import { MessagePortLinkTransport, MessagePortLinkTransportOptions } from "./transport.js";
4
+ export { BrowserPortLike, MessagePortLinkTransport, MessagePortLinkTransportOptions, MessagePortMainLike, RPCLink, RPCLinkOptions, SupportedMessagePort, SupportedMessagePortData, onMessagePortClose, onMessagePortMessage, postMessagePortMessage };
@@ -1,3 +1,3 @@
1
- export * from './message-port.js';
2
- export * from './rpc-link.js';
3
- export * from './transport.js';
1
+ export { onMessagePortClose, onMessagePortMessage, postMessagePortMessage } from "./message-port.js";
2
+ export { RPCLink } from "./rpc-link.js";
3
+ export { MessagePortLinkTransport } from "./transport.js";
@@ -2,28 +2,28 @@
2
2
  * The message port used by electron in main process
3
3
  */
4
4
  export interface MessagePortMainLike {
5
- on: <T extends string>(event: T, callback: (event?: {
6
- data: any;
7
- }) => void) => void;
8
- postMessage: (data: any, transfer?: any[]) => void;
5
+ on: <T extends string>(event: T, callback: (event?: {
6
+ data: any;
7
+ }) => void) => void;
8
+ postMessage: (data: any, transfer?: any[]) => void;
9
9
  }
10
10
  /**
11
11
  * The message port used by browser extension
12
12
  */
13
13
  export interface BrowserPortLike {
14
- onMessage: {
15
- addListener: (callback: (data: any) => void) => void;
16
- };
17
- onDisconnect: {
18
- addListener: (callback: () => void) => void;
19
- };
20
- postMessage: (data: any) => void;
14
+ onMessage: {
15
+ addListener: (callback: (data: any) => void) => void;
16
+ };
17
+ onDisconnect: {
18
+ addListener: (callback: () => void) => void;
19
+ };
20
+ postMessage: (data: any) => void;
21
21
  }
22
- export type SupportedMessagePort = Pick<MessagePort, 'addEventListener' | 'postMessage'> | MessagePortMainLike | BrowserPortLike;
22
+ export type SupportedMessagePort = Pick<MessagePort, "addEventListener" | "postMessage"> | MessagePortMainLike | BrowserPortLike;
23
23
  /**
24
24
  * Message port can support [The structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm)
25
25
  */
26
26
  export type SupportedMessagePortData = any;
27
27
  export declare function postMessagePortMessage(port: SupportedMessagePort, data: SupportedMessagePortData, transfer?: any[]): void;
28
28
  export declare function onMessagePortMessage(port: SupportedMessagePort, callback: (data: SupportedMessagePortData) => void): void;
29
- export declare function onMessagePortClose(port: SupportedMessagePort, callback: () => void): void;
29
+ export declare function onMessagePortClose(port: SupportedMessagePort, callback: () => void): void;
@@ -1,56 +1,38 @@
1
- export function postMessagePortMessage(port, data, transfer) {
2
- if (transfer) {
3
- port.postMessage(data, transfer);
4
- }
5
- else {
6
- port.postMessage(data);
7
- }
1
+ // src/adapters/message-port/message-port.ts
2
+ function postMessagePortMessage(port, data, transfer) {
3
+ if (transfer) port.postMessage(data, transfer);
4
+ else port.postMessage(data);
8
5
  }
9
- export function onMessagePortMessage(port, callback) {
10
- /**
11
- * MessagePort in node.js might have "on" method but it pass different parameters vs MessagePortMainLike
12
- * So we need check "addEventListener" before "on"
13
- */
14
- if ('addEventListener' in port) {
15
- port.addEventListener('message', (event) => {
16
- callback(event.data);
17
- });
18
- }
19
- else if ('on' in port) {
20
- port.on('message', (event) => {
21
- callback(event?.data);
22
- });
23
- }
24
- else if ('onMessage' in port) {
25
- port.onMessage.addListener((data) => {
26
- callback(data);
27
- });
28
- }
29
- else {
30
- throw new Error('Cannot find a addEventListener/on/onMessage method on the port');
31
- }
6
+ function onMessagePortMessage(port, callback) {
7
+ /**
8
+ * MessagePort in node.js might have "on" method but it pass different parameters vs MessagePortMainLike
9
+ * So we need check "addEventListener" before "on"
10
+ */
11
+ if ("addEventListener" in port) port.addEventListener("message", (event) => {
12
+ callback(event.data);
13
+ });
14
+ else if ("on" in port) port.on("message", (event) => {
15
+ callback(event?.data);
16
+ });
17
+ else if ("onMessage" in port) port.onMessage.addListener((data) => {
18
+ callback(data);
19
+ });
20
+ else throw new Error("Cannot find a addEventListener/on/onMessage method on the port");
32
21
  }
33
- export function onMessagePortClose(port, callback) {
34
- /**
35
- * MessagePort in node.js might have "on" method but it pass different parameters vs MessagePortMainLike
36
- * So we need check "addEventListener" before "on"
37
- */
38
- if ('addEventListener' in port) {
39
- port.addEventListener('close', () => {
40
- callback();
41
- });
42
- }
43
- else if ('on' in port) {
44
- port.on('close', () => {
45
- callback();
46
- });
47
- }
48
- else if ('onDisconnect' in port) {
49
- port.onDisconnect.addListener(() => {
50
- callback();
51
- });
52
- }
53
- else {
54
- throw new Error('Cannot find a addEventListener/on/onDisconnect method on the port');
55
- }
22
+ function onMessagePortClose(port, callback) {
23
+ /**
24
+ * MessagePort in node.js might have "on" method but it pass different parameters vs MessagePortMainLike
25
+ * So we need check "addEventListener" before "on"
26
+ */
27
+ if ("addEventListener" in port) port.addEventListener("close", () => {
28
+ callback();
29
+ });
30
+ else if ("on" in port) port.on("close", () => {
31
+ callback();
32
+ });
33
+ else if ("onDisconnect" in port) port.onDisconnect.addListener(() => {
34
+ callback();
35
+ });
36
+ else throw new Error("Cannot find a addEventListener/on/onDisconnect method on the port");
56
37
  }
38
+ export { onMessagePortClose, onMessagePortMessage, postMessagePortMessage };
@@ -1,9 +1,9 @@
1
- import type { ClientContext } from '../../types.ts';
2
- import type { RPCLinkCodecOptions, StandardLinkOptions } from '../standard/index.ts';
3
- import { StandardLink } from '../standard/index.ts';
4
- import type { MessagePortLinkTransportOptions } from './transport.ts';
5
- export interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, MessagePortLinkTransportOptions<T>, RPCLinkCodecOptions<T> {
6
- }
1
+ import { ClientContext } from "../../types.js";
2
+ import { StandardLink, StandardLinkOptions } from "../standard/link.js";
3
+ import { RPCLinkCodecOptions } from "../standard/rpc-link-codec.js";
4
+ import "../standard/index.js";
5
+ import { MessagePortLinkTransportOptions } from "./transport.js";
6
+ export interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, MessagePortLinkTransportOptions<T>, RPCLinkCodecOptions<T> {}
7
7
  /**
8
8
  * Client link that communicates with an RPC Handler over a Message Port
9
9
  * (e.g. workers, iframes, browser extensions, Electron).
@@ -11,5 +11,5 @@ export interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOpt
11
11
  * @see {@link https://orpc.dev/docs/adapters/message-port | Message Port Adapter}
12
12
  */
13
13
  export declare class RPCLink<T extends ClientContext> extends StandardLink<T> {
14
- constructor(options: RPCLinkOptions<T>);
15
- }
14
+ constructor(options: RPCLinkOptions<T>);
15
+ }
@@ -1,15 +1,18 @@
1
- import { RPCLinkCodec, StandardLink } from '../standard/index.js';
2
- import { MessagePortLinkTransport } from './transport.js';
1
+ import { RPCLinkCodec } from "../standard/rpc-link-codec.js";
2
+ import { StandardLink } from "../standard/link.js";
3
+ import { MessagePortLinkTransport } from "./transport.js";
4
+ // src/adapters/message-port/rpc-link.ts
3
5
  /**
4
- * Client link that communicates with an RPC Handler over a Message Port
5
- * (e.g. workers, iframes, browser extensions, Electron).
6
- *
7
- * @see {@link https://orpc.dev/docs/adapters/message-port | Message Port Adapter}
8
- */
9
- export class RPCLink extends StandardLink {
10
- constructor(options) {
11
- const codec = new RPCLinkCodec(options);
12
- const transport = new MessagePortLinkTransport(options);
13
- super(codec, transport, options);
14
- }
15
- }
6
+ * Client link that communicates with an RPC Handler over a Message Port
7
+ * (e.g. workers, iframes, browser extensions, Electron).
8
+ *
9
+ * @see {@link https://orpc.dev/docs/adapters/message-port | Message Port Adapter}
10
+ */
11
+ var RPCLink = class extends StandardLink {
12
+ constructor(options) {
13
+ const codec = new RPCLinkCodec(options);
14
+ const transport = new MessagePortLinkTransport(options);
15
+ super(codec, transport, options);
16
+ }
17
+ };
18
+ export { RPCLink };
@@ -1,38 +1,35 @@
1
- import type { Promisable, Value } from '@orpc/shared';
2
- import type { StandardLazyResponse, StandardRequest } from '@standard-server/core';
3
- import type { DecodePeerMessageOptions, EncodePeerMessageOptions } from '@standard-server/peer';
4
- import { ClientPeer } from '@standard-server/peer';
5
- import type { ClientContext, ClientOptions } from '../../types.ts';
6
- import type { StandardLinkTransport } from '../standard/index.ts';
7
- import type { SupportedMessagePort } from './message-port.ts';
8
- type DecodedRequestMessage = ConstructorParameters<typeof ClientPeer>[0] extends (message: infer TMessage) => unknown ? TMessage : never;
1
+ import { ClientContext, ClientOptions } from "../../types.js";
2
+ import { StandardLinkTransport } from "../standard/transport.js";
3
+ import "../standard/index.js";
4
+ import { SupportedMessagePort } from "./message-port.js";
5
+ import { Promisable, Value } from "@orpc/shared";
6
+ import { StandardLazyResponse, StandardRequest } from "@standard-server/core";
7
+ import { ClientPeer, DecodePeerMessageOptions, EncodePeerMessageOptions } from "@standard-server/peer";
8
+ type DecodedRequestMessage = ConstructorParameters<typeof ClientPeer>[0] extends ((message: infer TMessage) => unknown) ? TMessage : never;
9
9
  export interface MessagePortLinkTransportOptions<_T extends ClientContext> {
10
- port: SupportedMessagePort;
11
- /**
12
- * By default, oRPC serializes request/response messages to string/binary data before sending over message port.
13
- * If needed, define this option to utilize full power of [MessagePort: postMessage() method](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort/postMessage),
14
- * such as transferring ownership of objects to the other side or support unserializable objects like `OffscreenCanvas`.
15
- *
16
- * @remarks
17
- * **Note**: Returning `null` or `undefined` disables this feature.
18
- * **Warning**: Make sure your message port supports `transfer` before using this feature.
19
- */
20
- experimental_transfer?: Value<Promisable<object[] | null | undefined>, [
21
- message: DecodedRequestMessage,
22
- port: SupportedMessagePort
23
- ]> | undefined;
24
- /**
25
- * Options for encoding peer messages. such as `prefix` for distinguishing messages on the same channel..
26
- */
27
- encodePeerMessage?: EncodePeerMessageOptions | undefined;
28
- /**
29
- * Options for decoding peer messages, such as `prefix` for distinguishing messages on the same channel.
30
- */
31
- decodePeerMessage?: DecodePeerMessageOptions | undefined;
10
+ port: SupportedMessagePort;
11
+ /**
12
+ * By default, oRPC serializes request/response messages to string/binary data before sending over message port.
13
+ * If needed, define this option to utilize full power of [MessagePort: postMessage() method](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort/postMessage),
14
+ * such as transferring ownership of objects to the other side or support unserializable objects like `OffscreenCanvas`.
15
+ *
16
+ * @remarks
17
+ * **Note**: Returning `null` or `undefined` disables this feature.
18
+ * **Warning**: Make sure your message port supports `transfer` before using this feature.
19
+ */
20
+ experimental_transfer?: Value<Promisable<object[] | null | undefined>, [message: DecodedRequestMessage, port: SupportedMessagePort]> | undefined;
21
+ /**
22
+ * Options for encoding peer messages. such as `prefix` for distinguishing messages on the same channel..
23
+ */
24
+ encodePeerMessage?: EncodePeerMessageOptions | undefined;
25
+ /**
26
+ * Options for decoding peer messages, such as `prefix` for distinguishing messages on the same channel.
27
+ */
28
+ decodePeerMessage?: DecodePeerMessageOptions | undefined;
32
29
  }
33
30
  export declare class MessagePortLinkTransport<T extends ClientContext> implements StandardLinkTransport<T> {
34
- private readonly peer;
35
- constructor({ port, experimental_transfer, encodePeerMessage: encodePeerMessageOptions, decodePeerMessage: decodePeerMessageOptions, }: MessagePortLinkTransportOptions<T>);
36
- send(standardRequest: StandardRequest, _path: string[], _options: ClientOptions<T>): Promise<StandardLazyResponse>;
31
+ private readonly peer;
32
+ constructor({ port, experimental_transfer, encodePeerMessage: encodePeerMessageOptions, decodePeerMessage: decodePeerMessageOptions }: MessagePortLinkTransportOptions<T>);
33
+ send(standardRequest: StandardRequest, _path: string[], _options: ClientOptions<T>): Promise<StandardLazyResponse>;
37
34
  }
38
- export {};
35
+ export {};