@orpc/client 0.0.0-next.cba521d → 0.0.0-next.cc8802c
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 +88 -0
- package/dist/adapters/fetch/index.d.mts +29 -0
- package/dist/adapters/fetch/index.d.ts +29 -0
- package/dist/adapters/fetch/index.mjs +35 -0
- package/dist/adapters/standard/index.d.mts +148 -0
- package/dist/adapters/standard/index.d.ts +148 -0
- package/dist/adapters/standard/index.mjs +4 -0
- package/dist/index.d.mts +155 -0
- package/dist/index.d.ts +155 -0
- package/dist/index.mjs +63 -0
- package/dist/shared/client.D_CzLDyB.d.mts +42 -0
- package/dist/shared/client.D_CzLDyB.d.ts +42 -0
- package/dist/shared/client.Df5pd75N.mjs +320 -0
- package/dist/shared/client.XAn8cDTM.mjs +266 -0
- package/package.json +17 -18
- package/dist/fetch.js +0 -89
- package/dist/index.js +0 -42
- package/dist/src/adapters/fetch/index.d.ts +0 -3
- package/dist/src/adapters/fetch/orpc-link.d.ts +0 -46
- package/dist/src/adapters/fetch/types.d.ts +0 -4
- package/dist/src/client.d.ts +0 -11
- package/dist/src/dynamic-link.d.ts +0 -13
- package/dist/src/index.d.ts +0 -6
- package/dist/src/types.d.ts +0 -5
package/README.md
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
<div align="center">
|
2
|
+
<image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 alt="oRPC logo" />
|
3
|
+
</div>
|
4
|
+
|
5
|
+
<h1></h1>
|
6
|
+
|
7
|
+
<div align="center">
|
8
|
+
<a href="https://codecov.io/gh/unnoq/orpc">
|
9
|
+
<img alt="codecov" src="https://codecov.io/gh/unnoq/orpc/branch/main/graph/badge.svg">
|
10
|
+
</a>
|
11
|
+
<a href="https://www.npmjs.com/package/@orpc/client">
|
12
|
+
<img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40orpc%2Fclient?logo=npm" />
|
13
|
+
</a>
|
14
|
+
<a href="https://github.com/unnoq/orpc/blob/main/LICENSE">
|
15
|
+
<img alt="MIT License" src="https://img.shields.io/github/license/unnoq/orpc?logo=open-source-initiative" />
|
16
|
+
</a>
|
17
|
+
<a href="https://discord.gg/TXEbwRBvQn">
|
18
|
+
<img alt="Discord" src="https://img.shields.io/discord/1308966753044398161?color=7389D8&label&logo=discord&logoColor=ffffff" />
|
19
|
+
</a>
|
20
|
+
</div>
|
21
|
+
|
22
|
+
<h3 align="center">Typesafe APIs Made Simple 🪄</h3>
|
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.
|
25
|
+
|
26
|
+
---
|
27
|
+
|
28
|
+
## Highlights
|
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.
|
46
|
+
|
47
|
+
## Documentation
|
48
|
+
|
49
|
+
You can find the full documentation [here](https://orpc.unnoq.com).
|
50
|
+
|
51
|
+
## Packages
|
52
|
+
|
53
|
+
- [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
|
54
|
+
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
55
|
+
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
56
|
+
- [@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
|
+
- [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
|
58
|
+
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
59
|
+
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
60
|
+
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
61
|
+
|
62
|
+
## `@orpc/client`
|
63
|
+
|
64
|
+
Consume your API on the client with type-safety. Read the [documentation](https://orpc.unnoq.com/docs/client/client-side) for more information.
|
65
|
+
|
66
|
+
```ts
|
67
|
+
import { createORPCClient } from '@orpc/client'
|
68
|
+
import { RPCLink } from '@orpc/client/fetch'
|
69
|
+
import { ContractRouterClient } from '@orpc/contract'
|
70
|
+
import { RouterClient } from '@orpc/server'
|
71
|
+
|
72
|
+
const link = new RPCLink({
|
73
|
+
url: 'http://localhost:3000/rpc',
|
74
|
+
headers: () => ({
|
75
|
+
authorization: 'Bearer token',
|
76
|
+
}),
|
77
|
+
// fetch: <-- provide fetch polyfill fetch if needed
|
78
|
+
})
|
79
|
+
|
80
|
+
// Create a client for your router
|
81
|
+
const client: RouterClient<typeof router> = createORPCClient(link)
|
82
|
+
// Or, create a client using a contract
|
83
|
+
const client: ContractRouterClient<typeof contract> = createORPCClient(link)
|
84
|
+
```
|
85
|
+
|
86
|
+
## License
|
87
|
+
|
88
|
+
Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
2
|
+
import { ToFetchRequestOptions } from '@orpc/standard-server-fetch';
|
3
|
+
import { C as ClientContext, a as ClientOptionsOut, b as ClientLink } from '../../shared/client.D_CzLDyB.mjs';
|
4
|
+
import { StandardLinkClient, StandardLinkOptions, StandardRPCLinkCodecOptions } from '../standard/index.mjs';
|
5
|
+
import '@orpc/shared';
|
6
|
+
|
7
|
+
interface LinkFetchClientOptions<T extends ClientContext> extends ToFetchRequestOptions {
|
8
|
+
fetch?: (request: Request, init: Record<never, never>, options: ClientOptionsOut<T>, path: readonly string[], input: unknown) => Promise<Response>;
|
9
|
+
}
|
10
|
+
declare class LinkFetchClient<T extends ClientContext> implements StandardLinkClient<T> {
|
11
|
+
private readonly fetch;
|
12
|
+
private readonly toFetchRequestOptions;
|
13
|
+
constructor(options: LinkFetchClientOptions<T>);
|
14
|
+
call(request: StandardRequest, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
|
15
|
+
}
|
16
|
+
|
17
|
+
interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardRPCLinkCodecOptions<T>, LinkFetchClientOptions<T> {
|
18
|
+
}
|
19
|
+
declare class RPCLink<T extends ClientContext> implements ClientLink<T> {
|
20
|
+
private readonly standardLink;
|
21
|
+
constructor(options: RPCLinkOptions<T>);
|
22
|
+
call(path: readonly string[], input: unknown, options: ClientOptionsOut<T>): Promise<unknown>;
|
23
|
+
}
|
24
|
+
|
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, LinkFetchClient, type LinkFetchClientOptions, RPCLink, type RPCLinkOptions };
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
2
|
+
import { ToFetchRequestOptions } from '@orpc/standard-server-fetch';
|
3
|
+
import { C as ClientContext, a as ClientOptionsOut, b as ClientLink } from '../../shared/client.D_CzLDyB.js';
|
4
|
+
import { StandardLinkClient, StandardLinkOptions, StandardRPCLinkCodecOptions } from '../standard/index.js';
|
5
|
+
import '@orpc/shared';
|
6
|
+
|
7
|
+
interface LinkFetchClientOptions<T extends ClientContext> extends ToFetchRequestOptions {
|
8
|
+
fetch?: (request: Request, init: Record<never, never>, options: ClientOptionsOut<T>, path: readonly string[], input: unknown) => Promise<Response>;
|
9
|
+
}
|
10
|
+
declare class LinkFetchClient<T extends ClientContext> implements StandardLinkClient<T> {
|
11
|
+
private readonly fetch;
|
12
|
+
private readonly toFetchRequestOptions;
|
13
|
+
constructor(options: LinkFetchClientOptions<T>);
|
14
|
+
call(request: StandardRequest, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
|
15
|
+
}
|
16
|
+
|
17
|
+
interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardRPCLinkCodecOptions<T>, LinkFetchClientOptions<T> {
|
18
|
+
}
|
19
|
+
declare class RPCLink<T extends ClientContext> implements ClientLink<T> {
|
20
|
+
private readonly standardLink;
|
21
|
+
constructor(options: RPCLinkOptions<T>);
|
22
|
+
call(path: readonly string[], input: unknown, options: ClientOptionsOut<T>): Promise<unknown>;
|
23
|
+
}
|
24
|
+
|
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, LinkFetchClient, type LinkFetchClientOptions, RPCLink, type RPCLinkOptions };
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import { toFetchRequest, toStandardLazyResponse } from '@orpc/standard-server-fetch';
|
2
|
+
import { a as StandardRPCLinkCodec, b as RPCSerializer, S as StandardLink } from '../../shared/client.Df5pd75N.mjs';
|
3
|
+
import '@orpc/shared';
|
4
|
+
import '../../shared/client.XAn8cDTM.mjs';
|
5
|
+
import '@orpc/standard-server';
|
6
|
+
|
7
|
+
class LinkFetchClient {
|
8
|
+
fetch;
|
9
|
+
toFetchRequestOptions;
|
10
|
+
constructor(options) {
|
11
|
+
this.fetch = options?.fetch ?? globalThis.fetch.bind(globalThis);
|
12
|
+
this.toFetchRequestOptions = options;
|
13
|
+
}
|
14
|
+
async call(request, options, path, input) {
|
15
|
+
const fetchRequest = toFetchRequest(request, this.toFetchRequestOptions);
|
16
|
+
const fetchResponse = await this.fetch(fetchRequest, {}, options, path, input);
|
17
|
+
const lazyResponse = toStandardLazyResponse(fetchResponse);
|
18
|
+
return lazyResponse;
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
class RPCLink {
|
23
|
+
standardLink;
|
24
|
+
constructor(options) {
|
25
|
+
const serializer = new RPCSerializer();
|
26
|
+
const linkCodec = new StandardRPCLinkCodec(serializer, options);
|
27
|
+
const linkClient = new LinkFetchClient(options);
|
28
|
+
this.standardLink = new StandardLink(linkCodec, linkClient, options);
|
29
|
+
}
|
30
|
+
async call(path, input, options) {
|
31
|
+
return this.standardLink.call(path, input, options);
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
export { LinkFetchClient, RPCLink };
|
@@ -0,0 +1,148 @@
|
|
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';
|
4
|
+
|
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
|
+
}
|
12
|
+
|
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
|
+
}
|
136
|
+
declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
|
137
|
+
private readonly serializer;
|
138
|
+
private readonly baseUrl;
|
139
|
+
private readonly maxUrlLength;
|
140
|
+
private readonly fallbackMethod;
|
141
|
+
private readonly expectedMethod;
|
142
|
+
private readonly headers;
|
143
|
+
constructor(serializer: RPCSerializer, options: StandardRPCLinkCodecOptions<T>);
|
144
|
+
encode(path: readonly string[], input: unknown, options: ClientOptionsOut<any>): Promise<StandardRequest>;
|
145
|
+
decode(response: StandardLazyResponse): Promise<unknown>;
|
146
|
+
}
|
147
|
+
|
148
|
+
export { InvalidEventIteratorRetryResponse, type RPCJsonSerialized, type RPCJsonSerializedMeta, RPCJsonSerializer, RPCSerializer, StandardLink, type StandardLinkClient, type StandardLinkCodec, type StandardLinkOptions, StandardRPCLinkCodec, type StandardRPCLinkCodecOptions };
|
@@ -0,0 +1,148 @@
|
|
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.js';
|
4
|
+
|
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
|
+
}
|
12
|
+
|
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
|
+
}
|
136
|
+
declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
|
137
|
+
private readonly serializer;
|
138
|
+
private readonly baseUrl;
|
139
|
+
private readonly maxUrlLength;
|
140
|
+
private readonly fallbackMethod;
|
141
|
+
private readonly expectedMethod;
|
142
|
+
private readonly headers;
|
143
|
+
constructor(serializer: RPCSerializer, options: StandardRPCLinkCodecOptions<T>);
|
144
|
+
encode(path: readonly string[], input: unknown, options: ClientOptionsOut<any>): Promise<StandardRequest>;
|
145
|
+
decode(response: StandardLazyResponse): Promise<unknown>;
|
146
|
+
}
|
147
|
+
|
148
|
+
export { InvalidEventIteratorRetryResponse, type RPCJsonSerialized, type RPCJsonSerializedMeta, RPCJsonSerializer, RPCSerializer, StandardLink, type StandardLinkClient, type StandardLinkCodec, type StandardLinkOptions, StandardRPCLinkCodec, type StandardRPCLinkCodecOptions };
|
@@ -0,0 +1,4 @@
|
|
1
|
+
export { I as InvalidEventIteratorRetryResponse, R as RPCJsonSerializer, b as RPCSerializer, S as StandardLink, a as StandardRPCLinkCodec } from '../../shared/client.Df5pd75N.mjs';
|
2
|
+
import '@orpc/shared';
|
3
|
+
import '../../shared/client.XAn8cDTM.mjs';
|
4
|
+
import '@orpc/standard-server';
|
package/dist/index.d.mts
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
import { N as NestedClient, b as ClientLink, I as InferClientContext, C as ClientContext, a as ClientOptionsOut, c as ClientPromiseResult } from './shared/client.D_CzLDyB.mjs';
|
2
|
+
export { g as Client, e as ClientOptions, f as ClientRest, E as EventIteratorReconnectOptions, d as createAutoRetryEventIterator, m as mapEventIterator } from './shared/client.D_CzLDyB.mjs';
|
3
|
+
import { Promisable, MaybeOptionalOptions } from '@orpc/shared';
|
4
|
+
export { ErrorEvent } from '@orpc/standard-server';
|
5
|
+
|
6
|
+
interface createORPCClientOptions {
|
7
|
+
/**
|
8
|
+
* Use as base path for all procedure, useful when you only want to call a subset of the procedure.
|
9
|
+
*/
|
10
|
+
path?: string[];
|
11
|
+
}
|
12
|
+
declare function createORPCClient<T extends NestedClient<any>>(link: ClientLink<InferClientContext<T>>, options?: createORPCClientOptions): T;
|
13
|
+
|
14
|
+
/**
|
15
|
+
* DynamicLink provides a way to dynamically resolve and delegate calls to other ClientLinks
|
16
|
+
* based on the request path, input, and context.
|
17
|
+
*/
|
18
|
+
declare class DynamicLink<TClientContext extends ClientContext> implements ClientLink<TClientContext> {
|
19
|
+
private readonly linkResolver;
|
20
|
+
constructor(linkResolver: (options: ClientOptionsOut<TClientContext>, path: readonly string[], input: unknown) => Promisable<ClientLink<TClientContext>>);
|
21
|
+
call(path: readonly string[], input: unknown, options: ClientOptionsOut<TClientContext>): Promise<unknown>;
|
22
|
+
}
|
23
|
+
|
24
|
+
declare const COMMON_ORPC_ERROR_DEFS: {
|
25
|
+
readonly BAD_REQUEST: {
|
26
|
+
readonly status: 400;
|
27
|
+
readonly message: "Bad Request";
|
28
|
+
};
|
29
|
+
readonly UNAUTHORIZED: {
|
30
|
+
readonly status: 401;
|
31
|
+
readonly message: "Unauthorized";
|
32
|
+
};
|
33
|
+
readonly FORBIDDEN: {
|
34
|
+
readonly status: 403;
|
35
|
+
readonly message: "Forbidden";
|
36
|
+
};
|
37
|
+
readonly NOT_FOUND: {
|
38
|
+
readonly status: 404;
|
39
|
+
readonly message: "Not Found";
|
40
|
+
};
|
41
|
+
readonly METHOD_NOT_SUPPORTED: {
|
42
|
+
readonly status: 405;
|
43
|
+
readonly message: "Method Not Supported";
|
44
|
+
};
|
45
|
+
readonly NOT_ACCEPTABLE: {
|
46
|
+
readonly status: 406;
|
47
|
+
readonly message: "Not Acceptable";
|
48
|
+
};
|
49
|
+
readonly TIMEOUT: {
|
50
|
+
readonly status: 408;
|
51
|
+
readonly message: "Request Timeout";
|
52
|
+
};
|
53
|
+
readonly CONFLICT: {
|
54
|
+
readonly status: 409;
|
55
|
+
readonly message: "Conflict";
|
56
|
+
};
|
57
|
+
readonly PRECONDITION_FAILED: {
|
58
|
+
readonly status: 412;
|
59
|
+
readonly message: "Precondition Failed";
|
60
|
+
};
|
61
|
+
readonly PAYLOAD_TOO_LARGE: {
|
62
|
+
readonly status: 413;
|
63
|
+
readonly message: "Payload Too Large";
|
64
|
+
};
|
65
|
+
readonly UNSUPPORTED_MEDIA_TYPE: {
|
66
|
+
readonly status: 415;
|
67
|
+
readonly message: "Unsupported Media Type";
|
68
|
+
};
|
69
|
+
readonly UNPROCESSABLE_CONTENT: {
|
70
|
+
readonly status: 422;
|
71
|
+
readonly message: "Unprocessable Content";
|
72
|
+
};
|
73
|
+
readonly TOO_MANY_REQUESTS: {
|
74
|
+
readonly status: 429;
|
75
|
+
readonly message: "Too Many Requests";
|
76
|
+
};
|
77
|
+
readonly CLIENT_CLOSED_REQUEST: {
|
78
|
+
readonly status: 499;
|
79
|
+
readonly message: "Client Closed Request";
|
80
|
+
};
|
81
|
+
readonly INTERNAL_SERVER_ERROR: {
|
82
|
+
readonly status: 500;
|
83
|
+
readonly message: "Internal Server Error";
|
84
|
+
};
|
85
|
+
readonly NOT_IMPLEMENTED: {
|
86
|
+
readonly status: 501;
|
87
|
+
readonly message: "Not Implemented";
|
88
|
+
};
|
89
|
+
readonly BAD_GATEWAY: {
|
90
|
+
readonly status: 502;
|
91
|
+
readonly message: "Bad Gateway";
|
92
|
+
};
|
93
|
+
readonly SERVICE_UNAVAILABLE: {
|
94
|
+
readonly status: 503;
|
95
|
+
readonly message: "Service Unavailable";
|
96
|
+
};
|
97
|
+
readonly GATEWAY_TIMEOUT: {
|
98
|
+
readonly status: 504;
|
99
|
+
readonly message: "Gateway Timeout";
|
100
|
+
};
|
101
|
+
};
|
102
|
+
type CommonORPCErrorCode = keyof typeof COMMON_ORPC_ERROR_DEFS;
|
103
|
+
type ORPCErrorCode = CommonORPCErrorCode | (string & {});
|
104
|
+
declare function fallbackORPCErrorStatus(code: ORPCErrorCode, status: number | undefined): number;
|
105
|
+
declare function fallbackORPCErrorMessage(code: ORPCErrorCode, message: string | undefined): string;
|
106
|
+
type ORPCErrorOptions<TData> = ErrorOptions & {
|
107
|
+
defined?: boolean;
|
108
|
+
status?: number;
|
109
|
+
message?: string;
|
110
|
+
} & (undefined extends TData ? {
|
111
|
+
data?: TData;
|
112
|
+
} : {
|
113
|
+
data: TData;
|
114
|
+
});
|
115
|
+
declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error {
|
116
|
+
readonly defined: boolean;
|
117
|
+
readonly code: TCode;
|
118
|
+
readonly status: number;
|
119
|
+
readonly data: TData;
|
120
|
+
constructor(code: TCode, ...[options]: MaybeOptionalOptions<ORPCErrorOptions<TData>>);
|
121
|
+
toJSON(): ORPCErrorJSON<TCode, TData>;
|
122
|
+
static fromJSON<TCode extends ORPCErrorCode, TData>(json: ORPCErrorJSON<TCode, TData>, options?: ErrorOptions): ORPCError<TCode, TData>;
|
123
|
+
static isValidJSON(json: unknown): json is ORPCErrorJSON<ORPCErrorCode, unknown>;
|
124
|
+
}
|
125
|
+
type ORPCErrorJSON<TCode extends string, TData> = Pick<ORPCError<TCode, TData>, 'defined' | 'code' | 'status' | 'message' | 'data'>;
|
126
|
+
declare function isDefinedError<T>(error: T): error is Extract<T, ORPCError<any, any>>;
|
127
|
+
declare function toORPCError(error: unknown): ORPCError<any, any>;
|
128
|
+
|
129
|
+
type ConnectionStatus = 'reconnecting' | 'connected' | 'closed';
|
130
|
+
interface EventIteratorState {
|
131
|
+
status: ConnectionStatus;
|
132
|
+
listeners: Array<(newStatus: ConnectionStatus) => void>;
|
133
|
+
}
|
134
|
+
declare function registerEventIteratorState(iterator: AsyncIteratorObject<unknown, unknown, void>, state: EventIteratorState): void;
|
135
|
+
declare function updateEventIteratorStatus(state: EventIteratorState, status: ConnectionStatus): void;
|
136
|
+
declare function onEventIteratorStatusChange(iterator: AsyncIteratorObject<unknown, unknown, void>, callback: (status: ConnectionStatus) => void, options?: {
|
137
|
+
notifyImmediately?: boolean;
|
138
|
+
}): () => void;
|
139
|
+
|
140
|
+
type SafeResult<TOutput, TError extends Error> = [error: null, data: TOutput, isDefined: false] & {
|
141
|
+
error: null;
|
142
|
+
data: TOutput;
|
143
|
+
isDefined: false;
|
144
|
+
} | [error: Exclude<TError, ORPCError<any, any>>, data: undefined, isDefined: false] & {
|
145
|
+
error: Exclude<TError, ORPCError<any, any>>;
|
146
|
+
data: undefined;
|
147
|
+
isDefined: false;
|
148
|
+
} | [error: Extract<TError, ORPCError<any, any>>, data: undefined, isDefined: true] & {
|
149
|
+
error: Extract<TError, ORPCError<any, any>>;
|
150
|
+
data: undefined;
|
151
|
+
isDefined: true;
|
152
|
+
};
|
153
|
+
declare function safe<TOutput, TError extends Error>(promise: ClientPromiseResult<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
|
154
|
+
|
155
|
+
export { COMMON_ORPC_ERROR_DEFS, ClientContext, ClientLink, ClientOptionsOut, ClientPromiseResult, type CommonORPCErrorCode, type ConnectionStatus, DynamicLink, type EventIteratorState, InferClientContext, NestedClient, ORPCError, type ORPCErrorCode, type ORPCErrorJSON, type ORPCErrorOptions, type SafeResult, createORPCClient, type createORPCClientOptions, fallbackORPCErrorMessage, fallbackORPCErrorStatus, isDefinedError, onEventIteratorStatusChange, registerEventIteratorState, safe, toORPCError, updateEventIteratorStatus };
|