@orpc/client 1.14.11 → 1.14.12

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 +68 -52
  2. package/dist/adapters/fetch/index.d.mts +35 -54
  3. package/dist/adapters/fetch/index.d.ts +35 -54
  4. package/dist/adapters/fetch/index.mjs +27 -74
  5. package/dist/adapters/message-port/index.d.mts +30 -25
  6. package/dist/adapters/message-port/index.d.ts +30 -25
  7. package/dist/adapters/message-port/index.mjs +30 -39
  8. package/dist/adapters/standard/index.d.mts +9 -59
  9. package/dist/adapters/standard/index.d.ts +9 -59
  10. package/dist/adapters/standard/index.mjs +5 -5
  11. package/dist/adapters/websocket/index.d.mts +21 -113
  12. package/dist/adapters/websocket/index.d.ts +21 -113
  13. package/dist/adapters/websocket/index.mjs +37 -95
  14. package/dist/index.d.mts +184 -75
  15. package/dist/index.d.ts +184 -75
  16. package/dist/index.mjs +63 -74
  17. package/dist/plugins/index.d.mts +122 -191
  18. package/dist/plugins/index.d.ts +122 -191
  19. package/dist/plugins/index.mjs +281 -627
  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.C1VUaWTu.mjs +404 -0
  25. package/dist/shared/client.CpCa3si8.d.mts +45 -0
  26. package/dist/shared/client.DrCRv_sG.mjs +174 -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 +7 -7
  30. package/dist/shared/client.8f4DNmdE.d.mts +0 -96
  31. package/dist/shared/client.BBZBQID8.d.mts +0 -167
  32. package/dist/shared/client.BBZBQID8.d.ts +0 -167
  33. package/dist/shared/client.BMKYqpdy.d.ts +0 -96
  34. package/dist/shared/client.BRJnOJ0R.mjs +0 -174
  35. package/dist/shared/client.BdItY5DT.d.mts +0 -111
  36. package/dist/shared/client.BdItY5DT.d.ts +0 -111
  37. package/dist/shared/client.Dnfj8jnT.mjs +0 -92
  38. package/dist/shared/client.DqYwRDUO.mjs +0 -343
package/README.md CHANGED
@@ -1,16 +1,17 @@
1
- <h1 align="center">oRPC - Typesafe APIs Made Simple 🪄</h1>
1
+ <div align="center">
2
+ <image align="center" src="https://orpc.dev/logo.webp" width=280 alt="oRPC logo" />
3
+ </div>
4
+
5
+ <h1></h1>
2
6
 
3
7
  <div align="center">
4
8
  <a href="https://codecov.io/gh/middleapi/orpc">
5
- <img alt="codecov" src="https://codecov.io/gh/middleapi/orpc/branch/main/graph/badge.svg">
9
+ <img alt="codecov" src="https://codecov.io/gh/middleapi/orpc/branch/1.x/graph/badge.svg">
6
10
  </a>
7
11
  <a href="https://www.npmjs.com/package/@orpc/client">
8
12
  <img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40orpc%2Fclient?logo=npm" />
9
13
  </a>
10
- <a href="https://app.codspeed.io/middleapi/orpc?utm_source=badge">
11
- <img alt="CodSpeed" src="https://img.shields.io/endpoint?url=https://codspeed.io/badge.json" />
12
- </a>
13
- <a href="https://github.com/middleapi/orpc/blob/main/LICENSE">
14
+ <a href="https://github.com/middleapi/orpc/blob/1.x/LICENSE">
14
15
  <img alt="MIT License" src="https://img.shields.io/github/license/middleapi/orpc?logo=open-source-initiative" />
15
16
  </a>
16
17
  <a href="https://discord.gg/TXEbwRBvQn">
@@ -21,53 +22,75 @@
21
22
  </a>
22
23
  </div>
23
24
 
