@orpc/client 0.0.0-next.f17a1a0 → 0.0.0-next.f47352c

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +15 -2
  2. package/dist/adapters/fetch/index.d.mts +26 -0
  3. package/dist/adapters/fetch/index.d.ts +26 -0
  4. package/dist/adapters/fetch/index.mjs +32 -0
  5. package/dist/adapters/standard/index.d.mts +10 -0
  6. package/dist/adapters/standard/index.d.ts +10 -0
  7. package/dist/adapters/standard/index.mjs +4 -0
  8. package/dist/index.d.mts +155 -0
  9. package/dist/index.d.ts +155 -0
  10. package/dist/index.mjs +65 -0
  11. package/dist/plugins/index.d.mts +65 -0
  12. package/dist/plugins/index.d.ts +65 -0
  13. package/dist/plugins/index.mjs +131 -0
  14. package/dist/shared/client.5813Ufvs.d.mts +39 -0
  15. package/dist/shared/client.Bt94sjrK.d.mts +103 -0
  16. package/dist/shared/client.C0lT7w02.d.mts +30 -0
  17. package/dist/shared/client.C0lT7w02.d.ts +30 -0
  18. package/dist/shared/client.D-jrSuDb.d.ts +103 -0
  19. package/dist/shared/client.DhAxdT4W.mjs +336 -0
  20. package/dist/shared/client.grRbC25r.d.ts +39 -0
  21. package/dist/shared/client.jKEwIsRd.mjs +175 -0
  22. package/package.json +20 -25
  23. package/dist/chunk-4FUUNP74.js +0 -212
  24. package/dist/chunk-OGAGXWCU.js +0 -281
  25. package/dist/fetch.js +0 -128
  26. package/dist/index.js +0 -81
  27. package/dist/openapi.js +0 -231
  28. package/dist/rpc.js +0 -10
  29. package/dist/src/adapters/fetch/index.d.ts +0 -3
  30. package/dist/src/adapters/fetch/rpc-link.d.ts +0 -98
  31. package/dist/src/adapters/fetch/types.d.ts +0 -5
  32. package/dist/src/client.d.ts +0 -9
  33. package/dist/src/dynamic-link.d.ts +0 -12
  34. package/dist/src/error.d.ts +0 -106
  35. package/dist/src/event-iterator-state.d.ts +0 -9
  36. package/dist/src/event-iterator.d.ts +0 -12
  37. package/dist/src/index.d.ts +0 -9
  38. package/dist/src/openapi/bracket-notation.d.ts +0 -9
  39. package/dist/src/openapi/index.d.ts +0 -4
  40. package/dist/src/openapi/json-serializer.d.ts +0 -7
  41. package/dist/src/openapi/serializer.d.ts +0 -11
  42. package/dist/src/rpc/index.d.ts +0 -3
  43. package/dist/src/rpc/json-serializer.d.ts +0 -12
  44. package/dist/src/rpc/serializer.d.ts +0 -9
  45. package/dist/src/types.d.ts +0 -29
  46. package/dist/src/utils.d.ts +0 -5
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <div align="center">
2
- <image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 />
2
+ <image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 alt="oRPC logo" />
3
3
  </div>
4
4
 
5
5
  <h1></h1>
@@ -32,7 +32,7 @@
32
32
  - **Contract-First Development 📜**: (Optional) Define your API contract upfront and implement it with confidence.
33
33
  - **Exceptional Developer Experience ✨**: Enjoy a streamlined workflow with robust typing and clear, in-code documentation.
34
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.
35
+ - **Framework Integrations 🧩**: Supports Tanstack Query (React, Vue, Solid, Svelte), Pinia Colada, and more.
36
36
  - **Server Actions ⚡️**: Fully compatible with React Server Actions on Next.js, TanStack Start, and more.
37
37
  - **Standard Schema Support 🗂️**: Effortlessly work with Zod, Valibot, ArkType, and others right out of the box.
38
38
  - **Fast & Lightweight 💨**: Built on native APIs across all runtimes – optimized for speed and efficiency.
@@ -53,11 +53,16 @@ You can find the full documentation [here](https://orpc.unnoq.com).
53
53
  - [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
54
54
  - [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
55
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.
56
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).
57
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).
58
61
  - [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
59
62
  - [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
60
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/).
61
66
 
62
67
  ## `@orpc/client`
63
68
 
@@ -83,6 +88,14 @@ const client: RouterClient<typeof router> = createORPCClient(link)
83
88
  const client: ContractRouterClient<typeof contract> = createORPCClient(link)
84
89
  ```
85
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
+
86
99
  ## License
87
100
 
88
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.DhAxdT4W.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.DhAxdT4W.mjs';
2
+ import '@orpc/shared';
3
+ import '@orpc/standard-server';
4
+ import '../../shared/client.jKEwIsRd.mjs';
@@ -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 };
@@ -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 };