@orpc/client 2.0.0-beta.45 → 2.0.0-beta.47
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 +53 -19
- package/dist/adapters/fetch/index.mjs +1 -1
- package/dist/adapters/message-port/index.mjs +1 -1
- package/dist/adapters/standard/index.d.mts +2 -2
- package/dist/adapters/standard/index.d.ts +2 -2
- package/dist/adapters/standard/index.mjs +1 -1
- package/dist/adapters/websocket/index.mjs +1 -1
- package/dist/index.d.mts +4 -5
- package/dist/index.d.ts +4 -5
- package/dist/index.mjs +1 -1
- package/dist/plugins/index.mjs +14 -14
- package/dist/shared/{client.Bpyj1NM2.mjs → client.CKQeJJ2U.mjs} +1 -1
- package/dist/shared/{client.DBDKICdk.d.ts → client.JBJwBhR8.d.ts} +1 -7
- package/dist/shared/{client.CkwtFnrc.d.mts → client.euYjjcFz.d.mts} +1 -7
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -21,9 +21,40 @@
|
|
|
21
21
|
</a>
|
|
22
22
|
</div>
|
|
23
23
|
|
|
24
|
+
**oRPC** is a TypeScript framework for building end-to-end typesafe APIs. Write your API once as plain TypeScript functions, and oRPC gives you a fully typed client, a REST API with an OpenAPI document, and MCP tools for AI agents, with no code generation. It runs on Node.js, Bun, Deno, Cloudflare Workers, and more.
|
|
25
|
+
|
|
26
|
+
Define procedures on the server and serve them with an [RPC handler](https://orpc.dev/docs/rpc/handler):
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { os } from '@orpc/server'
|
|
30
|
+
import * as z from 'zod'
|
|
31
|
+
|
|
32
|
+
export const router = {
|
|
33
|
+
planet: {
|
|
34
|
+
find: os
|
|
35
|
+
.input(z.object({ id: z.number() }))
|
|
36
|
+
.handler(({ input }) => ({ id: input.id, name: 'Earth' })),
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Then call them from a client that knows every input and output, without generating anything:
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import type { RouterClient } from '@orpc/server'
|
|
45
|
+
import type { router } from './router'
|
|
46
|
+
import { createORPCClient } from '@orpc/client'
|
|
47
|
+
import { RPCLink } from '@orpc/client/fetch'
|
|
48
|
+
|
|
49
|
+
const link = new RPCLink({ origin: 'http://localhost:3000', url: '/rpc' })
|
|
50
|
+
const client: RouterClient<typeof router> = createORPCClient(link)
|
|
51
|
+
|
|
52
|
+
const planet = await client.planet.find({ id: 1 }) // { id: number, name: string }
|
|
53
|
+
```
|
|
54
|
+
|
|
24
55
|
## Documentation
|
|
25
56
|
|
|
26
|
-
|
|
57
|
+
Read the full documentation at [orpc.dev](https://orpc.dev), starting with the [Getting Started guide](https://orpc.dev/docs/getting-started).
|
|
27
58
|
|
|
28
59
|
## Packages
|
|
29
60
|
|
|
@@ -56,21 +87,21 @@ You can read the documentation [here](https://orpc.dev).
|
|
|
56
87
|
|
|
57
88
|
**Framework & ecosystem integrations**
|
|
58
89
|
|
|
59
|
-
| Package
|
|
60
|
-
|
|
|
61
|
-
| [@orpc/next](https://www.npmjs.com/package/@orpc/next)
|
|
62
|
-
| [@orpc/ai-sdk](https://www.npmjs.com/package/@orpc/ai-sdk)
|
|
63
|
-
| [@orpc/mcp](https://www.npmjs.com/package/@orpc/mcp)
|
|
64
|
-
| [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query)
|
|
65
|
-
| [@orpc/pinia-colada](https://www.npmjs.com/package/@orpc/pinia-colada)
|
|
66
|
-
| [@orpc/swr](https://www.npmjs.com/package/@orpc/swr)
|
|
67
|
-
| [@orpc/msw](https://www.npmjs.com/package/@orpc/msw)
|
|
68
|
-
| [@orpc/
|
|
69
|
-
| [@orpc/nest](https://www.npmjs.com/package/@orpc/nest)
|
|
70
|
-
| [@orpc/node](https://www.npmjs.com/package/@orpc/node)
|
|
71
|
-
| [@orpc/bun](https://www.npmjs.com/package/@orpc/bun)
|
|
72
|
-
| [@orpc/cloudflare](https://www.npmjs.com/package/@orpc/cloudflare)
|
|
73
|
-
| [@orpc/trpc](https://www.npmjs.com/package/@orpc/trpc)
|
|
90
|
+
| Package | Purpose | Docs |
|
|
91
|
+
| -------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
92
|
+
| [@orpc/next](https://www.npmjs.com/package/@orpc/next) | Integrate with [Next.js Server Functions](https://nextjs.org/docs/app/getting-started/mutating-data). | [Next.js](https://orpc.dev/docs/integrations/next) |
|
|
93
|
+
| [@orpc/ai-sdk](https://www.npmjs.com/package/@orpc/ai-sdk) | Turn contracts and procedures into [AI SDK](https://ai-sdk.dev/) tools. | [AI SDK](https://orpc.dev/docs/integrations/ai-sdk) |
|
|
94
|
+
| [@orpc/mcp](https://www.npmjs.com/package/@orpc/mcp) | Expose procedures as [MCP](https://modelcontextprotocol.io/) tools. | [MCP](https://orpc.dev/docs/integrations/mcp) |
|
|
95
|
+
| [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query) | Integrate with [TanStack Query](https://tanstack.com/query/latest). | [TanStack Query](https://orpc.dev/docs/integrations/tanstack-query) |
|
|
96
|
+
| [@orpc/pinia-colada](https://www.npmjs.com/package/@orpc/pinia-colada) | Integrate with [Pinia Colada](https://pinia-colada.esm.dev/). | [Pinia Colada](https://orpc.dev/docs/integrations/pinia-colada) |
|
|
97
|
+
| [@orpc/swr](https://www.npmjs.com/package/@orpc/swr) | Integrate with [SWR](https://swr.vercel.app/). | [SWR](https://orpc.dev/docs/integrations/swr) |
|
|
98
|
+
| [@orpc/msw](https://www.npmjs.com/package/@orpc/msw) | Mock procedures with [Mock Service Worker](https://mswjs.io/). | [MSW](https://orpc.dev/docs/integrations/msw) |
|
|
99
|
+
| [@orpc/effect](https://www.npmjs.com/package/@orpc/effect) | Integrate with [Effect](https://effect.website/). | [Effect](https://orpc.dev/docs/integrations/effect) |
|
|
100
|
+
| [@orpc/nest](https://www.npmjs.com/package/@orpc/nest) | Implement your contract with [NestJS](https://nestjs.com/). | [NestJS](https://orpc.dev/docs/integrations/nest) |
|
|
101
|
+
| [@orpc/node](https://www.npmjs.com/package/@orpc/node) | [Node.js](https://nodejs.org/) plugins for static file serving and large uploads. | [Static File](https://orpc.dev/docs/plugins/static-file), [Tmp File Upload](https://orpc.dev/docs/plugins/tmp-file-upload), [Batch Response Compression](https://orpc.dev/docs/plugins/batch-response-compression) |
|
|
102
|
+
| [@orpc/bun](https://www.npmjs.com/package/@orpc/bun) | Adapters for [Bun's Redis](https://bun.sh/). | [Publisher](https://orpc.dev/docs/helpers/publisher), [Rate Limit](https://orpc.dev/docs/helpers/ratelimit), [Lock](https://orpc.dev/docs/helpers/lock) |
|
|
103
|
+
| [@orpc/cloudflare](https://www.npmjs.com/package/@orpc/cloudflare) | Adapters for [Cloudflare Workers](https://developers.cloudflare.com/workers/). | [Publisher](https://orpc.dev/docs/helpers/publisher), [Rate Limit](https://orpc.dev/docs/helpers/ratelimit), [Lock](https://orpc.dev/docs/helpers/lock), [Traces](https://orpc.dev/docs/integrations/cloudflare-traces) |
|
|
104
|
+
| [@orpc/trpc](https://www.npmjs.com/package/@orpc/trpc) | Reuse existing [tRPC](https://trpc.io/) routers within oRPC. | [tRPC](https://orpc.dev/docs/integrations/trpc) |
|
|
74
105
|
|
|
75
106
|
**Observability**
|
|
76
107
|
|
|
@@ -125,10 +156,11 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
125
156
|
<td align="center"><a href="https://github.com/christ12938?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="christ12938"><img src="https://avatars.githubusercontent.com/u/25758598?v=4" width="167" alt="christ12938"/><br />christ12938</a></td>
|
|
126
157
|
<td align="center"><a href="https://github.com/Ryanjso?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Ryan Soderberg"><img src="https://avatars.githubusercontent.com/u/39172778?u=5ed913c31d57e7221b75784abcad48c7ebddde27&v=4" width="167" alt="Ryan Soderberg"/><br />Ryan Soderberg</a></td>
|
|
127
158
|
<td align="center"><a href="https://github.com/itigoore01?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="shota"><img src="https://avatars.githubusercontent.com/u/11831107?u=c976a6dc7e055eb026304c46c99100ed22b0c8e0&v=4" width="167" alt="shota"/><br />shota</a></td>
|
|
159
|
+
<td align="center"><a href="https://github.com/Nic13Gamer?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Nicholas"><img src="https://avatars.githubusercontent.com/u/54724556?u=56a7ab430ce7a80d648ab6eba051d454a818ed0b&v=4" width="167" alt="Nicholas"/><br />Nicholas</a></td>
|
|
128
160
|
<td align="center"><a href="https://github.com/ellis-driscoll?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Ellis Driscoll"><img src="https://avatars.githubusercontent.com/u/70685966?u=c5f95bc33b5991d9744abe00052542e4a2ed3cb9&v=4" width="167" alt="Ellis Driscoll"/><br />Ellis Driscoll</a></td>
|
|
129
|
-
<td align="center"><a href="https://github.com/hoangbn?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Hoang Nguyen"><img src="https://avatars.githubusercontent.com/u/38968280?u=c90084c6de65c56facabab7ba13a72a49ddbc3e4&v=4" width="167" alt="Hoang Nguyen"/><br />Hoang Nguyen</a></td>
|
|
130
161
|
</tr>
|
|
131
162
|
<tr>
|
|
163
|
+
<td align="center"><a href="https://github.com/hoangbn?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Hoang Nguyen"><img src="https://avatars.githubusercontent.com/u/38968280?u=c90084c6de65c56facabab7ba13a72a49ddbc3e4&v=4" width="167" alt="Hoang Nguyen"/><br />Hoang Nguyen</a></td>
|
|
132
164
|
<td align="center"><a href="https://opencollective.com/guest-ac41de3b?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Orestis Ioannou"><img src="https://images.opencollective.com/guest-ac41de3b/avatar/460.png" width="167" alt="Orestis Ioannou"/><br />Orestis Ioannou</a></td>
|
|
133
165
|
<td align="center"><a href="https://automatio.ai/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Stefan Smiljkovic"><img src="https://avatars.githubusercontent.com/u/1984909?u=b7bf5bc40ed49df3c22f69d2da7b8d78709c49ed&v=4" width="167" alt="Stefan Smiljkovic"/><br />Stefan Smiljkovic</a></td>
|
|
134
166
|
</tr>
|
|
@@ -167,7 +199,7 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
167
199
|
</tr>
|
|
168
200
|
</table>
|
|
169
201
|
|
|
170
|
-
With thanks to [
|
|
202
|
+
With thanks to [39 past sponsors](https://orpc.dev/sponsors#past-sponsors) who helped get oRPC here.
|
|
171
203
|
|
|
172
204
|
## Open Source Programs
|
|
173
205
|
|
|
@@ -175,7 +207,9 @@ With thanks to [40 past sponsors](https://orpc.dev/sponsors#past-sponsors) who h
|
|
|
175
207
|
|
|
176
208
|
<table>
|
|
177
209
|
<tr>
|
|
178
|
-
<td align="center"><a href="https://claude.com/contact-sales/claude-for-oss" target="_blank" rel="noopener" title="Claude for Open Source"><img src="https://cdn.simpleicons.org/claude" width="64" alt="Claude"/><br />Claude
|
|
210
|
+
<td align="center"><a href="https://claude.com/contact-sales/claude-for-oss" target="_blank" rel="noopener" title="Claude for Open Source"><img src="https://cdn.simpleicons.org/claude" width="64" alt="Claude"/><br />Claude</a></td>
|
|
211
|
+
<td align="center"><a href="https://pullfrog.com/for-oss" target="_blank" rel="noopener" title="Pullfrog for OSS"><img src="https://avatars.githubusercontent.com/in/1768019?s=128&v=4" width="64" alt="Pullfrog"/><br />Pullfrog</a></td>
|
|
212
|
+
<td align="center"><a href="https://macroscope.com/open-source" target="_blank" rel="noopener" title="Macroscope for Open Source"><img src="https://avatars.githubusercontent.com/in/900172?s=128&v=4" width="64" alt="Macroscope"/><br />Macroscope</a></td>
|
|
179
213
|
</tr>
|
|
180
214
|
</table>
|
|
181
215
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { value, once } from '@orpc/shared';
|
|
2
2
|
import { toFetchBody, toFetchHeaders, toStandardLazyResponse } from '@standard-server/fetch';
|
|
3
|
-
import { S as StandardLink, R as RPCLinkCodec } from '../../shared/client.
|
|
3
|
+
import { S as StandardLink, R as RPCLinkCodec } from '../../shared/client.CKQeJJ2U.mjs';
|
|
4
4
|
import '@standard-server/core';
|
|
5
5
|
import '../../shared/client.LF04eOvL.mjs';
|
|
6
6
|
import '../../shared/client._wG5INmC.mjs';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { value, AbortError } from '@orpc/shared';
|
|
2
2
|
import { ClientPeer, encodePeerMessage, decodePeerMessage, isServerPeerSendMessage, isPeerMessage } from '@standard-server/peer';
|
|
3
|
-
import { S as StandardLink, R as RPCLinkCodec } from '../../shared/client.
|
|
3
|
+
import { S as StandardLink, R as RPCLinkCodec } from '../../shared/client.CKQeJJ2U.mjs';
|
|
4
4
|
import '@standard-server/core';
|
|
5
5
|
import '@standard-server/fetch';
|
|
6
6
|
import '../../shared/client.LF04eOvL.mjs';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { f as StandardLinkCodec, g as StandardLinkCodecDecodedResponse } from '../../shared/client.
|
|
2
|
-
export {
|
|
1
|
+
import { f as StandardLinkCodec, g as StandardLinkCodecDecodedResponse } from '../../shared/client.euYjjcFz.mjs';
|
|
2
|
+
export { a as StandardLink, h as StandardLinkInterceptor, e as StandardLinkInterceptorOptions, b as StandardLinkOptions, c as StandardLinkPlugin, S as StandardLinkTransport, i as StandardLinkTransportInterceptor, d as StandardLinkTransportInterceptorOptions } from '../../shared/client.euYjjcFz.mjs';
|
|
3
3
|
import { Value, Promisable, Public } from '@orpc/shared';
|
|
4
4
|
import { StandardUrl, StandardHeaders, StandardRequest, StandardLazyResponse } from '@standard-server/core';
|
|
5
5
|
import { ClientContext, ClientOptions } from '../../index.mjs';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { f as StandardLinkCodec, g as StandardLinkCodecDecodedResponse } from '../../shared/client.
|
|
2
|
-
export {
|
|
1
|
+
import { f as StandardLinkCodec, g as StandardLinkCodecDecodedResponse } from '../../shared/client.JBJwBhR8.js';
|
|
2
|
+
export { a as StandardLink, h as StandardLinkInterceptor, e as StandardLinkInterceptorOptions, b as StandardLinkOptions, c as StandardLinkPlugin, S as StandardLinkTransport, i as StandardLinkTransportInterceptor, d as StandardLinkTransportInterceptorOptions } from '../../shared/client.JBJwBhR8.js';
|
|
3
3
|
import { Value, Promisable, Public } from '@orpc/shared';
|
|
4
4
|
import { StandardUrl, StandardHeaders, StandardRequest, StandardLazyResponse } from '@standard-server/core';
|
|
5
5
|
import { ClientContext, ClientOptions } from '../../index.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { R as RPCLinkCodec, S as StandardLink } from '../../shared/client.CKQeJJ2U.mjs';
|
|
2
2
|
import '@orpc/shared';
|
|
3
3
|
import '@standard-server/core';
|
|
4
4
|
import '@standard-server/fetch';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { runWithSignal, AbortError, sleep, promiseWithResolvers, sequential, loadBytes, toStringOrBytes } from '@orpc/shared';
|
|
2
2
|
import { ClientPeer, encodePeerMessage, decodePeerMessage, isServerPeerSendMessage } from '@standard-server/peer';
|
|
3
|
-
import { S as StandardLink, R as RPCLinkCodec } from '../../shared/client.
|
|
3
|
+
import { S as StandardLink, R as RPCLinkCodec } from '../../shared/client.CKQeJJ2U.mjs';
|
|
4
4
|
import '@standard-server/core';
|
|
5
5
|
import '@standard-server/fetch';
|
|
6
6
|
import '../../shared/client.LF04eOvL.mjs';
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { WrapAsyncIteratorOptions, AsyncIteratorClass, Interceptor, PromiseWithError, ThrowableError, Promisable } from '@orpc/shared';
|
|
2
2
|
export { AsyncCleanupFn, AsyncIteratorClass, AsyncIteratorClassNextFn, PromiseWithError as ClientPromiseResult, MaybeOptionalOptions, PromiseWithError, Registry, ThrowableError, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, consumeAsyncIterator, consumeAsyncIterator as consumeEventIterator, asyncIteratorToStream as eventIteratorToStream, asyncIteratorToUnproxiedDataStream as eventIteratorToUnproxiedDataStream, onAsyncIteratorObjectError, onError, onFinish, onReadableStreamError, onStart, onSuccess, streamToAsyncIteratorObject, streamToAsyncIteratorObject as streamToEventIterator } from '@orpc/shared';
|
|
3
|
-
import { C as ClientContext, a as ClientOptions, c as AnyNestedClient, I as InferClientContext, d as InferClientError, e as Client, b as ClientLink, A as AnyORPCError, f as ClientRest,
|
|
4
|
-
export { i as AnyORPCErrorJSON, j as COMMON_ERROR_STATUS_MAP, k as InferClientBodyInputs, l as InferClientBodyOutputs, m as InferClientErrors, n as InferClientInputs, o as InferClientOutputs, M as MalformedResponseError, p as MalformedResponseErrorOptions, N as NestedClient, q as ORPCErrorOptions, R as ResponseError, r as ResponseErrorOptions } from './shared/client.BoHJeq15.mjs';
|
|
3
|
+
import { C as ClientContext, a as ClientOptions, c as AnyNestedClient, I as InferClientContext, d as InferClientError, e as Client, b as ClientLink, A as AnyORPCError, f as ClientRest, O as ORPCErrorCode, g as ORPCErrorJSON, h as ORPCError } from './shared/client.BoHJeq15.mjs';
|
|
4
|
+
export { i as AnyORPCErrorJSON, j as COMMON_ERROR_STATUS_MAP, F as FriendlyClientOptions, k as InferClientBodyInputs, l as InferClientBodyOutputs, m as InferClientErrors, n as InferClientInputs, o as InferClientOutputs, M as MalformedResponseError, p as MalformedResponseErrorOptions, N as NestedClient, q as ORPCErrorOptions, R as ResponseError, r as ResponseErrorOptions } from './shared/client.BoHJeq15.mjs';
|
|
5
5
|
export { R as RPCJsonSerialization, a as RPCJsonSerializationMeta, b as RPCJsonSerializer, c as RPCJsonSerializerHandler, d as RPCJsonSerializerOptions, e as RPCSerializer, f as RPCSerializerOptions, g as RPCSerializerSerializeOptions } from './shared/client.DqIWeNhQ.mjs';
|
|
6
6
|
export { ErrorEvent, EventMeta, StandardBody, StandardBodyHint, StandardHeaders, StandardLazyRequest, StandardLazyResponse, StandardMethod, StandardRequest, StandardResponse, StandardUrl, getEventMeta, unwrapEvent, withEventMeta } from '@standard-server/core';
|
|
7
7
|
|
|
@@ -46,7 +46,6 @@ interface ORPCClientOptions<T extends AnyNestedClient> {
|
|
|
46
46
|
*/
|
|
47
47
|
declare function createORPCClient<T extends AnyNestedClient>(link: ClientLink<InferClientContext<T>>, { path, ...options }?: NoInfer<ORPCClientOptions<T>>): T;
|
|
48
48
|
|
|
49
|
-
declare function resolveFriendlyClientOptions<T extends ClientContext>(options: FriendlyClientOptions<T>): ClientOptions<T>;
|
|
50
49
|
declare function resolveClientRest<TClientContext extends ClientContext, TInput>(rest: ClientRest<TClientContext, TInput>): [input: TInput, options: ClientOptions<TClientContext>];
|
|
51
50
|
type SafeResult<TOutput, TError> = [error: null, data: TOutput, definedError: null, isSuccess: true] & {
|
|
52
51
|
error: null;
|
|
@@ -107,7 +106,7 @@ declare function createSafeClient<T extends AnyNestedClient>(client: T): SafeCli
|
|
|
107
106
|
* proxy for them can cause unexpected behavior, compatibility issues, or
|
|
108
107
|
* infinite proxy chains.
|
|
109
108
|
*/
|
|
110
|
-
declare const RECURSIVE_CLIENT_UNWRAP_KEYS: Set<
|
|
109
|
+
declare const RECURSIVE_CLIENT_UNWRAP_KEYS: Set<PropertyKey>;
|
|
111
110
|
|
|
112
111
|
/**
|
|
113
112
|
* DynamicLink provides a way to dynamically resolve and delegate calls to other ClientLinks
|
|
@@ -141,5 +140,5 @@ declare function createORPCErrorFromJson<TCode extends ORPCErrorCode, TData>(jso
|
|
|
141
140
|
*/
|
|
142
141
|
declare function cloneORPCError<T extends AnyORPCError>(error: T): T;
|
|
143
142
|
|
|
144
|
-
export { AnyNestedClient, AnyORPCError, Client, ClientContext, ClientLink, ClientOptions, ClientRest, DynamicLink,
|
|
143
|
+
export { AnyNestedClient, AnyORPCError, Client, ClientContext, ClientLink, ClientOptions, ClientRest, DynamicLink, InferClientContext, InferClientError, InferClientError as InferClientErrorUnion, ORPCError, ORPCErrorCode, ORPCErrorJSON, RECURSIVE_CLIENT_UNWRAP_KEYS, cloneORPCError, createORPCClient, createORPCErrorFromJson, createSafeClient, isDefinedError, isORPCErrorJson, resolveClientRest, safe, toORPCError, wrapAsyncIteratorPreservingEventMeta };
|
|
145
144
|
export type { ORPCClientInterceptor, ORPCClientInterceptorOptions, ORPCClientOptions, ORPCClientScoped, ORPCClientScopedOptions, SafeClient, SafeResult };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { WrapAsyncIteratorOptions, AsyncIteratorClass, Interceptor, PromiseWithError, ThrowableError, Promisable } from '@orpc/shared';
|
|
2
2
|
export { AsyncCleanupFn, AsyncIteratorClass, AsyncIteratorClassNextFn, PromiseWithError as ClientPromiseResult, MaybeOptionalOptions, PromiseWithError, Registry, ThrowableError, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, consumeAsyncIterator, consumeAsyncIterator as consumeEventIterator, asyncIteratorToStream as eventIteratorToStream, asyncIteratorToUnproxiedDataStream as eventIteratorToUnproxiedDataStream, onAsyncIteratorObjectError, onError, onFinish, onReadableStreamError, onStart, onSuccess, streamToAsyncIteratorObject, streamToAsyncIteratorObject as streamToEventIterator } from '@orpc/shared';
|
|
3
|
-
import { C as ClientContext, a as ClientOptions, c as AnyNestedClient, I as InferClientContext, d as InferClientError, e as Client, b as ClientLink, A as AnyORPCError, f as ClientRest,
|
|
4
|
-
export { i as AnyORPCErrorJSON, j as COMMON_ERROR_STATUS_MAP, k as InferClientBodyInputs, l as InferClientBodyOutputs, m as InferClientErrors, n as InferClientInputs, o as InferClientOutputs, M as MalformedResponseError, p as MalformedResponseErrorOptions, N as NestedClient, q as ORPCErrorOptions, R as ResponseError, r as ResponseErrorOptions } from './shared/client.BoHJeq15.js';
|
|
3
|
+
import { C as ClientContext, a as ClientOptions, c as AnyNestedClient, I as InferClientContext, d as InferClientError, e as Client, b as ClientLink, A as AnyORPCError, f as ClientRest, O as ORPCErrorCode, g as ORPCErrorJSON, h as ORPCError } from './shared/client.BoHJeq15.js';
|
|
4
|
+
export { i as AnyORPCErrorJSON, j as COMMON_ERROR_STATUS_MAP, F as FriendlyClientOptions, k as InferClientBodyInputs, l as InferClientBodyOutputs, m as InferClientErrors, n as InferClientInputs, o as InferClientOutputs, M as MalformedResponseError, p as MalformedResponseErrorOptions, N as NestedClient, q as ORPCErrorOptions, R as ResponseError, r as ResponseErrorOptions } from './shared/client.BoHJeq15.js';
|
|
5
5
|
export { R as RPCJsonSerialization, a as RPCJsonSerializationMeta, b as RPCJsonSerializer, c as RPCJsonSerializerHandler, d as RPCJsonSerializerOptions, e as RPCSerializer, f as RPCSerializerOptions, g as RPCSerializerSerializeOptions } from './shared/client.DqIWeNhQ.js';
|
|
6
6
|
export { ErrorEvent, EventMeta, StandardBody, StandardBodyHint, StandardHeaders, StandardLazyRequest, StandardLazyResponse, StandardMethod, StandardRequest, StandardResponse, StandardUrl, getEventMeta, unwrapEvent, withEventMeta } from '@standard-server/core';
|
|
7
7
|
|
|
@@ -46,7 +46,6 @@ interface ORPCClientOptions<T extends AnyNestedClient> {
|
|
|
46
46
|
*/
|
|
47
47
|
declare function createORPCClient<T extends AnyNestedClient>(link: ClientLink<InferClientContext<T>>, { path, ...options }?: NoInfer<ORPCClientOptions<T>>): T;
|
|
48
48
|
|
|
49
|
-
declare function resolveFriendlyClientOptions<T extends ClientContext>(options: FriendlyClientOptions<T>): ClientOptions<T>;
|
|
50
49
|
declare function resolveClientRest<TClientContext extends ClientContext, TInput>(rest: ClientRest<TClientContext, TInput>): [input: TInput, options: ClientOptions<TClientContext>];
|
|
51
50
|
type SafeResult<TOutput, TError> = [error: null, data: TOutput, definedError: null, isSuccess: true] & {
|
|
52
51
|
error: null;
|
|
@@ -107,7 +106,7 @@ declare function createSafeClient<T extends AnyNestedClient>(client: T): SafeCli
|
|
|
107
106
|
* proxy for them can cause unexpected behavior, compatibility issues, or
|
|
108
107
|
* infinite proxy chains.
|
|
109
108
|
*/
|
|
110
|
-
declare const RECURSIVE_CLIENT_UNWRAP_KEYS: Set<
|
|
109
|
+
declare const RECURSIVE_CLIENT_UNWRAP_KEYS: Set<PropertyKey>;
|
|
111
110
|
|
|
112
111
|
/**
|
|
113
112
|
* DynamicLink provides a way to dynamically resolve and delegate calls to other ClientLinks
|
|
@@ -141,5 +140,5 @@ declare function createORPCErrorFromJson<TCode extends ORPCErrorCode, TData>(jso
|
|
|
141
140
|
*/
|
|
142
141
|
declare function cloneORPCError<T extends AnyORPCError>(error: T): T;
|
|
143
142
|
|
|
144
|
-
export { AnyNestedClient, AnyORPCError, Client, ClientContext, ClientLink, ClientOptions, ClientRest, DynamicLink,
|
|
143
|
+
export { AnyNestedClient, AnyORPCError, Client, ClientContext, ClientLink, ClientOptions, ClientRest, DynamicLink, InferClientContext, InferClientError, InferClientError as InferClientErrorUnion, ORPCError, ORPCErrorCode, ORPCErrorJSON, RECURSIVE_CLIENT_UNWRAP_KEYS, cloneORPCError, createORPCClient, createORPCErrorFromJson, createSafeClient, isDefinedError, isORPCErrorJson, resolveClientRest, safe, toORPCError, wrapAsyncIteratorPreservingEventMeta };
|
|
145
144
|
export type { ORPCClientInterceptor, ORPCClientInterceptorOptions, ORPCClientOptions, ORPCClientScoped, ORPCClientScopedOptions, SafeClient, SafeResult };
|
package/dist/index.mjs
CHANGED
|
@@ -144,4 +144,4 @@ class DynamicLink {
|
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
export { DynamicLink, RECURSIVE_CLIENT_UNWRAP_KEYS, createORPCClient, createSafeClient, isDefinedError, resolveClientRest,
|
|
147
|
+
export { DynamicLink, RECURSIVE_CLIENT_UNWRAP_KEYS, createORPCClient, createSafeClient, isDefinedError, resolveClientRest, safe };
|
package/dist/plugins/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { toArray, value, splitInHalf, promiseWithResolvers, safeEncodeURIComponent, stringifyJSON, once, isAsyncIteratorObject, defer, captureAsyncContext, loadBytes, allAbortSignal, runWithSignal, replicateAsyncIterator, replicateReadableStream, wrapAsyncIterator, throwIfAborted, isCompressibleContentType, override, AsyncIteratorClass, sleep, AbortError, anyAbortSignal } from '@orpc/shared';
|
|
2
2
|
import { parseStandardUrl, flattenStandardHeader, generateContentDisposition, getEventMeta } from '@standard-server/core';
|
|
3
|
-
import { ClientPeer, isServerPeerSendMessage, decodePeerMessage } from '@standard-server/peer';
|
|
4
|
-
import { toFetchHeaders, toStandardBody } from '@standard-server/fetch';
|
|
3
|
+
import { ClientPeer, isPeerMessage, isServerPeerSendMessage, decodePeerMessage } from '@standard-server/peer';
|
|
4
|
+
import { toFetchBody, toFetchHeaders, toStandardBody } from '@standard-server/fetch';
|
|
5
5
|
import { O as ORPCError, R as ResponseError, C as COMMON_ERROR_STATUS_MAP } from '../shared/client.LF04eOvL.mjs';
|
|
6
6
|
|
|
7
7
|
const BATCH_HEADER = "orpc-batch";
|
|
@@ -224,7 +224,7 @@ class BatchLinkPlugin {
|
|
|
224
224
|
return;
|
|
225
225
|
}
|
|
226
226
|
const body = await batchResponse.resolveBody();
|
|
227
|
-
if (Array.isArray(body) && body.every((v) => isServerPeerSendMessage(v))) {
|
|
227
|
+
if (Array.isArray(body) && body.every((v) => isPeerMessage(v) && isServerPeerSendMessage(v))) {
|
|
228
228
|
for (const message of body) {
|
|
229
229
|
await peer.message(message);
|
|
230
230
|
}
|
|
@@ -548,7 +548,6 @@ class RequestCompressionLinkPlugin {
|
|
|
548
548
|
body: compressedStream,
|
|
549
549
|
headers: {
|
|
550
550
|
...request.headers,
|
|
551
|
-
"standard-server": "octet-stream",
|
|
552
551
|
"content-length": [],
|
|
553
552
|
"content-encoding": this.encoding
|
|
554
553
|
}
|
|
@@ -556,7 +555,8 @@ class RequestCompressionLinkPlugin {
|
|
|
556
555
|
});
|
|
557
556
|
}
|
|
558
557
|
} else if (request.body instanceof Blob) {
|
|
559
|
-
|
|
558
|
+
const contentType = request.headers["content-type"] ?? request.body.type;
|
|
559
|
+
if ((!Number.isFinite(request.body.size) || request.body.size >= this.threshold) && this.isCompressibleContentType(flattenStandardHeader(contentType), interceptorOptions)) {
|
|
560
560
|
const compressedStream = request.body.stream().pipeThrough(new CompressionStream(this.encoding));
|
|
561
561
|
const contentDisposition = request.headers["content-disposition"] ?? generateContentDisposition(
|
|
562
562
|
request.body instanceof File ? request.body.name : "blob"
|
|
@@ -568,8 +568,8 @@ class RequestCompressionLinkPlugin {
|
|
|
568
568
|
body: compressedStream,
|
|
569
569
|
headers: {
|
|
570
570
|
...request.headers,
|
|
571
|
-
"standard-server": "file",
|
|
572
|
-
"content-type":
|
|
571
|
+
"standard-server": request.headers["standard-server"] ?? "file",
|
|
572
|
+
"content-type": contentType,
|
|
573
573
|
"content-length": [],
|
|
574
574
|
"content-disposition": contentDisposition,
|
|
575
575
|
"content-encoding": this.encoding
|
|
@@ -618,15 +618,16 @@ class RequestCompressionLinkPlugin {
|
|
|
618
618
|
const string = request.body.toString();
|
|
619
619
|
if (string.length * AVG_BYTES_PER_CHAR >= this.threshold) {
|
|
620
620
|
const compressedStream = new Blob([string]).stream().pipeThrough(new CompressionStream(this.encoding));
|
|
621
|
+
const [, bodyHeaders] = toFetchBody(request.body, request.headers);
|
|
621
622
|
return next({
|
|
622
623
|
...interceptorOptions,
|
|
623
624
|
request: {
|
|
624
625
|
...interceptorOptions.request,
|
|
625
626
|
body: compressedStream,
|
|
626
627
|
headers: {
|
|
627
|
-
...
|
|
628
|
-
|
|
629
|
-
"
|
|
628
|
+
...bodyHeaders,
|
|
629
|
+
// An empty hint rather than none, so the adapter does not hint the compressed stream as `octet-stream`
|
|
630
|
+
"standard-server": bodyHeaders["standard-server"] ?? [],
|
|
630
631
|
"content-length": [],
|
|
631
632
|
"content-encoding": this.encoding
|
|
632
633
|
}
|
|
@@ -634,7 +635,7 @@ class RequestCompressionLinkPlugin {
|
|
|
634
635
|
});
|
|
635
636
|
}
|
|
636
637
|
} else if (request.body !== void 0 && !isAsyncIteratorObject(request.body)) {
|
|
637
|
-
const string =
|
|
638
|
+
const [string, bodyHeaders] = toFetchBody(request.body, request.headers);
|
|
638
639
|
if (string.length * AVG_BYTES_PER_CHAR >= this.threshold) {
|
|
639
640
|
const compressedStream = new Blob([string]).stream().pipeThrough(new CompressionStream(this.encoding));
|
|
640
641
|
return next({
|
|
@@ -643,9 +644,8 @@ class RequestCompressionLinkPlugin {
|
|
|
643
644
|
...interceptorOptions.request,
|
|
644
645
|
body: compressedStream,
|
|
645
646
|
headers: {
|
|
646
|
-
...
|
|
647
|
-
"standard-server": [],
|
|
648
|
-
"content-type": "application/json",
|
|
647
|
+
...bodyHeaders,
|
|
648
|
+
"standard-server": bodyHeaders["standard-server"] ?? [],
|
|
649
649
|
"content-length": [],
|
|
650
650
|
"content-encoding": this.encoding
|
|
651
651
|
}
|
|
@@ -37,12 +37,6 @@ interface StandardLinkPlugin<T extends ClientContext> extends OrderablePlugin {
|
|
|
37
37
|
*/
|
|
38
38
|
init?(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
|
|
39
39
|
}
|
|
40
|
-
declare class CompositeStandardLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
41
|
-
name: string;
|
|
42
|
-
protected readonly plugins: StandardLinkPlugin<T>[];
|
|
43
|
-
constructor(plugins?: StandardLinkPlugin<T>[]);
|
|
44
|
-
init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
|
|
45
|
-
}
|
|
46
40
|
|
|
47
41
|
/**
|
|
48
42
|
* Handles the transport layer for sending requests and receiving responses.
|
|
@@ -92,5 +86,5 @@ declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
|
|
|
92
86
|
call(path: string[], input: unknown, options: ClientOptions<T>): Promise<unknown>;
|
|
93
87
|
}
|
|
94
88
|
|
|
95
|
-
export {
|
|
89
|
+
export { StandardLink as a };
|
|
96
90
|
export type { StandardLinkTransport as S, StandardLinkOptions as b, StandardLinkPlugin as c, StandardLinkTransportInterceptorOptions as d, StandardLinkInterceptorOptions as e, StandardLinkCodec as f, StandardLinkCodecDecodedResponse as g, StandardLinkInterceptor as h, StandardLinkTransportInterceptor as i };
|
|
@@ -37,12 +37,6 @@ interface StandardLinkPlugin<T extends ClientContext> extends OrderablePlugin {
|
|
|
37
37
|
*/
|
|
38
38
|
init?(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
|
|
39
39
|
}
|
|
40
|
-
declare class CompositeStandardLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
41
|
-
name: string;
|
|
42
|
-
protected readonly plugins: StandardLinkPlugin<T>[];
|
|
43
|
-
constructor(plugins?: StandardLinkPlugin<T>[]);
|
|
44
|
-
init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
|
|
45
|
-
}
|
|
46
40
|
|
|
47
41
|
/**
|
|
48
42
|
* Handles the transport layer for sending requests and receiving responses.
|
|
@@ -92,5 +86,5 @@ declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
|
|
|
92
86
|
call(path: string[], input: unknown, options: ClientOptions<T>): Promise<unknown>;
|
|
93
87
|
}
|
|
94
88
|
|
|
95
|
-
export {
|
|
89
|
+
export { StandardLink as a };
|
|
96
90
|
export type { StandardLinkTransport as S, StandardLinkOptions as b, StandardLinkPlugin as c, StandardLinkTransportInterceptorOptions as d, StandardLinkInterceptorOptions as e, StandardLinkCodec as f, StandardLinkCodecDecodedResponse as g, StandardLinkInterceptor as h, StandardLinkTransportInterceptor as i };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/client",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.47",
|
|
5
5
|
"description": "Consume oRPC and OpenAPI APIs with end-to-end type safety over HTTP, WebSocket, or message ports",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": [
|
|
@@ -63,10 +63,10 @@
|
|
|
63
63
|
"dist"
|
|
64
64
|
],
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@orpc/shared": "2.0.0-beta.
|
|
67
|
-
"@standard-server/core": "~0.
|
|
68
|
-
"@standard-server/fetch": "~0.
|
|
69
|
-
"@standard-server/peer": "~0.
|
|
66
|
+
"@orpc/shared": "2.0.0-beta.47",
|
|
67
|
+
"@standard-server/core": "~0.13.0",
|
|
68
|
+
"@standard-server/fetch": "~0.13.0",
|
|
69
|
+
"@standard-server/peer": "~0.13.0"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
72
|
"@types/ws": "^8.18.2",
|