@orpc/client 0.0.0-next.d16a1b6 → 0.0.0-next.d177d36

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.
package/README.md CHANGED
@@ -21,28 +21,24 @@
21
21
 
22
22
  <h3 align="center">Typesafe APIs Made Simple 🪄</h3>
23
23
 
24
- **oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards, ensuring a smooth and enjoyable developer experience.
24
+ **oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards
25
25
 
26
26
  ---
27
27
 
28
28
  ## Highlights
29
29
 
30
- - **End-to-End Type Safety 🔒**: Ensure complete type safety from inputs to outputs and errors, bridging server and client seamlessly.
31
- - **First-Class OpenAPI 📄**: Adheres to the OpenAPI standard out of the box, ensuring seamless integration and comprehensive API documentation.
32
- - **Contract-First Development 📜**: (Optional) Define your API contract upfront and implement it with confidence.
33
- - **Exceptional Developer Experience ✨**: Enjoy a streamlined workflow with robust typing and clear, in-code documentation.
34
- - **Multi-Runtime Support 🌍**: Run your code seamlessly on Cloudflare, Deno, Bun, Node.js, and more.
35
- - **Framework Integrations 🧩**: Supports Tanstack Query (React, Vue), Pinia Colada, and more.
36
- - **Server Actions ⚡️**: Fully compatible with React Server Actions on Next.js, TanStack Start, and more.
37
- - **Standard Schema Support 🗂️**: Effortlessly work with Zod, Valibot, ArkType, and others right out of the box.
38
- - **Fast & Lightweight 💨**: Built on native APIs across all runtimes – optimized for speed and efficiency.
39
- - **Native Types 📦**: Enjoy built-in support for Date, File, Blob, BigInt, URL and more with no extra setup.
40
- - **Lazy Router ⏱️**: Improve cold start times with our lazy routing feature.
41
- - **SSE & Streaming 📡**: Provides SSE and streaming features – perfect for real-time notifications and AI-powered streaming responses.
42
- - **Reusability 🔄**: Write once and reuse your code across multiple purposes effortlessly.
43
- - **Extendability 🔌**: Easily enhance oRPC with plugins, middleware, and interceptors.
44
- - **Reliability 🛡️**: Well-tested, fully TypeScript, production-ready, and MIT licensed for peace of mind.
45
- - **Simplicity 💡**: Enjoy straightforward, clean code with no hidden magic.
30
+ - **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
31
+ - **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
32
+ - **📝 Contract-First Development**: Optionally define your API contract before implementation.
33
+ - **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte), Pinia Colada, and more.
34
+ - **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
35
+ - **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
36
+ - **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
37
+ - **⏱️ Lazy Router**: Enhance cold start times with our lazy routing feature.
38
+ - **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
39
+ - **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
40
+ - **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
41
+ - **🛡️ Reliability**: Well-tested, TypeScript-based, production-ready, and MIT licensed.
46
42
 
47
43
  ## Documentation
48
44
 