24
- ## Documentation
25
-
26
- You can read the documentation [here](https://orpc.dev).
27
-
28
- ## Packages
29
-
30
- **Core**
25
+ <h3 align="center">Typesafe APIs Made Simple 🪄</h3>
31
26
 
32
- - [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Define API contract as the single source of truth.
33
- - [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build APIs or implement contracts.
34
- - [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume APIs with end-to-end type safety.
35
- - [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Add OpenAPI compatibility to APIs.
27
+ **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
36
28
 
37
- **Schema validation**
29
+ ---
38
30
 
39
- - [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): Integrate with [Zod](https://zod.dev/).
40
- - [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): Integrate with [Valibot](https://valibot.dev/).
41
- - [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): Integrate with [ArkType](https://arktype.io/).
31
+ ## Highlights
42
32
 
43
- **Built-in features**
33
+ - **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
34
+ - **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
35
+ - **📝 Contract-First Development**: Optionally define your API contract before implementation.
36
+ - **🔍 First-Class OpenTelemetry**: Seamlessly integrate with OpenTelemetry for observability.
37
+ - **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), SWR, Pinia Colada, and more.
38
+ - **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
39
+ - **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
40
+ - **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
41
+ - **⏱️ Lazy Router**: Enhance cold start times with our lazy routing feature.
42
+ - **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
43
+ - **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
44
+ - **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
44
45
 
45
- - [@orpc/publisher](https://www.npmjs.com/package/@orpc/publisher): Pub/Sub with memory, Redis, and Upstash adapters.
46
- - [@orpc/ratelimit](https://www.npmjs.com/package/@orpc/ratelimit): Rate limiting with memory, Redis, and Upstash adapters.
47
- - [@orpc/json-schema](https://www.npmjs.com/package/@orpc/json-schema): Smart coercion for OpenAPI requests.
48
-
49
- **Framework & ecosystem integrations**
46
+ ## Documentation
50
47
 
51
- - [@orpc/next](https://www.npmjs.com/package/@orpc/next): Integrate with [Next.js Server Functions](https://nextjs.org/docs/app/getting-started/mutating-data).
52
- - [@orpc/ai-sdk](https://www.npmjs.com/package/@orpc/ai-sdk): Turn contracts and procedures into [AI SDK](https://ai-sdk.dev/) tools.
53
- - [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): Integrate with [TanStack Query](https://tanstack.com/query/latest).
54
- - [@orpc/pinia-colada](https://www.npmjs.com/package/@orpc/pinia-colada): Integrate with [Pinia Colada](https://pinia-colada.esm.dev/).
55
- - [@orpc/swr](https://www.npmjs.com/package/@orpc/swr): Integrate with [SWR](https://swr.vercel.app/).
56
- - [@orpc/experimental-effect](https://www.npmjs.com/package/@orpc/experimental-effect): Integrate with [Effect](https://effect.website/).
57
- - [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Implement your contract with [NestJS](https://nestjs.com/).
58
- - [@orpc/bun](https://www.npmjs.com/package/@orpc/bun): Adapters for [Bun's Redis](https://bun.sh/).
59
- - [@orpc/cloudflare](https://www.npmjs.com/package/@orpc/cloudflare): Adapters for [Cloudflare's RateLimit and Durable Objects](https://developers.cloudflare.com/workers/).
60
- - [@orpc/trpc](https://www.npmjs.com/package/@orpc/trpc): Reuse existing [tRPC](https://trpc.io/) routers within oRPC.
48
+ You can find the full documentation [here](https://orpc.dev).
61
49
 
62
- **Observability**
50
+ ## Packages
63
51
 
64
- - [@orpc/opentelemetry](https://www.npmjs.com/package/@orpc/opentelemetry): Integrate with [OpenTelemetry](https://opentelemetry.io/) for distributed tracing.
65
- - [@orpc/pino](https://www.npmjs.com/package/@orpc/pino): Integrate with [Pino](https://getpino.io/) for logging.
66
- - [@orpc/evlog](https://www.npmjs.com/package/@orpc/evlog): Integrate with [Evlog](https://evlog.dev/) for logging.
52
+ - [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
53
+ - [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
54
+ - [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
55
+ - [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
56
+ - [@orpc/otel](https://www.npmjs.com/package/@orpc/otel): [OpenTelemetry](https://opentelemetry.io/) integration for observability.
57
+ - [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
58
+ - [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
59
+ - [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): [TanStack Query](https://tanstack.com/query/latest) integration.
60
+ - [@orpc/experimental-react-swr](https://www.npmjs.com/package/@orpc/experimental-react-swr): [SWR](https://swr.vercel.app/) integration.
61
+ - [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
62
+ - [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
63
+ - [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
64
+ - [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
65
+ - [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
66
+
67
+ ## `@orpc/client`
68
+
69
+ Consume your API on the client with type-safety. Read the [documentation](https://orpc.dev/docs/client/client-side) for more information.
70
+
71
+ ```ts
72
+ import { createORPCClient } from '@orpc/client'
73
+ import { RPCLink } from '@orpc/client/fetch'
74
+ import { ContractRouterClient } from '@orpc/contract'
75
+ import { RouterClient } from '@orpc/server'
76
+
77
+ const link = new RPCLink({
78
+ url: 'http://localhost:3000/rpc',
79
+ headers: () => ({
80
+ authorization: 'Bearer token',
81
+ }),
82
+ // fetch: <-- provide fetch polyfill fetch if needed
83
+ })
84
+
85
+ // Create a client for your router
86
+ const client: RouterClient<typeof router> = createORPCClient(link)
87
+ // Or, create a client using a contract
88
+ const client: ContractRouterClient<typeof contract> = createORPCClient(link)
89
+ ```
67
90
 
68
91
  ## Sponsors
69
92
 
70
- Like what we build over at [middleapi](https://github.com/middleapi)? You can help keep it going here: [GitHub Sponsors](https://github.com/sponsors/dinwwwh). Every bit helps! 🚀
93
+ If you find oRPC valuable and would like to support its development, you can do so here: [GitHub Sponsors](https://github.com/sponsors/dinwwwh).
71
94
 
72
95
  ### 🏆 Platinum Sponsor
73
96
 
@@ -109,10 +132,11 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
109
132
  <td align="center"><a href="https://github.com/valerii15298?ref=orpc" target="_blank" rel="noopener" title="Valerii Petryniak"><img src="https://avatars.githubusercontent.com/u/44531564?u=88ac74d9bacd20401518441907acad21063cd397&amp;v=4" width="139" alt="Valerii Petryniak"/><br />Valerii Petryniak</a></td>
110
133
  <td align="center"><a href="https://github.com/letstri?ref=orpc" target="_blank" rel="noopener" title="Valerii Strilets"><img src="https://avatars.githubusercontent.com/u/13253748?u=c7b10399ccc8f8081e24db94ec32cd9858e86ac3&amp;v=4" width="139" alt="Valerii Strilets"/><br />Valerii Strilets</a></td>
111
134
  <td align="center"><a href="https://github.com/K-Mistele?ref=orpc" target="_blank" rel="noopener" title="Kyle Mistele"><img src="https://avatars.githubusercontent.com/u/18430555?u=3afebeb81de666e35aaac3ed46f14159d7603ffb&amp;v=4" width="139" alt="Kyle Mistele"/><br />Kyle Mistele</a></td>
135
+ <td align="center"><a href="https://github.com/R44VC0RP?ref=orpc" target="_blank" rel="noopener" title="Ryan Vogel"><img src="https://avatars.githubusercontent.com/u/89211796?u=1857347b9787d8d8a7ea5bfc333f96be92d5a683&amp;v=4" width="139" alt="Ryan Vogel"/><br />Ryan Vogel</a></td>
112
136
  <td align="center"><a href="https://github.com/christ12938?ref=orpc" target="_blank" rel="noopener" title="christ12938"><img src="https://avatars.githubusercontent.com/u/25758598?v=4" width="139" alt="christ12938"/><br />christ12938</a></td>
113
- <td align="center"><a href="https://github.com/Ryanjso?ref=orpc" target="_blank" rel="noopener" title="Ryan Soderberg"><img src="https://avatars.githubusercontent.com/u/39172778?u=5ed913c31d57e7221b75784abcad48c7ebddde27&amp;v=4" width="139" alt="Ryan Soderberg"/><br />Ryan Soderberg</a></td>
114
137
  </tr>
115
138
  <tr>
139
+ <td align="center"><a href="https://github.com/Ryanjso?ref=orpc" target="_blank" rel="noopener" title="Ryan Soderberg"><img src="https://avatars.githubusercontent.com/u/39172778?u=5ed913c31d57e7221b75784abcad48c7ebddde27&amp;v=4" width="139" alt="Ryan Soderberg"/><br />Ryan Soderberg</a></td>
116
140
  <td align="center"><a href="https://github.com/itigoore01?ref=orpc" target="_blank" rel="noopener" title="shota"><img src="https://avatars.githubusercontent.com/u/11831107?u=c976a6dc7e055eb026304c46c99100ed22b0c8e0&amp;v=4" width="139" alt="shota"/><br />shota</a></td>
117
141
  </tr>
118
142
  </table>
@@ -172,7 +196,6 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
172
196
  <a href="https://github.com/nguyenlc1993?ref=orpc" target="_blank" rel="noopener" title="Lê Cao Nguyên"><img src="https://avatars.githubusercontent.com/u/13871971?u=83c8b69d9e35b589c4e1f066cc113b1d9461386f&amp;v=4" width="32" height="32" alt="Lê Cao Nguyên" /></a>
173
197
  <a href="https://github.com/wobsoriano?ref=orpc" target="_blank" rel="noopener" title="Robert Soriano"><img src="https://avatars.githubusercontent.com/u/13049130?u=6d72104182e7c9ed25934815313fb69107332111&amp;v=4" width="32" height="32" alt="Robert Soriano" /></a>
174
198
  <a href="https://github.com/andrewpeters9?ref=orpc" target="_blank" rel="noopener" title="Andrew Peters"><img src="https://avatars.githubusercontent.com/u/36251325?v=4" width="32" height="32" alt="Andrew Peters" /></a>
175
- <a href="https://github.com/R44VC0RP?ref=orpc" target="_blank" rel="noopener" title="Ryan Vogel"><img src="https://avatars.githubusercontent.com/u/89211796?u=1857347b9787d8d8a7ea5bfc333f96be92d5a683&amp;v=4" width="32" height="32" alt="Ryan Vogel" /></a>
176
199
  <a href="https://github.com/SKostyukovich?ref=orpc" target="_blank" rel="noopener" title="SKostyukovich"><img src="https://avatars.githubusercontent.com/u/10700067?v=4" width="32" height="32" alt="SKostyukovich" /></a>
177
200
  <a href="https://github.com/peter-adam-dy?ref=orpc" target="_blank" rel="noopener" title="Peter Adam"><img src="https://avatars.githubusercontent.com/u/132129459?u=4f3dbbb3b443990b56acb7d6a5d11ed2c555f6db&amp;v=4" width="32" height="32" alt="Peter Adam" /></a>
178
201
  <a href="https://github.com/FabworksHQ?ref=orpc" target="_blank" rel="noopener" title="Fabworks"><img src="https://avatars.githubusercontent.com/u/160179500?v=4" width="32" height="32" alt="Fabworks" /></a>
@@ -187,13 +210,6 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
187
210
  <a href="https://github.com/plancraft?ref=orpc" target="_blank" rel="noopener" title="plancraft"><img src="https://avatars.githubusercontent.com/u/46482287?v=4" width="32" height="32" alt="plancraft" /></a>
188
211
  </p>
189
212
 
190
- ## References
191
-
192
- oRPC is inspired by existing solutions that prioritize type safety and developer experience. Special acknowledgments to:
193
-
194
- - [tRPC](https://trpc.io): For pioneering the concept of end-to-end type-safe RPC and influencing the development of type-safe APIs.
195
- - [ts-rest](https://ts-rest.com): For its emphasis on contract-first development and OpenAPI integration, which have greatly inspired oRPC's feature set.
196
-
197
213
  ## License
198
214
 
199
- Distributed under the MIT License. See [LICENSE](https://github.com/middleapi/orpc/blob/main/LICENSE) for more information.
215
+ Distributed under the MIT License. See [LICENSE](https://github.com/middleapi/orpc/blob/1.x/LICENSE) for more information.
@@ -1,65 +1,46 @@
1
- import { C as ClientContext, a as ClientOptions } from '../../shared/client.BBZBQID8.mjs';
2
- import { Value, Promisable, Interceptor } from '@orpc/shared';
3
- import { StandardRequest, StandardLazyResponse } from '@standardserver/core';
4
- import { ToFetchBodyOptions } from '@standardserver/fetch';
5
- import { S as StandardLinkTransport, c as StandardLinkPlugin, a as StandardLink, b as StandardLinkOptions } from '../../shared/client.8f4DNmdE.mjs';
6
- import { RPCLinkCodecOptions } from '../standard/index.mjs';
7
- import '../../shared/client.BdItY5DT.mjs';
1
+ import { Interceptor } from '@orpc/shared';
2
+ import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
3
+ import { ToFetchRequestOptions } from '@orpc/standard-server-fetch';
4
+ import { b as ClientContext, c as ClientOptions } from '../../shared/client.i2uoJbEp.mjs';
5
+ import { a as StandardLinkPlugin, f as StandardLinkClient } from '../../shared/client.CpCa3si8.mjs';
6
+ import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.BFAVy68H.mjs';
8
7
 
9
- interface FetchLinkTransportFetchInterceptorOptions<T extends ClientContext> extends ClientOptions<T> {
10
- path: string[];
11
- url: string;
12
- init: RequestInit;
8
+ interface LinkFetchPlugin<T extends ClientContext> extends StandardLinkPlugin<T> {
9
+ initRuntimeAdapter?(options: LinkFetchClientOptions<T>): void;
13
10
  }
14
- type FetchLinkTransportFetchInterceptor<T extends ClientContext> = Interceptor<FetchLinkTransportFetchInterceptorOptions<T>, Promise<Response>>;
15
- interface FetchLinkTransportOptions<T extends ClientContext> {
16
- /**
17
- * The origin to prepend to all request URLs, useful for CORS requests.
18
- *
19
- * @example 'https://api.example.com'
20
- * @example 'http://localhost:3000'
21
- */
22
- origin?: Value<Promisable<`https://${string}` | `http://${string}` | ({} & string) | undefined>, [options: ClientOptions<T>, path: string[]]>;
23
- /**
24
- * Options for how to convert the Standard Request to a Fetch Request, like event stream options, etc.
25
- */
26
- toFetchRequest?: undefined | ToFetchBodyOptions;
27
- /**
28
- * Override the default fetch implementation.
29
- *
30
- * @default globalThis.fetch.bind(globalThis)
31
- */
32
- fetch?(url: string, init: RequestInit, options: ClientOptions<T>, path: string[]): Promise<Response>;
33
- /**
34
- * Interceptors that execute before the actual fetch call, useful for modifying the fetch parameters, adding logging, etc.
35
- */
36
- fetchInterceptors?: FetchLinkTransportFetchInterceptor<T>[];
37
- plugins?: FetchLinkTransportPlugin<T>[];
11
+
12
+ interface LinkFetchInterceptorOptions<T extends ClientContext> extends ClientOptions<T> {
13
+ request: Request;
14
+ init: {
15
+ redirect?: Request['redirect'];
16
+ };
17
+ path: readonly string[];
18
+ input: unknown;
19
+ }
20
+ interface LinkFetchClientOptions<T extends ClientContext> extends ToFetchRequestOptions {
21
+ fetch?: (request: Request, init: LinkFetchInterceptorOptions<T>['init'], options: ClientOptions<T>, path: readonly string[], input: unknown) => Promise<Response>;
22
+ adapterInterceptors?: Interceptor<LinkFetchInterceptorOptions<T>, Promise<Response>>[];
23
+ plugins?: LinkFetchPlugin<T>[];
38
24
  }
39
- declare class FetchLinkTransport<T extends ClientContext> implements StandardLinkTransport<T> {
40
- private readonly origin;
25
+ declare class LinkFetchClient<T extends ClientContext> implements StandardLinkClient<T> {
41
26
  private readonly fetch;
42
27
  private readonly toFetchRequestOptions;
43
- private readonly fetchInterceptors;
44
- constructor(options: FetchLinkTransportOptions<T>);
45
- send(standardRequest: StandardRequest, path: string[], options: ClientOptions<T>): Promise<StandardLazyResponse>;
46
- }
47
-
48
- interface FetchLinkTransportPlugin<T extends ClientContext> extends StandardLinkPlugin<T> {
49
- initFetchLinkTransportOptions?(options: FetchLinkTransportOptions<T>): FetchLinkTransportOptions<T>;
50
- }
51
- declare class CompositeFetchLinkTransportPlugin<T extends ClientContext> implements FetchLinkTransportPlugin<T> {
52
- protected readonly plugins: FetchLinkTransportPlugin<T>[];
53
- name: string;
54
- constructor(plugins?: FetchLinkTransportPlugin<T>[]);
55
- initFetchLinkTransportOptions(options: FetchLinkTransportOptions<T>): FetchLinkTransportOptions<T>;
28
+ private readonly adapterInterceptors;
29
+ constructor(options: LinkFetchClientOptions<T>);
30
+ call(standardRequest: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
56
31
  }
57
32
 
58
- interface RPCLinkOptions<T extends ClientContext> extends Omit<StandardLinkOptions<T>, 'plugins'>, FetchLinkTransportOptions<T>, RPCLinkCodecOptions<T> {
33
+ interface RPCLinkOptions<T extends ClientContext> extends LinkFetchClientOptions<T>, Omit<StandardRPCLinkOptions<T>, 'plugins'> {
59
34
  }
60
- declare class RPCLink<T extends ClientContext> extends StandardLink<T> {
35
+ /**
36
+ * The RPC Link communicates with the server using the RPC protocol.
37
+ *
38
+ * @see {@link https://orpc.dev/docs/client/rpc-link RPC Link Docs}
39
+ * @see {@link https://orpc.dev/docs/advanced/rpc-protocol RPC Protocol Docs}
40
+ */
41
+ declare class RPCLink<T extends ClientContext> extends StandardRPCLink<T> {
61
42
  constructor(options: RPCLinkOptions<T>);
62
43
  }
63
44
 
64
- export { CompositeFetchLinkTransportPlugin, FetchLinkTransport, RPCLink };
65
- export type { FetchLinkTransportFetchInterceptor, FetchLinkTransportFetchInterceptorOptions, FetchLinkTransportOptions, FetchLinkTransportPlugin, RPCLinkOptions };
45
+ export { LinkFetchClient, RPCLink };
46
+ export type { LinkFetchClientOptions, LinkFetchInterceptorOptions, RPCLinkOptions };
@@ -1,65 +1,46 @@
1
- import { C as ClientContext, a as ClientOptions } from '../../shared/client.BBZBQID8.js';
2
- import { Value, Promisable, Interceptor } from '@orpc/shared';
3
- import { StandardRequest, StandardLazyResponse } from '@standardserver/core';
4
- import { ToFetchBodyOptions } from '@standardserver/fetch';
5
- import { S as StandardLinkTransport, c as StandardLinkPlugin, a as StandardLink, b as StandardLinkOptions } from '../../shared/client.BMKYqpdy.js';
6
- import { RPCLinkCodecOptions } from '../standard/index.js';
7
- import '../../shared/client.BdItY5DT.js';
1
+ import { Interceptor } from '@orpc/shared';
2
+ import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
3
+ import { ToFetchRequestOptions } from '@orpc/standard-server-fetch';
4
+ import { b as ClientContext, c as ClientOptions } from '../../shared/client.i2uoJbEp.js';
5
+ import { a as StandardLinkPlugin, f as StandardLinkClient } from '../../shared/client.2jUAqzYU.js';
6
+ import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.B3pNRBih.js';
8
7
 
9
- interface FetchLinkTransportFetchInterceptorOptions<T extends ClientContext> extends ClientOptions<T> {
10
- path: string[];
11
- url: string;
12
- init: RequestInit;
8
+ interface LinkFetchPlugin<T extends ClientContext> extends StandardLinkPlugin<T> {
9
+ initRuntimeAdapter?(options: LinkFetchClientOptions<T>): void;
13
10
  }
14
- type FetchLinkTransportFetchInterceptor<T extends ClientContext> = Interceptor<FetchLinkTransportFetchInterceptorOptions<T>, Promise<Response>>;
15
- interface FetchLinkTransportOptions<T extends ClientContext> {
16
- /**
17
- * The origin to prepend to all request URLs, useful for CORS requests.
18
- *
19
- * @example 'https://api.example.com'
20
- * @example 'http://localhost:3000'
21
- */
22
- origin?: Value<Promisable<`https://${string}` | `http://${string}` | ({} & string) | undefined>, [options: ClientOptions<T>, path: string[]]>;
23
- /**
24
- * Options for how to convert the Standard Request to a Fetch Request, like event stream options, etc.
25
- */
26
- toFetchRequest?: undefined | ToFetchBodyOptions;
27
- /**
28
- * Override the default fetch implementation.
29
- *
30
- * @default globalThis.fetch.bind(globalThis)
31
- */
32
- fetch?(url: string, init: RequestInit, options: ClientOptions<T>, path: string[]): Promise<Response>;
33
- /**
34
- * Interceptors that execute before the actual fetch call, useful for modifying the fetch parameters, adding logging, etc.
35
- */
36
- fetchInterceptors?: FetchLinkTransportFetchInterceptor<T>[];
37
- plugins?: FetchLinkTransportPlugin<T>[];
11
+
12
+ interface LinkFetchInterceptorOptions<T extends ClientContext> extends ClientOptions<T> {
13
+ request: Request;
14
+ init: {
15
+ redirect?: Request['redirect'];
16
+ };
17
+ path: readonly string[];
18
+ input: unknown;
19
+ }
20
+ interface LinkFetchClientOptions<T extends ClientContext> extends ToFetchRequestOptions {
21
+ fetch?: (request: Request, init: LinkFetchInterceptorOptions<T>['init'], options: ClientOptions<T>, path: readonly string[], input: unknown) => Promise<Response>;
22
+ adapterInterceptors?: Interceptor<LinkFetchInterceptorOptions<T>, Promise<Response>>[];
23
+ plugins?: LinkFetchPlugin<T>[];
38
24
  }
39
- declare class FetchLinkTransport<T extends ClientContext> implements StandardLinkTransport<T> {
40
- private readonly origin;
25
+ declare class LinkFetchClient<T extends ClientContext> implements StandardLinkClient<T> {
41
26
  private readonly fetch;
42
27
  private readonly toFetchRequestOptions;
43
- private readonly fetchInterceptors;
44
- constructor(options: FetchLinkTransportOptions<T>);
45
- send(standardRequest: StandardRequest, path: string[], options: ClientOptions<T>): Promise<StandardLazyResponse>;
46
- }
47
-
48
- interface FetchLinkTransportPlugin<T extends ClientContext> extends StandardLinkPlugin<T> {
49
- initFetchLinkTransportOptions?(options: FetchLinkTransportOptions<T>): FetchLinkTransportOptions<T>;
50
- }
51
- declare class CompositeFetchLinkTransportPlugin<T extends ClientContext> implements FetchLinkTransportPlugin<T> {
52
- protected readonly plugins: FetchLinkTransportPlugin<T>[];
53
- name: string;
54
- constructor(plugins?: FetchLinkTransportPlugin<T>[]);
55
- initFetchLinkTransportOptions(options: FetchLinkTransportOptions<T>): FetchLinkTransportOptions<T>;
28
+ private readonly adapterInterceptors;
29
+ constructor(options: LinkFetchClientOptions<T>);
30
+ call(standardRequest: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
56
31
  }
57
32
 
58
- interface RPCLinkOptions<T extends ClientContext> extends Omit<StandardLinkOptions<T>, 'plugins'>, FetchLinkTransportOptions<T>, RPCLinkCodecOptions<T> {
33
+ interface RPCLinkOptions<T extends ClientContext> extends LinkFetchClientOptions<T>, Omit<StandardRPCLinkOptions<T>, 'plugins'> {
59
34
  }
60
- declare class RPCLink<T extends ClientContext> extends StandardLink<T> {
35
+ /**
36
+ * The RPC Link communicates with the server using the RPC protocol.
37
+ *
38
+ * @see {@link https://orpc.dev/docs/client/rpc-link RPC Link Docs}
39
+ * @see {@link https://orpc.dev/docs/advanced/rpc-protocol RPC Protocol Docs}
40
+ */
41
+ declare class RPCLink<T extends ClientContext> extends StandardRPCLink<T> {
61
42
  constructor(options: RPCLinkOptions<T>);
62
43
  }
63
44
 
64
- export { CompositeFetchLinkTransportPlugin, FetchLinkTransport, RPCLink };
65
- export type { FetchLinkTransportFetchInterceptor, FetchLinkTransportFetchInterceptorOptions, FetchLinkTransportOptions, FetchLinkTransportPlugin, RPCLinkOptions };
45
+ export { LinkFetchClient, RPCLink };
46
+ export type { LinkFetchClientOptions, LinkFetchInterceptorOptions, RPCLinkOptions };
@@ -1,93 +1,46 @@
1
- import { sortPlugins, value, intercept, once } from '@orpc/shared';
2
- import { toFetchBody, toFetchHeaders, toStandardLazyResponse } from '@standardserver/fetch';
3
- import { S as StandardLink, R as RPCLinkCodec } from '../../shared/client.BRJnOJ0R.mjs';
4
- import '@standardserver/core';
5
- import '../../shared/client.Dnfj8jnT.mjs';
6
- import '../../shared/client.DqYwRDUO.mjs';
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.C1VUaWTu.mjs';
4
+ import '@orpc/standard-server';
5
+ import '../../shared/client.DrCRv_sG.mjs';
6
+ import '../../shared/client.BLtwTQUg.mjs';
7
7
 
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) {
8
+ class CompositeLinkFetchPlugin extends CompositeStandardLinkPlugin {
9
+ initRuntimeAdapter(options) {
15
10
  for (const plugin of this.plugins) {
16
- if (plugin.initFetchLinkTransportOptions) {
17
- options = plugin.initFetchLinkTransportOptions(options);
18
- }
11
+ plugin.initRuntimeAdapter?.(options);
19
12
  }
20
- return options;
21
13
  }
22
14
  }
23
15
 
24
- const GET_SUPPORTED_DUPLEX_MODE = once(() => {
25
- try {
26
- let duplex;
27
- void new Request(
28
- "https://example.com",
29
- {
30
- method: "POST",
31
- body: new ReadableStream(),
32
- get duplex() {
33
- duplex = "half";
34
- return "half";
35
- }
36
- }
37
- );
38
- return duplex;
39
- } catch {
40
- return void 0;
41
- }
42
- });
43
- class FetchLinkTransport {
44
- origin;
16
+ class LinkFetchClient {
45
17
  fetch;
46
18
  toFetchRequestOptions;
47
- fetchInterceptors;
19
+ adapterInterceptors;
48
20
  constructor(options) {
49
- options = new CompositeFetchLinkTransportPlugin(options.plugins).initFetchLinkTransportOptions(options);
50
- this.origin = options.origin;
21
+ const plugin = new CompositeLinkFetchPlugin(options.plugins);
22
+ plugin.initRuntimeAdapter(options);
51
23
  this.fetch = options.fetch ?? globalThis.fetch.bind(globalThis);
52
- this.toFetchRequestOptions = options.toFetchRequest;
53
- this.fetchInterceptors = options.fetchInterceptors;
24
+ this.toFetchRequestOptions = options;
25
+ this.adapterInterceptors = toArray(options.adapterInterceptors);
54
26
  }
55
- async send(standardRequest, path, options) {
56
- let origin = await value(this.origin, options, path);
57
- if (origin?.endsWith("/")) {
58
- origin = origin.slice(0, -1);
59
- }
60
- const url = `${origin ?? ""}${standardRequest.url}`;
61
- const [body, standardHeaders] = toFetchBody(standardRequest.body, standardRequest.headers, this.toFetchRequestOptions);
62
- const init = {
63
- body,
64
- headers: toFetchHeaders(standardHeaders),
65
- method: standardRequest.method,
66
- signal: options.signal,
67
- redirect: "manual"
68
- };
69
- if (body instanceof ReadableStream) {
70
- const duplex = GET_SUPPORTED_DUPLEX_MODE();
71
- if (duplex !== void 0) {
72
- init.duplex = duplex;
73
- }
74
- }
75
- const response = await intercept(
76
- this.fetchInterceptors,
77
- { ...options, url, path, init },
78
- ({ url: url2, path: path2, init: init2, ...options2 }) => this.fetch(url2, init2, options2, path2)
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)
79
33
  );
80
- const standardResponse = toStandardLazyResponse(response);
81
- return standardResponse;
34
+ const lazyResponse = toStandardLazyResponse(fetchResponse, { signal: request.signal });
35
+ return lazyResponse;
82
36
  }
83
37
  }
84
38
 
85
- class RPCLink extends StandardLink {
39
+ class RPCLink extends StandardRPCLink {
86
40
  constructor(options) {
87
- const codec = new RPCLinkCodec(options);
88
- const transport = new FetchLinkTransport(options);
89
- super(codec, transport, options);
41
+ const linkClient = new LinkFetchClient(options);
42
+ super(linkClient, options);
90
43
  }
91
44
  }
92
45
 
93
- export { CompositeFetchLinkTransportPlugin, FetchLinkTransport, RPCLink };
46
+ export { LinkFetchClient, RPCLink };
@@ -1,10 +1,9 @@
1
- import { C as ClientContext, a as ClientOptions } from '../../shared/client.BBZBQID8.mjs';
2
1
  import { Value, Promisable } from '@orpc/shared';
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.8f4DNmdE.mjs';
6
- import { RPCLinkCodecOptions } from '../standard/index.mjs';
7
- import '../../shared/client.BdItY5DT.mjs';
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';
8
7
 
9
8
  /**
10
9
  * The message port used by electron in main process
@@ -29,47 +28,53 @@ interface BrowserPortLike {
29
28
  }
30
29
  type SupportedMessagePort = Pick<MessagePort, 'addEventListener' | 'postMessage'> | MessagePortMainLike | BrowserPortLike;
31
30
  /**
32
- * Message port can support [The structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm)
31
+ * Message port can support [The structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm)
33
32
  */
34
33
  type SupportedMessagePortData = any;
35
34
  declare function postMessagePortMessage(port: SupportedMessagePort, data: SupportedMessagePortData, transfer?: any[]): void;
36
35
  declare function onMessagePortMessage(port: SupportedMessagePort, callback: (data: SupportedMessagePortData) => void): void;
37
36
  declare function onMessagePortClose(port: SupportedMessagePort, callback: () => void): void;
38
37
 
39
- type DecodedRequestMessage = ConstructorParameters<typeof ClientPeer>[0] extends (message: infer TMessage) => unknown ? TMessage : never;
40
- interface MessagePortLinkTransportOptions<_T extends ClientContext> {
38
+ interface LinkMessagePortClientOptions {
41
39
  port: SupportedMessagePort;
42
40
  /**
43
41
  * By default, oRPC serializes request/response messages to string/binary data before sending over message port.
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),
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),
45
43
  * such as transferring ownership of objects to the other side or support unserializable objects like `OffscreenCanvas`.
46
44
  *
47
45
  * @remarks
48
46
  * - return null | undefined to disable this feature
49
47
  *
50
48
  * @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}
51
58
  */
52
59
  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;
61
60
  }
62
- declare class MessagePortLinkTransport<T extends ClientContext> implements StandardLinkTransport<T> {
61
+ declare class LinkMessagePortClient<T extends ClientContext> implements StandardLinkClient<T> {
63
62
  private readonly peer;
64
- constructor({ port, experimental_transfer, encodePeerMessage: encodePeerMessageOptions, decodePeerMessage: decodePeerMessageOptions }: MessagePortLinkTransportOptions<T>);
65
- send(standardRequest: StandardRequest, _path: string[], _options: ClientOptions<T>): Promise<StandardLazyResponse>;
63
+ constructor(options: LinkMessagePortClientOptions);
64
+ call(request: StandardRequest, _options: ClientOptions<T>, _path: readonly string[], _input: unknown): Promise<StandardLazyResponse>;
66
65
  }
67
66
 
68
- interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, MessagePortLinkTransportOptions<T>, RPCLinkCodecOptions<T> {
67
+ interface RPCLinkOptions<T extends ClientContext> extends Omit<StandardRPCLinkOptions<T>, 'url' | 'method' | 'fallbackMethod' | 'maxUrlLength'>, LinkMessagePortClientOptions {
69
68
  }
70
- declare class RPCLink<T extends ClientContext> extends StandardLink<T> {
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> {
71
76
  constructor(options: RPCLinkOptions<T>);
72
77
  }
73
78
 
74
- export { MessagePortLinkTransport, RPCLink, onMessagePortClose, onMessagePortMessage, postMessagePortMessage };
75
- export type { BrowserPortLike, MessagePortLinkTransportOptions, MessagePortMainLike, RPCLinkOptions, SupportedMessagePort, SupportedMessagePortData };
79
+ export { LinkMessagePortClient, RPCLink, onMessagePortClose, onMessagePortMessage, postMessagePortMessage };
80
+ export type { BrowserPortLike, LinkMessagePortClientOptions, MessagePortMainLike, RPCLinkOptions, SupportedMessagePort, SupportedMessagePortData };