@orpc/client 0.0.0-next.c29cb6d → 0.0.0-next.c40d0c9
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 +101 -0
- package/dist/adapters/fetch/index.d.mts +26 -0
- package/dist/adapters/fetch/index.d.ts +26 -0
- package/dist/adapters/fetch/index.mjs +32 -0
- package/dist/adapters/standard/index.d.mts +10 -0
- package/dist/adapters/standard/index.d.ts +10 -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 +65 -0
- package/dist/plugins/index.d.mts +65 -0
- package/dist/plugins/index.d.ts +65 -0
- package/dist/plugins/index.mjs +131 -0
- package/dist/shared/client.5813Ufvs.d.mts +39 -0
- package/dist/shared/client.Bt94sjrK.d.mts +103 -0
- package/dist/shared/client.C0lT7w02.d.mts +30 -0
- package/dist/shared/client.C0lT7w02.d.ts +30 -0
- package/dist/shared/client.D-jrSuDb.d.ts +103 -0
- package/dist/shared/client.DSPm2IGZ.mjs +337 -0
- package/dist/shared/client.grRbC25r.d.ts +39 -0
- package/dist/shared/client.jKEwIsRd.mjs +175 -0
- package/package.json +22 -20
- package/dist/fetch.js +0 -46
- package/dist/index.js +0 -39
- package/dist/src/adapters/fetch/index.d.ts +0 -3
- package/dist/src/adapters/fetch/orpc-link.d.ts +0 -19
- 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 -15
- package/dist/src/index.d.ts +0 -6
- package/dist/src/types.d.ts +0 -5
package/README.md
ADDED
@@ -0,0 +1,101 @@
|
|
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, Solid, Svelte), 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](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
57
|
+
- [@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
|
58
|
+
- [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
|
59
|
+
- [@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
|
60
|
+
- [@orpc/svelte-query](https://www.npmjs.com/package/@orpc/svelte-query): Integration with [Svelte Query](https://tanstack.com/query/latest/docs/framework/svelte/overview).
|
61
|
+
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
62
|
+
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
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.unnoq.com/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
|
+
```
|
90
|
+
|
91
|
+
## Sponsors
|
92
|
+
|
93
|
+
<p align="center">
|
94
|
+
<a href="https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg">
|
95
|
+
<img src='https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg'/>
|
96
|
+
</a>
|
97
|
+
</p>
|
98
|
+
|
99
|
+
## License
|
100
|
+
|
101
|
+
Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
2
|
+
import { ToFetchRequestOptions } from '@orpc/standard-server-fetch';
|
3
|
+
import { a as ClientContext, b as ClientOptions } from '../../shared/client.C0lT7w02.mjs';
|
4
|
+
import { d as StandardLinkClient, b as StandardLink } from '../../shared/client.5813Ufvs.mjs';
|
5
|
+
import { f as StandardRPCLinkOptions } from '../../shared/client.Bt94sjrK.mjs';
|
6
|
+
import '@orpc/shared';
|
7
|
+
|
8
|
+
interface LinkFetchClientOptions<T extends ClientContext> extends ToFetchRequestOptions {
|
9
|
+
fetch?: (request: Request, init: {
|
10
|
+
redirect?: Request['redirect'];
|
11
|
+
}, options: ClientOptions<T>, path: readonly string[], input: unknown) => Promise<Response>;
|
12
|
+
}
|
13
|
+
declare class LinkFetchClient<T extends ClientContext> implements StandardLinkClient<T> {
|
14
|
+
private readonly fetch;
|
15
|
+
private readonly toFetchRequestOptions;
|
16
|
+
constructor(options: LinkFetchClientOptions<T>);
|
17
|
+
call(request: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
|
18
|
+
}
|
19
|
+
|
20
|
+
interface RPCLinkOptions<T extends ClientContext> extends StandardRPCLinkOptions<T>, LinkFetchClientOptions<T> {
|
21
|
+
}
|
22
|
+
declare class RPCLink<T extends ClientContext> extends StandardLink<T> {
|
23
|
+
constructor(options: RPCLinkOptions<T>);
|
24
|
+
}
|
25
|
+
|
26
|
+
export { LinkFetchClient, type LinkFetchClientOptions, RPCLink, type RPCLinkOptions };
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
2
|
+
import { ToFetchRequestOptions } from '@orpc/standard-server-fetch';
|
3
|
+
import { a as ClientContext, b as ClientOptions } from '../../shared/client.C0lT7w02.js';
|
4
|
+
import { d as StandardLinkClient, b as StandardLink } from '../../shared/client.grRbC25r.js';
|
5
|
+
import { f as StandardRPCLinkOptions } from '../../shared/client.D-jrSuDb.js';
|
6
|
+
import '@orpc/shared';
|
7
|
+
|
8
|
+
interface LinkFetchClientOptions<T extends ClientContext> extends ToFetchRequestOptions {
|
9
|
+
fetch?: (request: Request, init: {
|
10
|
+
redirect?: Request['redirect'];
|
11
|
+
}, options: ClientOptions<T>, path: readonly string[], input: unknown) => Promise<Response>;
|
12
|
+
}
|
13
|
+
declare class LinkFetchClient<T extends ClientContext> implements StandardLinkClient<T> {
|
14
|
+
private readonly fetch;
|
15
|
+
private readonly toFetchRequestOptions;
|
16
|
+
constructor(options: LinkFetchClientOptions<T>);
|
17
|
+
call(request: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
|
18
|
+
}
|
19
|
+
|
20
|
+
interface RPCLinkOptions<T extends ClientContext> extends StandardRPCLinkOptions<T>, LinkFetchClientOptions<T> {
|
21
|
+
}
|
22
|
+
declare class RPCLink<T extends ClientContext> extends StandardLink<T> {
|
23
|
+
constructor(options: RPCLinkOptions<T>);
|
24
|
+
}
|
25
|
+
|
26
|
+
export { LinkFetchClient, type LinkFetchClientOptions, RPCLink, type RPCLinkOptions };
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import { toFetchRequest, toStandardLazyResponse } from '@orpc/standard-server-fetch';
|
2
|
+
import { S as StandardLink, b as StandardRPCJsonSerializer, c as StandardRPCLinkCodec, d as StandardRPCSerializer } from '../../shared/client.DSPm2IGZ.mjs';
|
3
|
+
import '@orpc/shared';
|
4
|
+
import '@orpc/standard-server';
|
5
|
+
import '../../shared/client.jKEwIsRd.mjs';
|
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, { redirect: "manual" }, options, path, input);
|
17
|
+
const lazyResponse = toStandardLazyResponse(fetchResponse);
|
18
|
+
return lazyResponse;
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
class RPCLink extends StandardLink {
|
23
|
+
constructor(options) {
|
24
|
+
const jsonSerializer = new StandardRPCJsonSerializer(options);
|
25
|
+
const serializer = new StandardRPCSerializer(jsonSerializer);
|
26
|
+
const linkCodec = new StandardRPCLinkCodec(serializer, options);
|
27
|
+
const linkClient = new LinkFetchClient(options);
|
28
|
+
super(linkCodec, linkClient, options);
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
export { LinkFetchClient, RPCLink };
|
@@ -0,0 +1,10 @@
|
|
1
|
+
export { I as InvalidEventIteratorRetryResponse, b as StandardLink, d as StandardLinkClient, c as StandardLinkCodec, a as StandardLinkOptions, S as StandardLinkPlugin } from '../../shared/client.5813Ufvs.mjs';
|
2
|
+
export { S as STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES, c as StandardRPCCustomJsonSerializer, b as StandardRPCJsonSerialized, a as StandardRPCJsonSerializedMetaItem, e as StandardRPCJsonSerializer, d as StandardRPCJsonSerializerOptions, h as StandardRPCLinkCodec, g as StandardRPCLinkCodecOptions, f as StandardRPCLinkOptions, i as StandardRPCSerializer } from '../../shared/client.Bt94sjrK.mjs';
|
3
|
+
import { H as HTTPPath } from '../../shared/client.C0lT7w02.mjs';
|
4
|
+
import '@orpc/shared';
|
5
|
+
import '@orpc/standard-server';
|
6
|
+
|
7
|
+
declare function toHttpPath(path: readonly string[]): HTTPPath;
|
8
|
+
declare function getMalformedResponseErrorCode(status: number): string;
|
9
|
+
|
10
|
+
export { getMalformedResponseErrorCode, toHttpPath };
|
@@ -0,0 +1,10 @@
|
|
1
|
+
export { I as InvalidEventIteratorRetryResponse, b as StandardLink, d as StandardLinkClient, c as StandardLinkCodec, a as StandardLinkOptions, S as StandardLinkPlugin } from '../../shared/client.grRbC25r.js';
|
2
|
+
export { S as STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES, c as StandardRPCCustomJsonSerializer, b as StandardRPCJsonSerialized, a as StandardRPCJsonSerializedMetaItem, e as StandardRPCJsonSerializer, d as StandardRPCJsonSerializerOptions, h as StandardRPCLinkCodec, g as StandardRPCLinkCodecOptions, f as StandardRPCLinkOptions, i as StandardRPCSerializer } from '../../shared/client.D-jrSuDb.js';
|
3
|
+
import { H as HTTPPath } from '../../shared/client.C0lT7w02.js';
|
4
|
+
import '@orpc/shared';
|
5
|
+
import '@orpc/standard-server';
|
6
|
+
|
7
|
+
declare function toHttpPath(path: readonly string[]): HTTPPath;
|
8
|
+
declare function getMalformedResponseErrorCode(status: number): string;
|
9
|
+
|
10
|
+
export { getMalformedResponseErrorCode, toHttpPath };
|
@@ -0,0 +1,4 @@
|
|
1
|
+
export { I as InvalidEventIteratorRetryResponse, a as STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES, S as StandardLink, b as StandardRPCJsonSerializer, c as StandardRPCLinkCodec, d as StandardRPCSerializer, g as getMalformedResponseErrorCode, t as toHttpPath } from '../../shared/client.DSPm2IGZ.mjs';
|
2
|
+
import '@orpc/shared';
|
3
|
+
import '@orpc/standard-server';
|
4
|
+
import '../../shared/client.jKEwIsRd.mjs';
|
package/dist/index.d.mts
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
import { N as NestedClient, C as ClientLink, I as InferClientContext, a as ClientContext, b as ClientOptions, c as ClientPromiseResult, F as FriendlyClientOptions } from './shared/client.C0lT7w02.mjs';
|
2
|
+
export { f as Client, e as ClientRest, d as HTTPMethod, H as HTTPPath } from './shared/client.C0lT7w02.mjs';
|
3
|
+
import { Promisable, MaybeOptionalOptions, ThrowableError } from '@orpc/shared';
|
4
|
+
export { Registry, ThrowableError, onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
5
|
+
export { ErrorEvent } from '@orpc/standard-server';
|
6
|
+
|
7
|
+
interface createORPCClientOptions {
|
8
|
+
/**
|
9
|
+
* Use as base path for all procedure, useful when you only want to call a subset of the procedure.
|
10
|
+
*/
|
11
|
+
path?: string[];
|
12
|
+
}
|
13
|
+
declare function createORPCClient<T extends NestedClient<any>>(link: ClientLink<InferClientContext<T>>, options?: createORPCClientOptions): T;
|
14
|
+
|
15
|
+
/**
|
16
|
+
* DynamicLink provides a way to dynamically resolve and delegate calls to other ClientLinks
|
17
|
+
* based on the request path, input, and context.
|
18
|
+
*/
|
19
|
+
declare class DynamicLink<TClientContext extends ClientContext> implements ClientLink<TClientContext> {
|
20
|
+
private readonly linkResolver;
|
21
|
+
constructor(linkResolver: (options: ClientOptions<TClientContext>, path: readonly string[], input: unknown) => Promisable<ClientLink<TClientContext>>);
|
22
|
+
call(path: readonly string[], input: unknown, options: ClientOptions<TClientContext>): Promise<unknown>;
|
23
|
+
}
|
24
|
+
|
25
|
+
declare const COMMON_ORPC_ERROR_DEFS: {
|
26
|
+
readonly BAD_REQUEST: {
|
27
|
+
readonly status: 400;
|
28
|
+
readonly message: "Bad Request";
|
29
|
+
};
|
30
|
+
readonly UNAUTHORIZED: {
|
31
|
+
readonly status: 401;
|
32
|
+
readonly message: "Unauthorized";
|
33
|
+
};
|
34
|
+
readonly FORBIDDEN: {
|
35
|
+
readonly status: 403;
|
36
|
+
readonly message: "Forbidden";
|
37
|
+
};
|
38
|
+
readonly NOT_FOUND: {
|
39
|
+
readonly status: 404;
|
40
|
+
readonly message: "Not Found";
|
41
|
+
};
|
42
|
+
readonly METHOD_NOT_SUPPORTED: {
|
43
|
+
readonly status: 405;
|
44
|
+
readonly message: "Method Not Supported";
|
45
|
+
};
|
46
|
+
readonly NOT_ACCEPTABLE: {
|
47
|
+
readonly status: 406;
|
48
|
+
readonly message: "Not Acceptable";
|
49
|
+
};
|
50
|
+
readonly TIMEOUT: {
|
51
|
+
readonly status: 408;
|
52
|
+
readonly message: "Request Timeout";
|
53
|
+
};
|
54
|
+
readonly CONFLICT: {
|
55
|
+
readonly status: 409;
|
56
|
+
readonly message: "Conflict";
|
57
|
+
};
|
58
|
+
readonly PRECONDITION_FAILED: {
|
59
|
+
readonly status: 412;
|
60
|
+
readonly message: "Precondition Failed";
|
61
|
+
};
|
62
|
+
readonly PAYLOAD_TOO_LARGE: {
|
63
|
+
readonly status: 413;
|
64
|
+
readonly message: "Payload Too Large";
|
65
|
+
};
|
66
|
+
readonly UNSUPPORTED_MEDIA_TYPE: {
|
67
|
+
readonly status: 415;
|
68
|
+
readonly message: "Unsupported Media Type";
|
69
|
+
};
|
70
|
+
readonly UNPROCESSABLE_CONTENT: {
|
71
|
+
readonly status: 422;
|
72
|
+
readonly message: "Unprocessable Content";
|
73
|
+
};
|
74
|
+
readonly TOO_MANY_REQUESTS: {
|
75
|
+
readonly status: 429;
|
76
|
+
readonly message: "Too Many Requests";
|
77
|
+
};
|
78
|
+
readonly CLIENT_CLOSED_REQUEST: {
|
79
|
+
readonly status: 499;
|
80
|
+
readonly message: "Client Closed Request";
|
81
|
+
};
|
82
|
+
readonly INTERNAL_SERVER_ERROR: {
|
83
|
+
readonly status: 500;
|
84
|
+
readonly message: "Internal Server Error";
|
85
|
+
};
|
86
|
+
readonly NOT_IMPLEMENTED: {
|
87
|
+
readonly status: 501;
|
88
|
+
readonly message: "Not Implemented";
|
89
|
+
};
|
90
|
+
readonly BAD_GATEWAY: {
|
91
|
+
readonly status: 502;
|
92
|
+
readonly message: "Bad Gateway";
|
93
|
+
};
|
94
|
+
readonly SERVICE_UNAVAILABLE: {
|
95
|
+
readonly status: 503;
|
96
|
+
readonly message: "Service Unavailable";
|
97
|
+
};
|
98
|
+
readonly GATEWAY_TIMEOUT: {
|
99
|
+
readonly status: 504;
|
100
|
+
readonly message: "Gateway Timeout";
|
101
|
+
};
|
102
|
+
};
|
103
|
+
type CommonORPCErrorCode = keyof typeof COMMON_ORPC_ERROR_DEFS;
|
104
|
+
type ORPCErrorCode = CommonORPCErrorCode | (string & {});
|
105
|
+
declare function fallbackORPCErrorStatus(code: ORPCErrorCode, status: number | undefined): number;
|
106
|
+
declare function fallbackORPCErrorMessage(code: ORPCErrorCode, message: string | undefined): string;
|
107
|
+
type ORPCErrorOptions<TData> = ErrorOptions & {
|
108
|
+
defined?: boolean;
|
109
|
+
status?: number;
|
110
|
+
message?: string;
|
111
|
+
} & (undefined extends TData ? {
|
112
|
+
data?: TData;
|
113
|
+
} : {
|
114
|
+
data: TData;
|
115
|
+
});
|
116
|
+
declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error {
|
117
|
+
readonly defined: boolean;
|
118
|
+
readonly code: TCode;
|
119
|
+
readonly status: number;
|
120
|
+
readonly data: TData;
|
121
|
+
constructor(code: TCode, ...[options]: MaybeOptionalOptions<ORPCErrorOptions<TData>>);
|
122
|
+
toJSON(): ORPCErrorJSON<TCode, TData>;
|
123
|
+
static fromJSON<TCode extends ORPCErrorCode, TData>(json: ORPCErrorJSON<TCode, TData>, options?: ErrorOptions): ORPCError<TCode, TData>;
|
124
|
+
static isValidJSON(json: unknown): json is ORPCErrorJSON<ORPCErrorCode, unknown>;
|
125
|
+
}
|
126
|
+
type ORPCErrorJSON<TCode extends string, TData> = Pick<ORPCError<TCode, TData>, 'defined' | 'code' | 'status' | 'message' | 'data'>;
|
127
|
+
declare function isDefinedError<T>(error: T): error is Extract<T, ORPCError<any, any>>;
|
128
|
+
declare function toORPCError(error: unknown): ORPCError<any, any>;
|
129
|
+
declare function isORPCErrorStatus(status: number): boolean;
|
130
|
+
|
131
|
+
declare function mapEventIterator<TYield, TReturn, TNext, TMap = TYield | TReturn>(iterator: AsyncIterator<TYield, TReturn, TNext>, maps: {
|
132
|
+
value: (value: NoInfer<TYield | TReturn>, done: boolean | undefined) => Promise<TMap>;
|
133
|
+
error: (error: unknown) => Promise<unknown>;
|
134
|
+
}): AsyncGenerator<TMap, TMap, TNext>;
|
135
|
+
|
136
|
+
type SafeResult<TOutput, TError> = [error: null, data: TOutput, isDefined: false, success: true] & {
|
137
|
+
error: null;
|
138
|
+
data: TOutput;
|
139
|
+
isDefined: false;
|
140
|
+
success: true;
|
141
|
+
} | [error: Exclude<TError, ORPCError<any, any>>, data: undefined, isDefined: false, success: false] & {
|
142
|
+
error: Exclude<TError, ORPCError<any, any>>;
|
143
|
+
data: undefined;
|
144
|
+
isDefined: false;
|
145
|
+
success: false;
|
146
|
+
} | [error: Extract<TError, ORPCError<any, any>>, data: undefined, isDefined: true, success: false] & {
|
147
|
+
error: Extract<TError, ORPCError<any, any>>;
|
148
|
+
data: undefined;
|
149
|
+
isDefined: true;
|
150
|
+
success: false;
|
151
|
+
};
|
152
|
+
declare function safe<TOutput, TError = ThrowableError>(promise: ClientPromiseResult<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
|
153
|
+
declare function resolveFriendlyClientOptions<T extends ClientContext>(options: FriendlyClientOptions<T>): ClientOptions<T>;
|
154
|
+
|
155
|
+
export { COMMON_ORPC_ERROR_DEFS, ClientContext, ClientLink, ClientOptions, ClientPromiseResult, type CommonORPCErrorCode, DynamicLink, FriendlyClientOptions, InferClientContext, NestedClient, ORPCError, type ORPCErrorCode, type ORPCErrorJSON, type ORPCErrorOptions, type SafeResult, createORPCClient, type createORPCClientOptions, fallbackORPCErrorMessage, fallbackORPCErrorStatus, isDefinedError, isORPCErrorStatus, mapEventIterator, resolveFriendlyClientOptions, safe, toORPCError };
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
import { N as NestedClient, C as ClientLink, I as InferClientContext, a as ClientContext, b as ClientOptions, c as ClientPromiseResult, F as FriendlyClientOptions } from './shared/client.C0lT7w02.js';
|
2
|
+
export { f as Client, e as ClientRest, d as HTTPMethod, H as HTTPPath } from './shared/client.C0lT7w02.js';
|
3
|
+
import { Promisable, MaybeOptionalOptions, ThrowableError } from '@orpc/shared';
|
4
|
+
export { Registry, ThrowableError, onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
5
|
+
export { ErrorEvent } from '@orpc/standard-server';
|
6
|
+
|
7
|
+
interface createORPCClientOptions {
|
8
|
+
/**
|
9
|
+
* Use as base path for all procedure, useful when you only want to call a subset of the procedure.
|
10
|
+
*/
|
11
|
+
path?: string[];
|
12
|
+
}
|
13
|
+
declare function createORPCClient<T extends NestedClient<any>>(link: ClientLink<InferClientContext<T>>, options?: createORPCClientOptions): T;
|
14
|
+
|
15
|
+
/**
|
16
|
+
* DynamicLink provides a way to dynamically resolve and delegate calls to other ClientLinks
|
17
|
+
* based on the request path, input, and context.
|
18
|
+
*/
|
19
|
+
declare class DynamicLink<TClientContext extends ClientContext> implements ClientLink<TClientContext> {
|
20
|
+
private readonly linkResolver;
|
21
|
+
constructor(linkResolver: (options: ClientOptions<TClientContext>, path: readonly string[], input: unknown) => Promisable<ClientLink<TClientContext>>);
|
22
|
+
call(path: readonly string[], input: unknown, options: ClientOptions<TClientContext>): Promise<unknown>;
|
23
|
+
}
|
24
|
+
|
25
|
+
declare const COMMON_ORPC_ERROR_DEFS: {
|
26
|
+
readonly BAD_REQUEST: {
|
27
|
+
readonly status: 400;
|
28
|
+
readonly message: "Bad Request";
|
29
|
+
};
|
30
|
+
readonly UNAUTHORIZED: {
|
31
|
+
readonly status: 401;
|
32
|
+
readonly message: "Unauthorized";
|
33
|
+
};
|
34
|
+
readonly FORBIDDEN: {
|
35
|
+
readonly status: 403;
|
36
|
+
readonly message: "Forbidden";
|
37
|
+
};
|
38
|
+
readonly NOT_FOUND: {
|
39
|
+
readonly status: 404;
|
40
|
+
readonly message: "Not Found";
|
41
|
+
};
|
42
|
+
readonly METHOD_NOT_SUPPORTED: {
|
43
|
+
readonly status: 405;
|
44
|
+
readonly message: "Method Not Supported";
|
45
|
+
};
|
46
|
+
readonly NOT_ACCEPTABLE: {
|
47
|
+
readonly status: 406;
|
48
|
+
readonly message: "Not Acceptable";
|
49
|
+
};
|
50
|
+
readonly TIMEOUT: {
|
51
|
+
readonly status: 408;
|
52
|
+
readonly message: "Request Timeout";
|
53
|
+
};
|
54
|
+
readonly CONFLICT: {
|
55
|
+
readonly status: 409;
|
56
|
+
readonly message: "Conflict";
|
57
|
+
};
|
58
|
+
readonly PRECONDITION_FAILED: {
|
59
|
+
readonly status: 412;
|
60
|
+
readonly message: "Precondition Failed";
|
61
|
+
};
|
62
|
+
readonly PAYLOAD_TOO_LARGE: {
|
63
|
+
readonly status: 413;
|
64
|
+
readonly message: "Payload Too Large";
|
65
|
+
};
|
66
|
+
readonly UNSUPPORTED_MEDIA_TYPE: {
|
67
|
+
readonly status: 415;
|
68
|
+
readonly message: "Unsupported Media Type";
|
69
|
+
};
|
70
|
+
readonly UNPROCESSABLE_CONTENT: {
|
71
|
+
readonly status: 422;
|
72
|
+
readonly message: "Unprocessable Content";
|
73
|
+
};
|
74
|
+
readonly TOO_MANY_REQUESTS: {
|
75
|
+
readonly status: 429;
|
76
|
+
readonly message: "Too Many Requests";
|
77
|
+
};
|
78
|
+
readonly CLIENT_CLOSED_REQUEST: {
|
79
|
+
readonly status: 499;
|
80
|
+
readonly message: "Client Closed Request";
|
81
|
+
};
|
82
|
+
readonly INTERNAL_SERVER_ERROR: {
|
83
|
+
readonly status: 500;
|
84
|
+
readonly message: "Internal Server Error";
|
85
|
+
};
|
86
|
+
readonly NOT_IMPLEMENTED: {
|
87
|
+
readonly status: 501;
|
88
|
+
readonly message: "Not Implemented";
|
89
|
+
};
|
90
|
+
readonly BAD_GATEWAY: {
|
91
|
+
readonly status: 502;
|
92
|
+
readonly message: "Bad Gateway";
|
93
|
+
};
|
94
|
+
readonly SERVICE_UNAVAILABLE: {
|
95
|
+
readonly status: 503;
|
96
|
+
readonly message: "Service Unavailable";
|
97
|
+
};
|
98
|
+
readonly GATEWAY_TIMEOUT: {
|
99
|
+
readonly status: 504;
|
100
|
+
readonly message: "Gateway Timeout";
|
101
|
+
};
|
102
|
+
};
|
103
|
+
type CommonORPCErrorCode = keyof typeof COMMON_ORPC_ERROR_DEFS;
|
104
|
+
type ORPCErrorCode = CommonORPCErrorCode | (string & {});
|
105
|
+
declare function fallbackORPCErrorStatus(code: ORPCErrorCode, status: number | undefined): number;
|
106
|
+
declare function fallbackORPCErrorMessage(code: ORPCErrorCode, message: string | undefined): string;
|
107
|
+
type ORPCErrorOptions<TData> = ErrorOptions & {
|
108
|
+
defined?: boolean;
|
109
|
+
status?: number;
|
110
|
+
message?: string;
|
111
|
+
} & (undefined extends TData ? {
|
112
|
+
data?: TData;
|
113
|
+
} : {
|
114
|
+
data: TData;
|
115
|
+
});
|
116
|
+
declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error {
|
117
|
+
readonly defined: boolean;
|
118
|
+
readonly code: TCode;
|
119
|
+
readonly status: number;
|
120
|
+
readonly data: TData;
|
121
|
+
constructor(code: TCode, ...[options]: MaybeOptionalOptions<ORPCErrorOptions<TData>>);
|
122
|
+
toJSON(): ORPCErrorJSON<TCode, TData>;
|
123
|
+
static fromJSON<TCode extends ORPCErrorCode, TData>(json: ORPCErrorJSON<TCode, TData>, options?: ErrorOptions): ORPCError<TCode, TData>;
|
124
|
+
static isValidJSON(json: unknown): json is ORPCErrorJSON<ORPCErrorCode, unknown>;
|
125
|
+
}
|
126
|
+
type ORPCErrorJSON<TCode extends string, TData> = Pick<ORPCError<TCode, TData>, 'defined' | 'code' | 'status' | 'message' | 'data'>;
|
127
|
+
declare function isDefinedError<T>(error: T): error is Extract<T, ORPCError<any, any>>;
|
128
|
+
declare function toORPCError(error: unknown): ORPCError<any, any>;
|
129
|
+
declare function isORPCErrorStatus(status: number): boolean;
|
130
|
+
|
131
|
+
declare function mapEventIterator<TYield, TReturn, TNext, TMap = TYield | TReturn>(iterator: AsyncIterator<TYield, TReturn, TNext>, maps: {
|
132
|
+
value: (value: NoInfer<TYield | TReturn>, done: boolean | undefined) => Promise<TMap>;
|
133
|
+
error: (error: unknown) => Promise<unknown>;
|
134
|
+
}): AsyncGenerator<TMap, TMap, TNext>;
|
135
|
+
|
136
|
+
type SafeResult<TOutput, TError> = [error: null, data: TOutput, isDefined: false, success: true] & {
|
137
|
+
error: null;
|
138
|
+
data: TOutput;
|
139
|
+
isDefined: false;
|
140
|
+
success: true;
|
141
|
+
} | [error: Exclude<TError, ORPCError<any, any>>, data: undefined, isDefined: false, success: false] & {
|
142
|
+
error: Exclude<TError, ORPCError<any, any>>;
|
143
|
+
data: undefined;
|
144
|
+
isDefined: false;
|
145
|
+
success: false;
|
146
|
+
} | [error: Extract<TError, ORPCError<any, any>>, data: undefined, isDefined: true, success: false] & {
|
147
|
+
error: Extract<TError, ORPCError<any, any>>;
|
148
|
+
data: undefined;
|
149
|
+
isDefined: true;
|
150
|
+
success: false;
|
151
|
+
};
|
152
|
+
declare function safe<TOutput, TError = ThrowableError>(promise: ClientPromiseResult<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
|
153
|
+
declare function resolveFriendlyClientOptions<T extends ClientContext>(options: FriendlyClientOptions<T>): ClientOptions<T>;
|
154
|
+
|
155
|
+
export { COMMON_ORPC_ERROR_DEFS, ClientContext, ClientLink, ClientOptions, ClientPromiseResult, type CommonORPCErrorCode, DynamicLink, FriendlyClientOptions, InferClientContext, NestedClient, ORPCError, type ORPCErrorCode, type ORPCErrorJSON, type ORPCErrorOptions, type SafeResult, createORPCClient, type createORPCClientOptions, fallbackORPCErrorMessage, fallbackORPCErrorStatus, isDefinedError, isORPCErrorStatus, mapEventIterator, resolveFriendlyClientOptions, safe, toORPCError };
|
package/dist/index.mjs
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
import { i as isDefinedError } from './shared/client.jKEwIsRd.mjs';
|
2
|
+
export { C as COMMON_ORPC_ERROR_DEFS, O as ORPCError, a as fallbackORPCErrorMessage, f as fallbackORPCErrorStatus, b as isORPCErrorStatus, m as mapEventIterator, t as toORPCError } from './shared/client.jKEwIsRd.mjs';
|
3
|
+
export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
4
|
+
export { ErrorEvent } from '@orpc/standard-server';
|
5
|
+
|
6
|
+
async function safe(promise) {
|
7
|
+
try {
|
8
|
+
const output = await promise;
|
9
|
+
return Object.assign(
|
10
|
+
[null, output, false, true],
|
11
|
+
{ error: null, data: output, isDefined: false, success: true }
|
12
|
+
);
|
13
|
+
} catch (e) {
|
14
|
+
const error = e;
|
15
|
+
if (isDefinedError(error)) {
|
16
|
+
return Object.assign(
|
17
|
+
[error, void 0, true, false],
|
18
|
+
{ error, data: void 0, isDefined: true, success: false }
|
19
|
+
);
|
20
|
+
}
|
21
|
+
return Object.assign(
|
22
|
+
[error, void 0, false, false],
|
23
|
+
{ error, data: void 0, isDefined: false, success: false }
|
24
|
+
);
|
25
|
+
}
|
26
|
+
}
|
27
|
+
function resolveFriendlyClientOptions(options) {
|
28
|
+
return {
|
29
|
+
...options,
|
30
|
+
context: options?.context ?? {}
|
31
|
+
// Context only optional if all fields are optional
|
32
|
+
};
|
33
|
+
}
|
34
|
+
|
35
|
+
function createORPCClient(link, options) {
|
36
|
+
const path = options?.path ?? [];
|
37
|
+
const procedureClient = async (...[input, options2 = {}]) => {
|
38
|
+
return await link.call(path, input, resolveFriendlyClientOptions(options2));
|
39
|
+
};
|
40
|
+
const recursive = new Proxy(procedureClient, {
|
41
|
+
get(target, key) {
|
42
|
+
if (typeof key !== "string") {
|
43
|
+
return Reflect.get(target, key);
|
44
|
+
}
|
45
|
+
return createORPCClient(link, {
|
46
|
+
...options,
|
47
|
+
path: [...path, key]
|
48
|
+
});
|
49
|
+
}
|
50
|
+
});
|
51
|
+
return recursive;
|
52
|
+
}
|
53
|
+
|
54
|
+
class DynamicLink {
|
55
|
+
constructor(linkResolver) {
|
56
|
+
this.linkResolver = linkResolver;
|
57
|
+
}
|
58
|
+
async call(path, input, options) {
|
59
|
+
const resolvedLink = await this.linkResolver(options, path, input);
|
60
|
+
const output = await resolvedLink.call(path, input, options);
|
61
|
+
return output;
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
export { DynamicLink, createORPCClient, isDefinedError, resolveFriendlyClientOptions, safe };
|
@@ -0,0 +1,65 @@
|
|
1
|
+
import { Value } from '@orpc/shared';
|
2
|
+
import { S as StandardLinkPlugin, a as StandardLinkOptions } from '../shared/client.5813Ufvs.mjs';
|
3
|
+
import { b as ClientOptions } from '../shared/client.C0lT7w02.mjs';
|
4
|
+
import '@orpc/standard-server';
|
5
|
+
|
6
|
+
interface ClientRetryPluginAttemptOptions {
|
7
|
+
lastEventRetry: number | undefined;
|
8
|
+
lastEventId: string | undefined;
|
9
|
+
attemptIndex: number;
|
10
|
+
error: unknown;
|
11
|
+
}
|
12
|
+
interface ClientRetryPluginContext {
|
13
|
+
/**
|
14
|
+
* Maximum retry attempts before throwing
|
15
|
+
* Use `Number.POSITIVE_INFINITY` for infinite retries (e.g., when handling Server-Sent Events).
|
16
|
+
*
|
17
|
+
* @default 0
|
18
|
+
*/
|
19
|
+
retry?: Value<number, [
|
20
|
+
clientOptions: ClientOptions<ClientRetryPluginContext>,
|
21
|
+
path: readonly string[],
|
22
|
+
input: unknown
|
23
|
+
]>;
|
24
|
+
/**
|
25
|
+
* Delay (in ms) before retrying.
|
26
|
+
*
|
27
|
+
* @default (o) => o.lastEventRetry ?? 2000
|
28
|
+
*/
|
29
|
+
retryDelay?: Value<number, [
|
30
|
+
attemptOptions: ClientRetryPluginAttemptOptions,
|
31
|
+
clientOptions: ClientOptions<ClientRetryPluginContext>,
|
32
|
+
path: readonly string[],
|
33
|
+
input: unknown
|
34
|
+
]>;
|
35
|
+
/**
|
36
|
+
* Determine should retry or not.
|
37
|
+
*
|
38
|
+
* @default true
|
39
|
+
*/
|
40
|
+
shouldRetry?: Value<boolean, [
|
41
|
+
attemptOptions: ClientRetryPluginAttemptOptions,
|
42
|
+
clientOptions: ClientOptions<ClientRetryPluginContext>,
|
43
|
+
path: readonly string[],
|
44
|
+
input: unknown
|
45
|
+
]>;
|
46
|
+
/**
|
47
|
+
* The hook called when retrying, and return the unsubscribe function.
|
48
|
+
*/
|
49
|
+
onRetry?: (options: ClientRetryPluginAttemptOptions, clientOptions: ClientOptions<ClientRetryPluginContext>, path: readonly string[], input: unknown) => void | (() => void);
|
50
|
+
}
|
51
|
+
declare class ClientRetryPluginInvalidEventIteratorRetryResponse extends Error {
|
52
|
+
}
|
53
|
+
interface ClientRetryPluginOptions {
|
54
|
+
default?: ClientRetryPluginContext;
|
55
|
+
}
|
56
|
+
declare class ClientRetryPlugin<T extends ClientRetryPluginContext> implements StandardLinkPlugin<T> {
|
57
|
+
private readonly defaultRetry;
|
58
|
+
private readonly defaultRetryDelay;
|
59
|
+
private readonly defaultShouldRetry;
|
60
|
+
private readonly defaultOnRetry;
|
61
|
+
constructor(options?: ClientRetryPluginOptions);
|
62
|
+
init(options: StandardLinkOptions<T>): void;
|
63
|
+
}
|
64
|
+
|
65
|
+
export { ClientRetryPlugin, type ClientRetryPluginAttemptOptions, type ClientRetryPluginContext, ClientRetryPluginInvalidEventIteratorRetryResponse, type ClientRetryPluginOptions };
|