@@ -53,11 +49,17 @@ You can find the full documentation [here](https://orpc.unnoq.com).
53
49
  - [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
54
50
  - [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
55
51
  - [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
52
+ - [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with NestJS.
53
+ - [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
56
54
  - [@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
57
55
  - [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
56
+ - [@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
57
+ - [@orpc/svelte-query](https://www.npmjs.com/package/@orpc/svelte-query): Integration with [Svelte Query](https://tanstack.com/query/latest/docs/framework/svelte/overview).
58
58
  - [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
59
59
  - [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
60
60
  - [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
61
+ - [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
62
+ - [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
61
63
 
62
64
  ## `@orpc/client`
63
65
 
@@ -83,6 +85,14 @@ const client: RouterClient<typeof router> = createORPCClient(link)
83
85
  const client: ContractRouterClient<typeof contract> = createORPCClient(link)
84
86
  ```
85
87
 
88
+ ## Sponsors
89
+
90
+ <p align="center">
91
+ <a href="https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg">
92
+ <img src='https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg'/>
93
+ </a>
94
+ </p>
95
+
86
96
  ## License
87
97
 
88
98
  Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
@@ -1,29 +1,33 @@
1
- import { C as ClientContext, a as ClientOptionsOut, b as ClientLink } from '../../shared/client.D_CzLDyB.mjs';
2
- import { StandardLinkClient, StandardLinkOptions, StandardRPCLinkCodecOptions, StandardRPCLinkCodec } from '../standard/index.mjs';
3
1
  import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
2
+ import { ToFetchRequestOptions } from '@orpc/standard-server-fetch';
3
+ import { a as ClientContext, b as ClientOptions } from '../../shared/client.4TS_0JaO.mjs';
4
+ import { f as StandardLinkClient } from '../../shared/client.BMoG_EdN.mjs';
5
+ import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.BdD8cpjs.mjs';
4
6
  import '@orpc/shared';
5
7
 
6
- interface LinkFetchClientOptions<T extends ClientContext> {
7
- fetch?: (request: Request, init: Record<never, never>, options: ClientOptionsOut<T>, path: readonly string[], input: unknown) => Promise<Response>;
8
+ interface LinkFetchClientOptions<T extends ClientContext> extends ToFetchRequestOptions {
9
+ fetch?: (request: Request, init: {
10
+ redirect?: Request['redirect'];
11
+ }, options: ClientOptions<T>, path: readonly string[], input: unknown) => Promise<Response>;
8
12
  }
9
13
  declare class LinkFetchClient<T extends ClientContext> implements StandardLinkClient<T> {
10
14
  private readonly fetch;
15
+ private readonly toFetchRequestOptions;
11
16
  constructor(options: LinkFetchClientOptions<T>);
12
- call(request: StandardRequest, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
17
+ call(request: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
13
18
  }
14
19
 
15
- interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardRPCLinkCodecOptions<T>, LinkFetchClientOptions<T> {
16
- linkCodec?: StandardRPCLinkCodec<T>;
17
- linkClient?: LinkFetchClient<T>;
20
+ interface RPCLinkOptions<T extends ClientContext> extends StandardRPCLinkOptions<T>, LinkFetchClientOptions<T> {
18
21
  }
19
- declare class RPCLink<T extends ClientContext> implements ClientLink<T> {
20
- private readonly standardLink;
22
+ /**
23
+ * The RPC Link communicates with the server using the RPC protocol.
24
+ *
25
+ * @see {@link https://orpc.unnoq.com/docs/client/rpc-link RPC Link Docs}
26
+ * @see {@link https://orpc.unnoq.com/docs/advanced/rpc-protocol RPC Protocol Docs}
27
+ */
28
+ declare class RPCLink<T extends ClientContext> extends StandardRPCLink<T> {
21
29
  constructor(options: RPCLinkOptions<T>);
22
- call(path: readonly string[], input: unknown, options: ClientOptionsOut<T>): Promise<unknown>;
23
30
  }
24
31
 
25
- interface FetchWithContext<TClientContext extends ClientContext> {
26
- (url: URL, init: RequestInit, options: ClientOptionsOut<TClientContext>, path: readonly string[], input: unknown): Promise<Response>;
27
- }
28
-
29
- export { type FetchWithContext, RPCLink, type RPCLinkOptions };
32
+ export { LinkFetchClient, RPCLink };
33
+ export type { LinkFetchClientOptions, RPCLinkOptions };
@@ -1,29 +1,33 @@
1
- import { C as ClientContext, a as ClientOptionsOut, b as ClientLink } from '../../shared/client.D_CzLDyB.js';
2
- import { StandardLinkClient, StandardLinkOptions, StandardRPCLinkCodecOptions, StandardRPCLinkCodec } from '../standard/index.js';
3
1
  import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
2
+ import { ToFetchRequestOptions } from '@orpc/standard-server-fetch';
3
+ import { a as ClientContext, b as ClientOptions } from '../../shared/client.4TS_0JaO.js';
4
+ import { f as StandardLinkClient } from '../../shared/client.C0KbSWlC.js';
5
+ import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.7UM0t5o-.js';
4
6
  import '@orpc/shared';
5
7
 
6
- interface LinkFetchClientOptions<T extends ClientContext> {
7
- fetch?: (request: Request, init: Record<never, never>, options: ClientOptionsOut<T>, path: readonly string[], input: unknown) => Promise<Response>;
8
+ interface LinkFetchClientOptions<T extends ClientContext> extends ToFetchRequestOptions {
9
+ fetch?: (request: Request, init: {
10
+ redirect?: Request['redirect'];
11
+ }, options: ClientOptions<T>, path: readonly string[], input: unknown) => Promise<Response>;
8
12
  }
9
13
  declare class LinkFetchClient<T extends ClientContext> implements StandardLinkClient<T> {
10
14
  private readonly fetch;
15
+ private readonly toFetchRequestOptions;
11
16
  constructor(options: LinkFetchClientOptions<T>);
12
- call(request: StandardRequest, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
17
+ call(request: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
13
18
  }
14
19
 
15
- interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardRPCLinkCodecOptions<T>, LinkFetchClientOptions<T> {
16
- linkCodec?: StandardRPCLinkCodec<T>;
17
- linkClient?: LinkFetchClient<T>;
20
+ interface RPCLinkOptions<T extends ClientContext> extends StandardRPCLinkOptions<T>, LinkFetchClientOptions<T> {
18
21
  }
19
- declare class RPCLink<T extends ClientContext> implements ClientLink<T> {
20
- private readonly standardLink;
22
+ /**
23
+ * The RPC Link communicates with the server using the RPC protocol.
24
+ *
25
+ * @see {@link https://orpc.unnoq.com/docs/client/rpc-link RPC Link Docs}
26
+ * @see {@link https://orpc.unnoq.com/docs/advanced/rpc-protocol RPC Protocol Docs}
27
+ */
28
+ declare class RPCLink<T extends ClientContext> extends StandardRPCLink<T> {
21
29
  constructor(options: RPCLinkOptions<T>);
22
- call(path: readonly string[], input: unknown, options: ClientOptionsOut<T>): Promise<unknown>;
23
30
  }
24
31
 
25
- interface FetchWithContext<TClientContext extends ClientContext> {
26
- (url: URL, init: RequestInit, options: ClientOptionsOut<TClientContext>, path: readonly string[], input: unknown): Promise<Response>;
27
- }
28
-
29
- export { type FetchWithContext, RPCLink, type RPCLinkOptions };
32
+ export { LinkFetchClient, RPCLink };
33
+ export type { LinkFetchClientOptions, RPCLinkOptions };
@@ -1,32 +1,29 @@
1
- import { a as StandardRPCLinkCodec, S as StandardLink } from '../../shared/client.MkoaGU3v.mjs';
1
+ import { toFetchRequest, toStandardLazyResponse } from '@orpc/standard-server-fetch';
2
2
  import '@orpc/shared';
3
+ import { c as StandardRPCLink } from '../../shared/client.DpICn1BD.mjs';
3
4
  import '@orpc/standard-server';
4
- import { toFetchRequest, toStandardLazyResponse } from '@orpc/standard-server-fetch';
5
- import '../../shared/client.DcaJQZfy.mjs';
5
+ import '../../shared/client.CRWEpqLB.mjs';
6
6
 
7
7
  class LinkFetchClient {
8
8
  fetch;
9
+ toFetchRequestOptions;
9
10
  constructor(options) {
10
11
  this.fetch = options?.fetch ?? globalThis.fetch.bind(globalThis);
12
+ this.toFetchRequestOptions = options;
11
13
  }
12
14
  async call(request, options, path, input) {
13
- const fetchRequest = toFetchRequest(request);
14
- const fetchResponse = await this.fetch(fetchRequest, {}, options, path, input);
15
+ const fetchRequest = toFetchRequest(request, this.toFetchRequestOptions);
16
+ const fetchResponse = await this.fetch(fetchRequest, { redirect: "manual" }, options, path, input);
15
17
  const lazyResponse = toStandardLazyResponse(fetchResponse);
16
18
  return lazyResponse;
17
19
  }
18
20
  }
19
21
 
20
- class RPCLink {
21
- standardLink;
22
+ class RPCLink extends StandardRPCLink {
22
23
  constructor(options) {
23
- const linkCodec = options.linkCodec ?? new StandardRPCLinkCodec(options);
24
- const linkClient = options.linkClient ?? new LinkFetchClient(options);
25
- this.standardLink = new StandardLink(linkCodec, linkClient, options);
26
- }
27
- async call(path, input, options) {
28
- return this.standardLink.call(path, input, options);
24
+ const linkClient = new LinkFetchClient(options);
25
+ super(linkClient, options);
29
26
  }
30
27
  }
31
28
 
32
- export { RPCLink };
29
+ export { LinkFetchClient, RPCLink };
@@ -0,0 +1,59 @@
1
+ import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
2
+ import { a as ClientContext, b as ClientOptions } from '../../shared/client.4TS_0JaO.mjs';
3
+ import { f as StandardLinkClient } from '../../shared/client.BMoG_EdN.mjs';
4
+ import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.BdD8cpjs.mjs';
5
+ import '@orpc/shared';
6
+
7
+ /**
8
+ * The message port used by electron in main process
9
+ */
10
+ interface MessagePortMainLike {
11
+ on: <T extends string>(event: T, callback: (event?: {
12
+ data: any;
13
+ }) => void) => void;
14
+ postMessage: (data: any) => void;
15
+ }
16
+ /**
17
+ * The message port used by browser extension
18
+ */
19
+ interface BrowserPortLike {
20
+ onMessage: {
21
+ addListener: (callback: (data: any) => void) => void;
22
+ };
23
+ onDisconnect: {
24
+ addListener: (callback: () => void) => void;
25
+ };
26
+ postMessage: (data: any) => void;
27
+ }
28
+ type SupportedMessagePort = Pick<MessagePort, 'addEventListener' | 'postMessage'> | MessagePortMainLike | BrowserPortLike;
29
+ /**
30
+ * Message port can support [The structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm)
31
+ */
32
+ type SupportedMessagePortData = string | ArrayBufferLike;
33
+ declare function postMessagePortMessage(port: SupportedMessagePort, data: SupportedMessagePortData): void;
34
+ declare function onMessagePortMessage(port: SupportedMessagePort, callback: (data: SupportedMessagePortData) => void): void;
35
+ declare function onMessagePortClose(port: SupportedMessagePort, callback: () => void): void;
36
+
37
+ interface experimental_LinkMessagePortClientOptions {
38
+ port: SupportedMessagePort;
39
+ }
40
+ declare class experimental_LinkMessagePortClient<T extends ClientContext> implements StandardLinkClient<T> {
41
+ private readonly peer;
42
+ constructor(options: experimental_LinkMessagePortClientOptions);
43
+ call(request: StandardRequest, _options: ClientOptions<T>, _path: readonly string[], _input: unknown): Promise<StandardLazyResponse>;
44
+ }
45
+
46
+ interface experimental_RPCLinkOptions<T extends ClientContext> extends Omit<StandardRPCLinkOptions<T>, 'url' | 'headers' | 'method' | 'fallbackMethod' | 'maxUrlLength'>, experimental_LinkMessagePortClientOptions {
47
+ }
48
+ /**
49
+ * The RPC Link for common message port implementations.
50
+ *
51
+ * @see {@link https://orpc.unnoq.com/docs/client/rpc-link RPC Link Docs}
52
+ * @see {@link https://orpc.unnoq.com/docs/adapters/message-port Message Port Adapter Docs}
53
+ */
54
+ declare class experimental_RPCLink<T extends ClientContext> extends StandardRPCLink<T> {
55
+ constructor(options: experimental_RPCLinkOptions<T>);
56
+ }
57
+
58
+ export { experimental_LinkMessagePortClient, experimental_RPCLink, onMessagePortClose, onMessagePortMessage, postMessagePortMessage };
59
+ export type { BrowserPortLike, MessagePortMainLike, SupportedMessagePort, SupportedMessagePortData, experimental_LinkMessagePortClientOptions, experimental_RPCLinkOptions };
@@ -0,0 +1,59 @@
1
+ import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
2
+ import { a as ClientContext, b as ClientOptions } from '../../shared/client.4TS_0JaO.js';
3
+ import { f as StandardLinkClient } from '../../shared/client.C0KbSWlC.js';
4
+ import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.7UM0t5o-.js';
5
+ import '@orpc/shared';
6
+
7
+ /**
8
+ * The message port used by electron in main process
9
+ */
10
+ interface MessagePortMainLike {
11
+ on: <T extends string>(event: T, callback: (event?: {
12
+ data: any;
13
+ }) => void) => void;
14
+ postMessage: (data: any) => void;
15
+ }
16
+ /**
17
+ * The message port used by browser extension
18
+ */
19
+ interface BrowserPortLike {
20
+ onMessage: {
21
+ addListener: (callback: (data: any) => void) => void;
22
+ };
23
+ onDisconnect: {
24
+ addListener: (callback: () => void) => void;
25
+ };
26
+ postMessage: (data: any) => void;
27
+ }
28
+ type SupportedMessagePort = Pick<MessagePort, 'addEventListener' | 'postMessage'> | MessagePortMainLike | BrowserPortLike;
29
+ /**
30
+ * Message port can support [The structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm)
31
+ */
32
+ type SupportedMessagePortData = string | ArrayBufferLike;
33
+ declare function postMessagePortMessage(port: SupportedMessagePort, data: SupportedMessagePortData): void;
34
+ declare function onMessagePortMessage(port: SupportedMessagePort, callback: (data: SupportedMessagePortData) => void): void;
35
+ declare function onMessagePortClose(port: SupportedMessagePort, callback: () => void): void;
36
+
37
+ interface experimental_LinkMessagePortClientOptions {
38
+ port: SupportedMessagePort;
39
+ }
40
+ declare class experimental_LinkMessagePortClient<T extends ClientContext> implements StandardLinkClient<T> {
41
+ private readonly peer;
42
+ constructor(options: experimental_LinkMessagePortClientOptions);
43
+ call(request: StandardRequest, _options: ClientOptions<T>, _path: readonly string[], _input: unknown): Promise<StandardLazyResponse>;
44
+ }
45
+
46
+ interface experimental_RPCLinkOptions<T extends ClientContext> extends Omit<StandardRPCLinkOptions<T>, 'url' | 'headers' | 'method' | 'fallbackMethod' | 'maxUrlLength'>, experimental_LinkMessagePortClientOptions {
47
+ }
48
+ /**
49
+ * The RPC Link for common message port implementations.
50
+ *
51
+ * @see {@link https://orpc.unnoq.com/docs/client/rpc-link RPC Link Docs}
52
+ * @see {@link https://orpc.unnoq.com/docs/adapters/message-port Message Port Adapter Docs}
53
+ */
54
+ declare class experimental_RPCLink<T extends ClientContext> extends StandardRPCLink<T> {
55
+ constructor(options: experimental_RPCLinkOptions<T>);
56
+ }
57
+
58
+ export { experimental_LinkMessagePortClient, experimental_RPCLink, onMessagePortClose, onMessagePortMessage, postMessagePortMessage };
59
+ export type { BrowserPortLike, MessagePortMainLike, SupportedMessagePort, SupportedMessagePortData, experimental_LinkMessagePortClientOptions, experimental_RPCLinkOptions };
@@ -0,0 +1,71 @@
1
+ import { ClientPeer } from '@orpc/standard-server-peer';
2
+ import '@orpc/shared';
3
+ import { c as StandardRPCLink } from '../../shared/client.DpICn1BD.mjs';
4
+ import '@orpc/standard-server';
5
+ import '../../shared/client.CRWEpqLB.mjs';
6
+
7
+ function postMessagePortMessage(port, data) {
8
+ port.postMessage(data);
9
+ }
10
+ function onMessagePortMessage(port, callback) {
11
+ if ("addEventListener" in port) {
12
+ port.addEventListener("message", (event) => {
13
+ callback(event.data);
14
+ });
15
+ } else if ("on" in port) {
16
+ port.on("message", (event) => {
17
+ callback(event?.data);
18
+ });
19
+ } else if ("onMessage" in port) {
20
+ port.onMessage.addListener((data) => {
21
+ callback(data);
22
+ });
23
+ } else {
24
+ throw new Error("Cannot find a addEventListener/on/onMessage method on the port");
25
+ }
26
+ }
27
+ function onMessagePortClose(port, callback) {
28
+ if ("addEventListener" in port) {
29
+ port.addEventListener("close", async () => {
30
+ callback();
31
+ });
32
+ } else if ("on" in port) {
33
+ port.on("close", async () => {
34
+ callback();
35
+ });
36
+ } else if ("onDisconnect" in port) {
37
+ port.onDisconnect.addListener(() => {
38
+ callback();
39
+ });
40
+ } else {
41
+ throw new Error("Cannot find a addEventListener/on/onDisconnect method on the port");
42
+ }
43
+ }
44
+
45
+ class experimental_LinkMessagePortClient {
46
+ peer;
47
+ constructor(options) {
48
+ this.peer = new ClientPeer(async (message) => {
49
+ postMessagePortMessage(options.port, message instanceof Blob ? await message.arrayBuffer() : message);
50
+ });
51
+ onMessagePortMessage(options.port, async (message) => {
52
+ await this.peer.message(message);
53
+ });
54
+ onMessagePortClose(options.port, () => {
55
+ this.peer.close();
56
+ });
57
+ }
58
+ async call(request, _options, _path, _input) {
59
+ const response = await this.peer.request(request);
60
+ return { ...response, body: () => Promise.resolve(response.body) };
61
+ }
62
+ }
63
+
64
+ class experimental_RPCLink extends StandardRPCLink {
65
+ constructor(options) {
66
+ const linkClient = new experimental_LinkMessagePortClient(options);
67
+ super(linkClient, { ...options, url: "orpc:/" });
68
+ }
69
+ }
70
+
71
+ export { experimental_LinkMessagePortClient, experimental_RPCLink, onMessagePortClose, onMessagePortMessage, postMessagePortMessage };
@@ -1,149 +1,10 @@
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.BMoG_EdN.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.BdD8cpjs.mjs';
3
+ import { H as HTTPPath } from '../../shared/client.4TS_0JaO.mjs';
4
+ import '@orpc/shared';
5
+ import '@orpc/standard-server';
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 getMalformedResponseErrorCode(status: number): string;
12
9
 
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
- rpcSerializer?: RPCSerializer;
136
- }
137
- declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
138
- private readonly baseUrl;
139
- private readonly maxUrlLength;
140
- private readonly fallbackMethod;
141
- private readonly expectedMethod;
142
- private readonly headers;
143
- private readonly rpcSerializer;
144
- constructor(options: StandardRPCLinkCodecOptions<T>);
145
- encode(path: readonly string[], input: unknown, options: ClientOptionsOut<any>): Promise<StandardRequest>;
146
- decode(response: StandardLazyResponse): Promise<unknown>;
147
- }
148
-
149
- export { InvalidEventIteratorRetryResponse, type RPCJsonSerialized, type RPCJsonSerializedMeta, RPCJsonSerializer, RPCSerializer, StandardLink, type StandardLinkClient, type StandardLinkCodec, type StandardLinkOptions, StandardRPCLinkCodec, type StandardRPCLinkCodecOptions };
10
+ export { getMalformedResponseErrorCode, toHttpPath };