@orpc/client 1.14.6 → 2.0.0-beta.1
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 +74 -106
- package/dist/adapters/fetch/index.d.mts +55 -36
- package/dist/adapters/fetch/index.d.ts +55 -36
- package/dist/adapters/fetch/index.mjs +50 -28
- package/dist/adapters/message-port/index.d.mts +25 -30
- package/dist/adapters/message-port/index.d.ts +25 -30
- package/dist/adapters/message-port/index.mjs +33 -29
- package/dist/adapters/standard/index.d.mts +58 -9
- package/dist/adapters/standard/index.d.ts +58 -9
- package/dist/adapters/standard/index.mjs +5 -5
- package/dist/adapters/websocket/index.d.mts +113 -21
- package/dist/adapters/websocket/index.d.ts +113 -21
- package/dist/adapters/websocket/index.mjs +95 -37
- package/dist/index.d.mts +84 -159
- package/dist/index.d.ts +84 -159
- package/dist/index.mjs +76 -34
- package/dist/plugins/index.d.mts +125 -132
- package/dist/plugins/index.d.ts +125 -132
- package/dist/plugins/index.mjs +373 -284
- package/dist/shared/client.8ug8I-zu.d.mts +167 -0
- package/dist/shared/client.8ug8I-zu.d.ts +167 -0
- package/dist/shared/client.BdItY5DT.d.mts +111 -0
- package/dist/shared/client.BdItY5DT.d.ts +111 -0
- package/dist/shared/client.CPF3hX6O.d.ts +96 -0
- package/dist/shared/client.Cby_-GGh.d.mts +96 -0
- package/dist/shared/client.DMXKFDyV.mjs +343 -0
- package/dist/shared/client.DXhchJ84.mjs +174 -0
- package/dist/shared/client.Dnfj8jnT.mjs +92 -0
- package/package.json +7 -7
- package/dist/shared/client.2jUAqzYU.d.ts +0 -45
- package/dist/shared/client.B3pNRBih.d.ts +0 -91
- package/dist/shared/client.BFAVy68H.d.mts +0 -91
- package/dist/shared/client.BLtwTQUg.mjs +0 -40
- package/dist/shared/client.CpCa3si8.d.mts +0 -45
- package/dist/shared/client.D9eWXdBV.mjs +0 -174
- package/dist/shared/client.DLhbktiD.mjs +0 -404
- package/dist/shared/client.i2uoJbEp.d.mts +0 -83
- package/dist/shared/client.i2uoJbEp.d.ts +0 -83
package/dist/index.d.ts
CHANGED
|
@@ -1,165 +1,79 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
3
|
-
import {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
1
|
+
import { O as ORPCErrorCode, c as ORPCError, d as ORPCErrorJSON, A as AnyORPCError, C as ClientContext, a as ClientOptions, e as AnyNestedClient, I as InferClientContext, f as InferClientError, g as Client, b as ClientLink, h as ClientRest, F as FriendlyClientOptions } from './shared/client.8ug8I-zu.js';
|
|
2
|
+
export { i as AnyORPCErrorJSON, j as COMMON_ERROR_STATUS_MAP, k as InferClientBodyInputs, l as InferClientBodyOutputs, m as InferClientErrors, n as InferClientInputs, o as InferClientOutputs, N as NestedClient, p as ORPCErrorOptions } from './shared/client.8ug8I-zu.js';
|
|
3
|
+
import { Interceptor, PromiseWithError, ThrowableError, Promisable, WrapAsyncIteratorOptions, AsyncIteratorClass } from '@orpc/shared';
|
|
4
|
+
export { AsyncCleanupFn, AsyncIteratorClass, AsyncIteratorClassNextFn, Registry, ThrowableError, asyncIteratorToStream as eventIteratorToStream, asyncIteratorToUnproxiedDataStream as eventIteratorToUnproxiedDataStream, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@orpc/shared';
|
|
5
|
+
export { R as RPCJsonSerialization, a as RPCJsonSerializationMeta, b as RPCJsonSerializer, c as RPCJsonSerializerHandler, d as RPCJsonSerializerOptions, e as RPCSerializer, f as RPCSerializerOptions, g as RPCSerializerSerializeOptions } from './shared/client.BdItY5DT.js';
|
|
6
|
+
export { ErrorEvent, getEventMeta, unwrapEvent, withEventMeta } from '@standardserver/core';
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
declare function isInferableError<T>(error: T): error is Extract<T, AnyORPCError>;
|
|
9
|
+
declare function toORPCError<T>(error: T): Extract<T, AnyORPCError> | ORPCError<'INTERNAL_SERVER_ERROR', undefined>;
|
|
10
|
+
declare function isORPCErrorJson(json: unknown): json is ORPCErrorJSON<ORPCErrorCode, unknown>;
|
|
11
|
+
declare function createORPCErrorFromJson<TCode extends ORPCErrorCode, TData>(json: ORPCErrorJSON<TCode, TData>, options?: ErrorOptions): ORPCError<TCode, TData>;
|
|
12
|
+
declare function cloneORPCError<T extends ORPCErrorCode, TData>(error: ORPCError<T, TData>): ORPCError<T, TData>;
|
|
13
|
+
|
|
14
|
+
interface ORPCClientInterceptorOptions<TClientContext extends ClientContext, TInput> extends ClientOptions<TClientContext> {
|
|
15
|
+
path: string[];
|
|
16
|
+
input: TInput;
|
|
17
|
+
}
|
|
18
|
+
type ORPCClientInterceptor<TClientContext extends ClientContext, TInput, TOutput, TError> = Interceptor<ORPCClientInterceptorOptions<TClientContext, TInput>, PromiseWithError<TOutput, TError>>;
|
|
19
|
+
interface ORPCClientScopedOptions<TClientContext extends ClientContext, TInput, TOutput, TError> {
|
|
8
20
|
/**
|
|
9
|
-
*
|
|
21
|
+
* Interceptors that wrap the entire client call lifecycle.
|
|
10
22
|
*/
|
|
11
|
-
|
|
23
|
+
interceptors?: ORPCClientInterceptor<TClientContext, TInput, TOutput, TError>[];
|
|
12
24
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*
|
|
16
|
-
* @see {@link https://orpc.dev/docs/client/client-side Client-side Client Docs}
|
|
17
|
-
*/
|
|
18
|
-
declare function createORPCClient<T extends NestedClient<any>>(link: ClientLink<InferClientContext<T>>, options?: createORPCClientOptions): T;
|
|
19
|
-
|
|
20
|
-
declare const COMMON_ORPC_ERROR_DEFS: {
|
|
21
|
-
readonly BAD_REQUEST: {
|
|
22
|
-
readonly status: 400;
|
|
23
|
-
readonly message: "Bad Request";
|
|
24
|
-
};
|
|
25
|
-
readonly UNAUTHORIZED: {
|
|
26
|
-
readonly status: 401;
|
|
27
|
-
readonly message: "Unauthorized";
|
|
28
|
-
};
|
|
29
|
-
readonly FORBIDDEN: {
|
|
30
|
-
readonly status: 403;
|
|
31
|
-
readonly message: "Forbidden";
|
|
32
|
-
};
|
|
33
|
-
readonly NOT_FOUND: {
|
|
34
|
-
readonly status: 404;
|
|
35
|
-
readonly message: "Not Found";
|
|
36
|
-
};
|
|
37
|
-
readonly METHOD_NOT_SUPPORTED: {
|
|
38
|
-
readonly status: 405;
|
|
39
|
-
readonly message: "Method Not Supported";
|
|
40
|
-
};
|
|
41
|
-
readonly NOT_ACCEPTABLE: {
|
|
42
|
-
readonly status: 406;
|
|
43
|
-
readonly message: "Not Acceptable";
|
|
44
|
-
};
|
|
45
|
-
readonly TIMEOUT: {
|
|
46
|
-
readonly status: 408;
|
|
47
|
-
readonly message: "Request Timeout";
|
|
48
|
-
};
|
|
49
|
-
readonly CONFLICT: {
|
|
50
|
-
readonly status: 409;
|
|
51
|
-
readonly message: "Conflict";
|
|
52
|
-
};
|
|
53
|
-
readonly PRECONDITION_FAILED: {
|
|
54
|
-
readonly status: 412;
|
|
55
|
-
readonly message: "Precondition Failed";
|
|
56
|
-
};
|
|
57
|
-
readonly PAYLOAD_TOO_LARGE: {
|
|
58
|
-
readonly status: 413;
|
|
59
|
-
readonly message: "Payload Too Large";
|
|
60
|
-
};
|
|
61
|
-
readonly UNSUPPORTED_MEDIA_TYPE: {
|
|
62
|
-
readonly status: 415;
|
|
63
|
-
readonly message: "Unsupported Media Type";
|
|
64
|
-
};
|
|
65
|
-
readonly UNPROCESSABLE_CONTENT: {
|
|
66
|
-
readonly status: 422;
|
|
67
|
-
readonly message: "Unprocessable Content";
|
|
68
|
-
};
|
|
69
|
-
readonly TOO_MANY_REQUESTS: {
|
|
70
|
-
readonly status: 429;
|
|
71
|
-
readonly message: "Too Many Requests";
|
|
72
|
-
};
|
|
73
|
-
readonly CLIENT_CLOSED_REQUEST: {
|
|
74
|
-
readonly status: 499;
|
|
75
|
-
readonly message: "Client Closed Request";
|
|
76
|
-
};
|
|
77
|
-
readonly INTERNAL_SERVER_ERROR: {
|
|
78
|
-
readonly status: 500;
|
|
79
|
-
readonly message: "Internal Server Error";
|
|
80
|
-
};
|
|
81
|
-
readonly NOT_IMPLEMENTED: {
|
|
82
|
-
readonly status: 501;
|
|
83
|
-
readonly message: "Not Implemented";
|
|
84
|
-
};
|
|
85
|
-
readonly BAD_GATEWAY: {
|
|
86
|
-
readonly status: 502;
|
|
87
|
-
readonly message: "Bad Gateway";
|
|
88
|
-
};
|
|
89
|
-
readonly SERVICE_UNAVAILABLE: {
|
|
90
|
-
readonly status: 503;
|
|
91
|
-
readonly message: "Service Unavailable";
|
|
92
|
-
};
|
|
93
|
-
readonly GATEWAY_TIMEOUT: {
|
|
94
|
-
readonly status: 504;
|
|
95
|
-
readonly message: "Gateway Timeout";
|
|
96
|
-
};
|
|
25
|
+
type ORPCClientScoped<T extends AnyNestedClient> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ORPCClientScopedOptions<UClientContext, UInput, UOutput, UError> : {
|
|
26
|
+
[K in keyof T]?: T[K] extends AnyNestedClient ? ORPCClientScoped<T[K]> : never;
|
|
97
27
|
};
|
|
98
|
-
|
|
99
|
-
type ORPCErrorCode = CommonORPCErrorCode | (string & {});
|
|
100
|
-
declare function fallbackORPCErrorStatus(code: ORPCErrorCode, status: number | undefined): number;
|
|
101
|
-
declare function fallbackORPCErrorMessage(code: ORPCErrorCode, message: string | undefined): string;
|
|
102
|
-
type ORPCErrorOptions<TData> = ErrorOptions & {
|
|
103
|
-
defined?: boolean;
|
|
104
|
-
status?: number;
|
|
105
|
-
message?: string;
|
|
106
|
-
} & (undefined extends TData ? {
|
|
107
|
-
data?: TData;
|
|
108
|
-
} : {
|
|
109
|
-
data: TData;
|
|
110
|
-
});
|
|
111
|
-
declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error {
|
|
112
|
-
readonly defined: boolean;
|
|
113
|
-
readonly code: TCode;
|
|
114
|
-
readonly status: number;
|
|
115
|
-
readonly data: TData;
|
|
116
|
-
constructor(code: TCode, ...rest: MaybeOptionalOptions<ORPCErrorOptions<TData>>);
|
|
117
|
-
toJSON(): ORPCErrorJSON<TCode, TData>;
|
|
28
|
+
interface ORPCClientOptions<T extends AnyNestedClient> {
|
|
118
29
|
/**
|
|
119
|
-
*
|
|
120
|
-
* dependency graphs, causing multiple ORPCError constructors existing and breaking
|
|
121
|
-
* `instanceof` checks across contexts.
|
|
122
|
-
*
|
|
123
|
-
* This is particularly problematic with "Optimized SSR", where orpc-client
|
|
124
|
-
* executes in one context but is invoked from another. When an error is thrown
|
|
125
|
-
* in the execution context, `instanceof ORPCError` checks fail in the
|
|
126
|
-
* invocation context due to separate class constructors.
|
|
127
|
-
*
|
|
128
|
-
* @todo Remove this and related code if Next.js resolves the multiple dependency graph issue.
|
|
30
|
+
* Use as base path for all procedure, useful when you only want to call a subset of the procedure.
|
|
129
31
|
*/
|
|
130
|
-
|
|
32
|
+
path?: string[];
|
|
33
|
+
/**
|
|
34
|
+
* Interceptors that wrap the entire client call lifecycle, applied to every procedure call.
|
|
35
|
+
*/
|
|
36
|
+
interceptors?: ORPCClientInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[];
|
|
37
|
+
/**
|
|
38
|
+
* Per-procedure options following the shape of the router.
|
|
39
|
+
* Allows fine-grained configuration (e.g. additional interceptors) for individual procedures
|
|
40
|
+
* without affecting the rest of the router.
|
|
41
|
+
*/
|
|
42
|
+
scoped?: ORPCClientScoped<T>;
|
|
131
43
|
}
|
|
132
|
-
|
|
133
|
-
declare function isDefinedError<T>(error: T): error is Extract<T, ORPCError<any, any>>;
|
|
134
|
-
declare function toORPCError(error: unknown): ORPCError<any, any>;
|
|
135
|
-
declare function isORPCErrorStatus(status: number): boolean;
|
|
136
|
-
declare function isORPCErrorJson(json: unknown): json is ORPCErrorJSON<ORPCErrorCode, unknown>;
|
|
137
|
-
declare function createORPCErrorFromJson<TCode extends ORPCErrorCode, TData>(json: ORPCErrorJSON<TCode, TData>, options?: ErrorOptions): ORPCError<TCode, TData>;
|
|
44
|
+
declare function createORPCClient<T extends AnyNestedClient>(link: ClientLink<InferClientContext<T>>, { path, ...options }?: NoInfer<ORPCClientOptions<T>>): T;
|
|
138
45
|
|
|
139
|
-
|
|
46
|
+
declare function resolveFriendlyClientOptions<T extends ClientContext>(options: FriendlyClientOptions<T>): ClientOptions<T>;
|
|
47
|
+
declare function resolveClientRest<TClientContext extends ClientContext, TInput>(rest: ClientRest<TClientContext, TInput>): [input: TInput, options: ClientOptions<TClientContext>];
|
|
48
|
+
type SafeResult<TOutput, TError> = [error: null, data: TOutput, inferableError: null, isSuccess: true] & {
|
|
140
49
|
error: null;
|
|
141
50
|
data: TOutput;
|
|
142
|
-
|
|
51
|
+
inferableError: null;
|
|
143
52
|
isSuccess: true;
|
|
144
|
-
} | [error: Exclude<TError,
|
|
145
|
-
error: Exclude<TError,
|
|
53
|
+
} | [error: Exclude<TError, AnyORPCError>, data: undefined, inferableError: null, isSuccess: false] & {
|
|
54
|
+
error: Exclude<TError, AnyORPCError>;
|
|
146
55
|
data: undefined;
|
|
147
|
-
|
|
56
|
+
inferableError: null;
|
|
148
57
|
isSuccess: false;
|
|
149
|
-
} | [error: Extract<TError,
|
|
150
|
-
error: Extract<TError,
|
|
58
|
+
} | [error: Extract<TError, AnyORPCError>, data: undefined, inferableError: Extract<TError, AnyORPCError>, isSuccess: false] & {
|
|
59
|
+
error: Extract<TError, AnyORPCError>;
|
|
151
60
|
data: undefined;
|
|
152
|
-
|
|
61
|
+
inferableError: Extract<TError, AnyORPCError>;
|
|
153
62
|
isSuccess: false;
|
|
154
63
|
};
|
|
155
64
|
/**
|
|
156
|
-
* Works like try/catch, but
|
|
65
|
+
* Works like try/catch, but help you infer the error type if it is inferable ORPCError.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* const [error, data, inferableError, isSuccess] = await safe(client(...))
|
|
70
|
+
* // or const { error, data, inferableError, isSuccess } = await safe(client(...))
|
|
157
71
|
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
72
|
+
* if (inferableError) {
|
|
73
|
+
* console.log(inferableError) // or error, both are well typed
|
|
74
|
+
* }
|
|
160
75
|
*/
|
|
161
|
-
declare function safe<TOutput, TError = ThrowableError>(promise:
|
|
162
|
-
declare function resolveFriendlyClientOptions<T extends ClientContext>(options: FriendlyClientOptions<T>): ClientOptions<T>;
|
|
76
|
+
declare function safe<TOutput, TError = ThrowableError>(promise: PromiseWithError<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
|
|
163
77
|
interface ConsumeEventIteratorOptions<T, TReturn, TError> {
|
|
164
78
|
/**
|
|
165
79
|
* Called on each event
|
|
@@ -180,18 +94,18 @@ interface ConsumeEventIteratorOptions<T, TReturn, TError> {
|
|
|
180
94
|
*
|
|
181
95
|
* @info If iterator is canceled, `undefined` can be passed on success
|
|
182
96
|
*/
|
|
183
|
-
onFinish?: (state:
|
|
97
|
+
onFinish?: (state: [error: TError, data: undefined, isSuccess: false] | [error: null, data: TReturn | undefined, isSuccess: true]) => void;
|
|
184
98
|
}
|
|
185
99
|
/**
|
|
186
100
|
* Consumes an event iterator with lifecycle callbacks
|
|
187
101
|
*
|
|
188
|
-
* @warning If no `onError` or `onFinish` is provided,
|
|
102
|
+
* @warning If no `onError` or `onFinish` is provided, error will be thrown into unhandled rejection channel.
|
|
189
103
|
* @return unsubscribe callback
|
|
190
104
|
*/
|
|
191
|
-
declare function consumeEventIterator<T, TReturn, TError = ThrowableError>(iterator: AsyncIterator<T, TReturn> |
|
|
105
|
+
declare function consumeEventIterator<T, TReturn, TError = ThrowableError>(iterator: AsyncIterator<T, TReturn> | PromiseWithError<AsyncIterator<T, TReturn>, TError>, options: ConsumeEventIteratorOptions<T, TReturn, TError>): () => Promise<void>;
|
|
192
106
|
|
|
193
|
-
type SafeClient<T extends
|
|
194
|
-
[K in keyof T]: T[K] extends
|
|
107
|
+
type SafeClient<T extends AnyNestedClient> = T extends Client<infer UContext, infer UInput, infer UOutput, infer UError> ? (...rest: ClientRest<UContext, UInput>) => Promise<SafeResult<UOutput, UError>> : {
|
|
108
|
+
[K in keyof T]: T[K] extends AnyNestedClient ? SafeClient<T[K]> : never;
|
|
195
109
|
};
|
|
196
110
|
/**
|
|
197
111
|
* Create a safe client that automatically wraps all procedure calls with the `safe` util.
|
|
@@ -199,15 +113,24 @@ type SafeClient<T extends NestedClient<any>> = T extends Client<infer UContext,
|
|
|
199
113
|
* @example
|
|
200
114
|
* ```ts
|
|
201
115
|
* const safeClient = createSafeClient(client)
|
|
202
|
-
* const { error, data,
|
|
116
|
+
* const { error, data, inferrableError, isSuccess } = await safeClient.doSomething({ id: '123' })
|
|
117
|
+
* // or const [error, data, inferrableError, isSuccess] = await safeClient.doSomething({ id: '123' })
|
|
203
118
|
* ```
|
|
204
119
|
*
|
|
205
120
|
* @see {@link https://orpc.dev/docs/client/error-handling#using-createsafeclient Safe Client Docs}
|
|
206
121
|
*/
|
|
207
|
-
declare function createSafeClient<T extends
|
|
122
|
+
declare function createSafeClient<T extends AnyNestedClient>(client: T): SafeClient<T>;
|
|
208
123
|
|
|
209
|
-
|
|
210
|
-
|
|
124
|
+
/**
|
|
125
|
+
* Property names that should resolve to the underlying value instead of
|
|
126
|
+
* continuing recursive proxy traversal.
|
|
127
|
+
*
|
|
128
|
+
* These properties are commonly accessed automatically by JavaScript runtimes,
|
|
129
|
+
* language features, or third-party libraries. Returning another recursive
|
|
130
|
+
* proxy for them can cause unexpected behavior, compatibility issues, or
|
|
131
|
+
* infinite proxy chains.
|
|
132
|
+
*/
|
|
133
|
+
declare const RECURSIVE_CLIENT_UNWRAP_KEYS: Set<string>;
|
|
211
134
|
|
|
212
135
|
/**
|
|
213
136
|
* DynamicLink provides a way to dynamically resolve and delegate calls to other ClientLinks
|
|
@@ -217,14 +140,16 @@ declare const ORPC_CLIENT_PACKAGE_VERSION = "1.14.6";
|
|
|
217
140
|
*/
|
|
218
141
|
declare class DynamicLink<TClientContext extends ClientContext> implements ClientLink<TClientContext> {
|
|
219
142
|
private readonly linkResolver;
|
|
220
|
-
constructor(linkResolver: (options: ClientOptions<TClientContext>, path:
|
|
221
|
-
call(path:
|
|
143
|
+
constructor(linkResolver: (options: ClientOptions<TClientContext>, path: string[], input: unknown) => Promisable<ClientLink<TClientContext>>);
|
|
144
|
+
call(path: string[], input: unknown, options: ClientOptions<TClientContext>): Promise<unknown>;
|
|
222
145
|
}
|
|
223
146
|
|
|
224
|
-
declare function
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
147
|
+
declare function wrapEventIteratorPreservingMeta<TYield, TReturn, TMappedYield = TYield, TMappedReturn = TReturn>(iterator: AsyncIterator<TYield, TReturn>, { mapResult, mapError, ...rest }: WrapAsyncIteratorOptions<TYield, TReturn, TMappedYield, TMappedReturn>): AsyncIteratorClass<TMappedYield, TMappedReturn>;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* @deprecated Use `isInferableError` instead.
|
|
151
|
+
*/
|
|
152
|
+
declare const isDefinedError: typeof isInferableError;
|
|
228
153
|
|
|
229
|
-
export {
|
|
230
|
-
export type {
|
|
154
|
+
export { AnyNestedClient, AnyORPCError, Client, ClientContext, ClientLink, ClientOptions, ClientRest, DynamicLink, FriendlyClientOptions, InferClientContext, InferClientError, ORPCError, ORPCErrorCode, ORPCErrorJSON, RECURSIVE_CLIENT_UNWRAP_KEYS, cloneORPCError, consumeEventIterator, createORPCClient, createORPCErrorFromJson, createSafeClient, isDefinedError, isInferableError, isORPCErrorJson, resolveClientRest, resolveFriendlyClientOptions, safe, toORPCError, wrapEventIteratorPreservingMeta };
|
|
155
|
+
export type { ConsumeEventIteratorOptions, ORPCClientInterceptor, ORPCClientInterceptorOptions, ORPCClientOptions, ORPCClientScoped, ORPCClientScopedOptions, SafeClient, SafeResult };
|
package/dist/index.mjs
CHANGED
|
@@ -1,38 +1,71 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
3
|
-
import {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export { ErrorEvent, getEventMeta, withEventMeta } from '@
|
|
1
|
+
import { a as isInferableError } from './shared/client.DMXKFDyV.mjs';
|
|
2
|
+
export { b as RPCJsonSerializer, R as RPCSerializer, d as cloneORPCError, c as createORPCErrorFromJson, i as isORPCErrorJson, t as toORPCError, w as wrapEventIteratorPreservingMeta } from './shared/client.DMXKFDyV.mjs';
|
|
3
|
+
import { getOrBind, toArray, intercept, isTypescriptObject } from '@orpc/shared';
|
|
4
|
+
export { AsyncIteratorClass, asyncIteratorToStream as eventIteratorToStream, asyncIteratorToUnproxiedDataStream as eventIteratorToUnproxiedDataStream, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@orpc/shared';
|
|
5
|
+
export { C as COMMON_ERROR_STATUS_MAP, O as ORPCError } from './shared/client.Dnfj8jnT.mjs';
|
|
6
|
+
export { ErrorEvent, getEventMeta, unwrapEvent, withEventMeta } from '@standardserver/core';
|
|
7
7
|
|
|
8
|
+
const RECURSIVE_CLIENT_UNWRAP_KEYS = /* @__PURE__ */ new Set([
|
|
9
|
+
/**
|
|
10
|
+
* Prevents the client from being treated as a thenable when users
|
|
11
|
+
* accidentally write `await client`.
|
|
12
|
+
*/
|
|
13
|
+
"then",
|
|
14
|
+
/**
|
|
15
|
+
* Commonly used by libraries to bind functions to a specific `this`
|
|
16
|
+
* context.
|
|
17
|
+
*/
|
|
18
|
+
"bind",
|
|
19
|
+
/**
|
|
20
|
+
* Commonly accessed during primitive conversion, inspection, and logging.
|
|
21
|
+
*/
|
|
22
|
+
"valueOf",
|
|
23
|
+
/**
|
|
24
|
+
* Commonly accessed during string conversion, inspection, and logging.
|
|
25
|
+
*/
|
|
26
|
+
"toString",
|
|
27
|
+
/**
|
|
28
|
+
* Commonly accessed by serializers such as `JSON.stringify`.
|
|
29
|
+
*/
|
|
30
|
+
"toJSON"
|
|
31
|
+
]);
|
|
32
|
+
|
|
33
|
+
function resolveFriendlyClientOptions(options) {
|
|
34
|
+
return {
|
|
35
|
+
...options,
|
|
36
|
+
context: options.context ?? {}
|
|
37
|
+
// Context only optional if all fields are optional
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function resolveClientRest(rest) {
|
|
41
|
+
return [
|
|
42
|
+
rest[0],
|
|
43
|
+
// rest[0] can be undefined if TInput is optional,
|
|
44
|
+
resolveFriendlyClientOptions(rest[1] ?? {})
|
|
45
|
+
// rest[1] can be undefined if all fields of FriendlyClientOptions are optional
|
|
46
|
+
];
|
|
47
|
+
}
|
|
8
48
|
async function safe(promise) {
|
|
9
49
|
try {
|
|
10
50
|
const output = await promise;
|
|
11
51
|
return Object.assign(
|
|
12
|
-
[null, output,
|
|
13
|
-
{ error: null, data: output,
|
|
52
|
+
[null, output, null, true],
|
|
53
|
+
{ error: null, data: output, inferableError: null, isSuccess: true }
|
|
14
54
|
);
|
|
15
55
|
} catch (e) {
|
|
16
56
|
const error = e;
|
|
17
|
-
if (
|
|
57
|
+
if (isInferableError(error)) {
|
|
18
58
|
return Object.assign(
|
|
19
|
-
[error, void 0,
|
|
20
|
-
{ error, data: void 0,
|
|
59
|
+
[error, void 0, error, false],
|
|
60
|
+
{ error, data: void 0, inferableError: error, isSuccess: false }
|
|
21
61
|
);
|
|
22
62
|
}
|
|
23
63
|
return Object.assign(
|
|
24
|
-
[error, void 0,
|
|
25
|
-
{ error, data: void 0,
|
|
64
|
+
[error, void 0, null, false],
|
|
65
|
+
{ error, data: void 0, inferableError: null, isSuccess: false }
|
|
26
66
|
);
|
|
27
67
|
}
|
|
28
68
|
}
|
|
29
|
-
function resolveFriendlyClientOptions(options) {
|
|
30
|
-
return {
|
|
31
|
-
...options,
|
|
32
|
-
context: options.context ?? {}
|
|
33
|
-
// Context only optional if all fields are optional
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
69
|
function consumeEventIterator(iterator, options) {
|
|
37
70
|
void (async () => {
|
|
38
71
|
let onFinishState;
|
|
@@ -63,32 +96,39 @@ function consumeEventIterator(iterator, options) {
|
|
|
63
96
|
};
|
|
64
97
|
}
|
|
65
98
|
|
|
66
|
-
function createORPCClient(link, options = {}) {
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
99
|
+
function createORPCClient(link, { path = [], ...options } = {}) {
|
|
100
|
+
const procedureClient = (...rest) => {
|
|
101
|
+
const [input, callOptions] = resolveClientRest(rest);
|
|
102
|
+
const interceptors = [
|
|
103
|
+
...toArray(options.interceptors),
|
|
104
|
+
...toArray(options.scoped?.interceptors)
|
|
105
|
+
];
|
|
106
|
+
return intercept(
|
|
107
|
+
interceptors,
|
|
108
|
+
{ ...callOptions, input, path },
|
|
109
|
+
({ path: path2, input: input2, ...callOptions2 }) => link.call(path2, input2, callOptions2)
|
|
110
|
+
);
|
|
70
111
|
};
|
|
71
112
|
const recursive = new Proxy(procedureClient, {
|
|
72
113
|
get(target, key) {
|
|
73
|
-
if (typeof key !== "string") {
|
|
74
|
-
return
|
|
114
|
+
if (typeof key !== "string" || RECURSIVE_CLIENT_UNWRAP_KEYS.has(key)) {
|
|
115
|
+
return getOrBind(target, key);
|
|
75
116
|
}
|
|
117
|
+
const scoped = options.scoped === void 0 ? void 0 : options.scoped[key];
|
|
76
118
|
return createORPCClient(link, {
|
|
77
119
|
...options,
|
|
78
|
-
path: [...path, key]
|
|
120
|
+
path: [...path, key],
|
|
121
|
+
scoped
|
|
79
122
|
});
|
|
80
123
|
}
|
|
81
124
|
});
|
|
82
|
-
return
|
|
125
|
+
return recursive;
|
|
83
126
|
}
|
|
84
127
|
|
|
85
128
|
function createSafeClient(client) {
|
|
86
129
|
const proxy = new Proxy((...args) => safe(client(...args)), {
|
|
87
|
-
get(_, prop
|
|
88
|
-
const value =
|
|
89
|
-
if (typeof prop !== "string") {
|
|
90
|
-
return value;
|
|
91
|
-
}
|
|
130
|
+
get(_, prop) {
|
|
131
|
+
const value = getOrBind(client, prop);
|
|
92
132
|
if (!isTypescriptObject(value)) {
|
|
93
133
|
return value;
|
|
94
134
|
}
|
|
@@ -109,4 +149,6 @@ class DynamicLink {
|
|
|
109
149
|
}
|
|
110
150
|
}
|
|
111
151
|
|
|
112
|
-
|
|
152
|
+
const isDefinedError = isInferableError;
|
|
153
|
+
|
|
154
|
+
export { DynamicLink, RECURSIVE_CLIENT_UNWRAP_KEYS, consumeEventIterator, createORPCClient, createSafeClient, isDefinedError, isInferableError, resolveClientRest, resolveFriendlyClientOptions, safe };
|