@orpc/client 1.14.10 → 1.14.11

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 (38) hide show
  1. package/README.md +52 -68
  2. package/dist/adapters/fetch/index.d.mts +54 -35
  3. package/dist/adapters/fetch/index.d.ts +54 -35
  4. package/dist/adapters/fetch/index.mjs +74 -27
  5. package/dist/adapters/message-port/index.d.mts +25 -30
  6. package/dist/adapters/message-port/index.d.ts +25 -30
  7. package/dist/adapters/message-port/index.mjs +39 -30
  8. package/dist/adapters/standard/index.d.mts +59 -9
  9. package/dist/adapters/standard/index.d.ts +59 -9
  10. package/dist/adapters/standard/index.mjs +5 -5
  11. package/dist/adapters/websocket/index.d.mts +113 -21
  12. package/dist/adapters/websocket/index.d.ts +113 -21
  13. package/dist/adapters/websocket/index.mjs +95 -37
  14. package/dist/index.d.mts +75 -184
  15. package/dist/index.d.ts +75 -184
  16. package/dist/index.mjs +74 -63
  17. package/dist/plugins/index.d.mts +191 -122
  18. package/dist/plugins/index.d.ts +191 -122
  19. package/dist/plugins/index.mjs +627 -281
  20. package/dist/shared/client.8f4DNmdE.d.mts +96 -0
  21. package/dist/shared/client.BBZBQID8.d.mts +167 -0
  22. package/dist/shared/client.BBZBQID8.d.ts +167 -0
  23. package/dist/shared/client.BMKYqpdy.d.ts +96 -0
  24. package/dist/shared/client.BRJnOJ0R.mjs +174 -0
  25. package/dist/shared/client.BdItY5DT.d.mts +111 -0
  26. package/dist/shared/client.BdItY5DT.d.ts +111 -0
  27. package/dist/shared/client.Dnfj8jnT.mjs +92 -0
  28. package/dist/shared/client.DqYwRDUO.mjs +343 -0
  29. package/package.json +7 -7
  30. package/dist/shared/client.2jUAqzYU.d.ts +0 -45
  31. package/dist/shared/client.B3pNRBih.d.ts +0 -91
  32. package/dist/shared/client.BFAVy68H.d.mts +0 -91
  33. package/dist/shared/client.BLtwTQUg.mjs +0 -40
  34. package/dist/shared/client.CpCa3si8.d.mts +0 -45
  35. package/dist/shared/client.DsgfctKs.mjs +0 -174
  36. package/dist/shared/client.i2uoJbEp.d.mts +0 -83
  37. package/dist/shared/client.i2uoJbEp.d.ts +0 -83
  38. package/dist/shared/client.wv-wJnEy.mjs +0 -404
package/dist/index.d.ts CHANGED
@@ -1,197 +1,78 @@
1
- import { N as NestedClient, C as ClientLink, I as InferClientContext, a as ClientPromiseResult, b as ClientContext, F as FriendlyClientOptions, c as ClientOptions, d as Client, e as ClientRest } from './shared/client.i2uoJbEp.js';
2
- export { f as HTTPMethod, H as HTTPPath, h as InferClientBodyInputs, j as InferClientBodyOutputs, l as InferClientErrorUnion, k as InferClientErrors, g as InferClientInputs, i as InferClientOutputs } from './shared/client.i2uoJbEp.js';
3
- import { MaybeOptionalOptions, ThrowableError, OnFinishState, Promisable, AsyncIteratorClass } from '@orpc/shared';
4
- export { AsyncIteratorClass, EventPublisher, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, Registry, ThrowableError, asyncIteratorToStream as eventIteratorToStream, asyncIteratorToUnproxiedDataStream as eventIteratorToUnproxiedDataStream, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@orpc/shared';
5
- export { ErrorEvent, EventMeta, getEventMeta, withEventMeta } from '@orpc/standard-server';
1
+ import { WrapAsyncIteratorOptions, AsyncIteratorClass, Interceptor, PromiseWithError, ThrowableError, Promisable } from '@orpc/shared';
2
+ export { AsyncCleanupFn, AsyncIteratorClass, AsyncIteratorClassNextFn, MaybeOptionalOptions, PromiseWithError, Registry, ThrowableError, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, consumeAsyncIterator, consumeAsyncIterator as consumeEventIterator, asyncIteratorToStream as eventIteratorToStream, asyncIteratorToUnproxiedDataStream as eventIteratorToUnproxiedDataStream, onAsyncIteratorObjectError, onError, onFinish, onReadableStreamError, onStart, onSuccess, streamToAsyncIteratorObject, streamToAsyncIteratorObject as streamToEventIterator } from '@orpc/shared';
3
+ import { C as ClientContext, a as ClientOptions, c as AnyNestedClient, I as InferClientContext, d as InferClientError, e as Client, b as ClientLink, A as AnyORPCError, f as ClientRest, F as FriendlyClientOptions, O as ORPCErrorCode, g as ORPCError, h as ORPCErrorJSON } from './shared/client.BBZBQID8.js';
4
+ export { i as AnyORPCErrorJSON, j as COMMON_ERROR_STATUS_MAP, k as InferClientBodyInputs, l as InferClientBodyOutputs, m as InferClientErrors, n as InferClientInputs, o as InferClientOutputs, N as NestedClient, p as ORPCErrorOptions } from './shared/client.BBZBQID8.js';
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, EventMeta, getEventMeta, unwrapEvent, withEventMeta } from '@standardserver/core';
6
7
 
7
- interface createORPCClientOptions {
8
+ declare function wrapAsyncIteratorPreservingEventMeta<TYield, TReturn, TMappedYield = TYield, TMappedReturn = TReturn>(iterator: AsyncIterator<TYield, TReturn>, { mapResult, mapError, ...rest }: WrapAsyncIteratorOptions<TYield, TReturn, TMappedYield, TMappedReturn>): AsyncIteratorClass<TMappedYield, TMappedReturn>;
9
+
10
+ interface ORPCClientInterceptorOptions<TClientContext extends ClientContext, TInput> extends ClientOptions<TClientContext> {
11
+ path: string[];
12
+ input: TInput;
13
+ }
14
+ type ORPCClientInterceptor<TClientContext extends ClientContext, TInput, TOutput, TError> = Interceptor<ORPCClientInterceptorOptions<TClientContext, TInput>, PromiseWithError<TOutput, TError>>;
15
+ interface ORPCClientScopedOptions<TClientContext extends ClientContext, TInput, TOutput, TError> {
8
16
  /**
9
- * Use as base path for all procedure, useful when you only want to call a subset of the procedure.
17
+ * Interceptors that wrap the entire client call lifecycle.
10
18
  */
11
- path?: readonly string[];
19
+ interceptors?: ORPCClientInterceptor<TClientContext, TInput, TOutput, TError>[];
12
20
  }
13
- /**
14
- * Create a oRPC client-side client from a link.
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
- };
21
+ type ORPCClientScoped<T extends AnyNestedClient> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ORPCClientScopedOptions<UClientContext, UInput, UOutput, UError> : {
22
+ [K in keyof T]?: T[K] extends AnyNestedClient ? ORPCClientScoped<T[K]> : never;
97
23
  };
98
- type CommonORPCErrorCode = keyof typeof COMMON_ORPC_ERROR_DEFS;
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>;
24
+ interface ORPCClientOptions<T extends AnyNestedClient> {
118
25
  /**
119
- * Workaround for Next.js where different contexts use separate
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.
26
+ * Use as base path for all procedure, useful when you only want to call a subset of the procedure.
129
27
  */
130
- static [Symbol.hasInstance](instance: unknown): boolean;
28
+ path?: string[];
29
+ /**
30
+ * Interceptors that wrap the entire client call lifecycle, applied to every procedure call.
31
+ */
32
+ interceptors?: ORPCClientInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[];
33
+ /**
34
+ * Per-procedure options following the shape of the router.
35
+ * Allows fine-grained configuration (e.g. additional interceptors) for individual procedures
36
+ * without affecting the rest of the router.
37
+ */
38
+ scoped?: ORPCClientScoped<T>;
131
39
  }
132
- type ORPCErrorJSON<TCode extends string, TData> = Pick<ORPCError<TCode, TData>, 'defined' | 'code' | 'status' | 'message' | 'data'>;
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>;
40
+ declare function createORPCClient<T extends AnyNestedClient>(link: ClientLink<InferClientContext<T>>, { path, ...options }?: NoInfer<ORPCClientOptions<T>>): T;
138
41
 
139
- type SafeResult<TOutput, TError> = [error: null, data: TOutput, isDefined: false, isSuccess: true] & {
42
+ declare function resolveFriendlyClientOptions<T extends ClientContext>(options: FriendlyClientOptions<T>): ClientOptions<T>;
43
+ declare function resolveClientRest<TClientContext extends ClientContext, TInput>(rest: ClientRest<TClientContext, TInput>): [input: TInput, options: ClientOptions<TClientContext>];
44
+ type SafeResult<TOutput, TError> = [error: null, data: TOutput, inferableError: null, isSuccess: true] & {
140
45
  error: null;
141
46
  data: TOutput;
142
- isDefined: false;
47
+ inferableError: null;
143
48
  isSuccess: true;
144
- } | [error: Exclude<TError, ORPCError<any, any>>, data: undefined, isDefined: false, isSuccess: false] & {
145
- error: Exclude<TError, ORPCError<any, any>>;
49
+ } | [error: Exclude<TError, AnyORPCError>, data: undefined, inferableError: null, isSuccess: false] & {
50
+ error: Exclude<TError, AnyORPCError>;
146
51
  data: undefined;
147
- isDefined: false;
52
+ inferableError: null;
148
53
  isSuccess: false;
149
- } | [error: Extract<TError, ORPCError<any, any>>, data: undefined, isDefined: true, isSuccess: false] & {
150
- error: Extract<TError, ORPCError<any, any>>;
54
+ } | [error: Extract<TError, AnyORPCError>, data: undefined, inferableError: Extract<TError, AnyORPCError>, isSuccess: false] & {
55
+ error: Extract<TError, AnyORPCError>;
151
56
  data: undefined;
152
- isDefined: true;
57
+ inferableError: Extract<TError, AnyORPCError>;
153
58
  isSuccess: false;
154
59
  };
155
60
  /**
156
- * Works like try/catch, but can infer error types.
61
+ * Works like try/catch, but help you infer the error type if it is inferable ORPCError.
157
62
  *
158
- * @info support both tuple `[error, data, isDefined, isSuccess]` and object `{ error, data, isDefined, isSuccess }` styles.
159
- * @see {@link https://orpc.dev/docs/client/error-handling Client Error Handling Docs}
160
- */
161
- declare function safe<TOutput, TError = ThrowableError>(promise: ClientPromiseResult<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
162
- declare function resolveFriendlyClientOptions<T extends ClientContext>(options: FriendlyClientOptions<T>): ClientOptions<T>;
163
- interface ConsumeEventIteratorOptions<T, TReturn, TError> {
164
- /**
165
- * Called on each event
166
- */
167
- onEvent: (event: T) => void;
168
- /**
169
- * Called once error happens
170
- */
171
- onError?: (error: TError) => void;
172
- /**
173
- * Called once event iterator is done
174
- *
175
- * @info If iterator is canceled, `undefined` can be passed on success
176
- */
177
- onSuccess?: (value: TReturn | undefined) => void;
178
- /**
179
- * Called once after onError or onSuccess
180
- *
181
- * @info If iterator is canceled, `undefined` can be passed on success
182
- */
183
- onFinish?: (state: OnFinishState<TReturn | undefined, TError>) => void;
184
- }
185
- /**
186
- * Consumes an event iterator with lifecycle callbacks
63
+ * @example
64
+ * ```ts
65
+ * const [error, data, inferableError, isSuccess] = await safe(client(...))
66
+ * // or const { error, data, inferableError, isSuccess } = await safe(client(...))
187
67
  *
188
- * @warning If no `onError` or `onFinish` is provided, unhandled rejections will be thrown
189
- * @return unsubscribe callback
68
+ * if (inferableError) {
69
+ * console.log(inferableError) // or error, both are well typed
70
+ * }
190
71
  */
191
- declare function consumeEventIterator<T, TReturn, TError = ThrowableError>(iterator: AsyncIterator<T, TReturn> | ClientPromiseResult<AsyncIterator<T, TReturn>, TError>, options: ConsumeEventIteratorOptions<T, TReturn, TError>): () => Promise<void>;
72
+ declare function safe<TOutput, TError = ThrowableError>(promise: PromiseWithError<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
192
73
 
193
- type SafeClient<T extends NestedClient<any>> = T extends Client<infer UContext, infer UInput, infer UOutput, infer UError> ? (...rest: ClientRest<UContext, UInput>) => Promise<SafeResult<UOutput, UError>> : {
194
- [K in keyof T]: T[K] extends NestedClient<any> ? SafeClient<T[K]> : never;
74
+ type SafeClient<T extends AnyNestedClient> = T extends Client<infer UContext, infer UInput, infer UOutput, infer UError> ? (...rest: ClientRest<UContext, UInput>) => Promise<SafeResult<UOutput, UError>> : {
75
+ [K in keyof T]: T[K] extends AnyNestedClient ? SafeClient<T[K]> : never;
195
76
  };
196
77
  /**
197
78
  * Create a safe client that automatically wraps all procedure calls with the `safe` util.
@@ -199,15 +80,24 @@ type SafeClient<T extends NestedClient<any>> = T extends Client<infer UContext,
199
80
  * @example
200
81
  * ```ts
201
82
  * const safeClient = createSafeClient(client)
202
- * const { error, data, isDefined } = await safeClient.doSomething({ id: '123' })
83
+ * const { error, data, inferrableError, isSuccess } = await safeClient.doSomething({ id: '123' })
84
+ * // or const [error, data, inferrableError, isSuccess] = await safeClient.doSomething({ id: '123' })
203
85
  * ```
204
86
  *
205
87
  * @see {@link https://orpc.dev/docs/client/error-handling#using-createsafeclient Safe Client Docs}
206
88
  */
207
- declare function createSafeClient<T extends NestedClient<any>>(client: T): SafeClient<T>;
89
+ declare function createSafeClient<T extends AnyNestedClient>(client: T): SafeClient<T>;
208
90
 
209
- declare const ORPC_CLIENT_PACKAGE_NAME = "@orpc/client";
210
- declare const ORPC_CLIENT_PACKAGE_VERSION = "1.14.10";
91
+ /**
92
+ * Property names that should resolve to the underlying value instead of
93
+ * continuing recursive proxy traversal.
94
+ *
95
+ * These properties are commonly accessed automatically by JavaScript runtimes,
96
+ * language features, or third-party libraries. Returning another recursive
97
+ * proxy for them can cause unexpected behavior, compatibility issues, or
98
+ * infinite proxy chains.
99
+ */
100
+ declare const RECURSIVE_CLIENT_UNWRAP_KEYS: Set<string>;
211
101
 
212
102
  /**
213
103
  * DynamicLink provides a way to dynamically resolve and delegate calls to other ClientLinks
@@ -217,14 +107,15 @@ declare const ORPC_CLIENT_PACKAGE_VERSION = "1.14.10";
217
107
  */
218
108
  declare class DynamicLink<TClientContext extends ClientContext> implements ClientLink<TClientContext> {
219
109
  private readonly linkResolver;
220
- constructor(linkResolver: (options: ClientOptions<TClientContext>, path: readonly string[], input: unknown) => Promisable<ClientLink<TClientContext>>);
221
- call(path: readonly string[], input: unknown, options: ClientOptions<TClientContext>): Promise<unknown>;
110
+ constructor(linkResolver: (options: ClientOptions<TClientContext>, path: string[], input: unknown) => Promisable<ClientLink<TClientContext>>);
111
+ call(path: string[], input: unknown, options: ClientOptions<TClientContext>): Promise<unknown>;
222
112
  }
223
113
 
224
- declare function mapEventIterator<TYield, TReturn, TNext, TMap = TYield | TReturn>(iterator: AsyncIterator<TYield, TReturn, TNext>, maps: {
225
- value: (value: NoInfer<TYield | TReturn>, done: boolean | undefined) => Promise<TMap>;
226
- error: (error: unknown) => Promise<unknown>;
227
- }): AsyncIteratorClass<TMap, TMap, TNext>;
114
+ declare function isInferableError<T>(error: T): error is Extract<T, AnyORPCError>;
115
+ declare function toORPCError<T>(error: T): Extract<T, AnyORPCError> | ORPCError<'INTERNAL_SERVER_ERROR', undefined>;
116
+ declare function isORPCErrorJson(json: unknown): json is ORPCErrorJSON<ORPCErrorCode, unknown>;
117
+ declare function createORPCErrorFromJson<TCode extends ORPCErrorCode, TData>(json: ORPCErrorJSON<TCode, TData>, options?: ErrorOptions): ORPCError<TCode, TData>;
118
+ declare function cloneORPCError<T extends ORPCErrorCode, TData>(error: ORPCError<T, TData>): ORPCError<T, TData>;
228
119
 
229
- export { COMMON_ORPC_ERROR_DEFS, Client, ClientContext, ClientLink, ClientOptions, ClientPromiseResult, ClientRest, DynamicLink, FriendlyClientOptions, InferClientContext, NestedClient, ORPCError, ORPC_CLIENT_PACKAGE_NAME, ORPC_CLIENT_PACKAGE_VERSION, consumeEventIterator, createORPCClient, createORPCErrorFromJson, createSafeClient, fallbackORPCErrorMessage, fallbackORPCErrorStatus, isDefinedError, isORPCErrorJson, isORPCErrorStatus, mapEventIterator, resolveFriendlyClientOptions, safe, toORPCError };
230
- export type { CommonORPCErrorCode, ConsumeEventIteratorOptions, ORPCErrorCode, ORPCErrorJSON, ORPCErrorOptions, SafeClient, SafeResult, createORPCClientOptions };
120
+ export { AnyNestedClient, AnyORPCError, Client, ClientContext, ClientLink, ClientOptions, ClientRest, DynamicLink, FriendlyClientOptions, InferClientContext, InferClientError, ORPCError, ORPCErrorCode, ORPCErrorJSON, RECURSIVE_CLIENT_UNWRAP_KEYS, cloneORPCError, createORPCClient, createORPCErrorFromJson, createSafeClient, isInferableError as isDefinedError, isInferableError, isORPCErrorJson, resolveClientRest, resolveFriendlyClientOptions, safe, toORPCError, wrapAsyncIteratorPreservingEventMeta };
121
+ export type { ORPCClientInterceptor, ORPCClientInterceptorOptions, ORPCClientOptions, ORPCClientScoped, ORPCClientScopedOptions, SafeClient, SafeResult };
package/dist/index.mjs CHANGED
@@ -1,94 +1,105 @@
1
- import { preventNativeAwait, isTypescriptObject } from '@orpc/shared';
2
- export { AsyncIteratorClass, EventPublisher, asyncIteratorToStream as eventIteratorToStream, asyncIteratorToUnproxiedDataStream as eventIteratorToUnproxiedDataStream, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@orpc/shared';
3
- import { i as isDefinedError } from './shared/client.DsgfctKs.mjs';
4
- export { C as COMMON_ORPC_ERROR_DEFS, c as ORPCError, O as ORPC_CLIENT_PACKAGE_NAME, a as ORPC_CLIENT_PACKAGE_VERSION, g as createORPCErrorFromJson, b as fallbackORPCErrorMessage, f as fallbackORPCErrorStatus, e as isORPCErrorJson, d as isORPCErrorStatus, t as toORPCError } from './shared/client.DsgfctKs.mjs';
5
- export { m as mapEventIterator } from './shared/client.BLtwTQUg.mjs';
6
- export { ErrorEvent, getEventMeta, withEventMeta } from '@orpc/standard-server';
1
+ import { a as isInferableError } from './shared/client.DqYwRDUO.mjs';
2
+ export { b as RPCJsonSerializer, R as RPCSerializer, d as cloneORPCError, c as createORPCErrorFromJson, i as isORPCErrorJson, t as toORPCError, w as wrapAsyncIteratorPreservingEventMeta } from './shared/client.DqYwRDUO.mjs';
3
+ import { getOrBind, toArray, intercept, isTypescriptObject } from '@orpc/shared';
4
+ export { AsyncIteratorClass, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, consumeAsyncIterator, consumeAsyncIterator as consumeEventIterator, asyncIteratorToStream as eventIteratorToStream, asyncIteratorToUnproxiedDataStream as eventIteratorToUnproxiedDataStream, onAsyncIteratorObjectError, onError, onFinish, onReadableStreamError, onStart, onSuccess, streamToAsyncIteratorObject, streamToAsyncIteratorObject as streamToEventIterator } from '@orpc/shared';
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, false, true],
13
- { error: null, data: output, isDefined: false, isSuccess: true }
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 (isDefinedError(error)) {
57
+ if (isInferableError(error)) {
18
58
  return Object.assign(
19
- [error, void 0, true, false],
20
- { error, data: void 0, isDefined: true, isSuccess: false }
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, false, false],
25
- { error, data: void 0, isDefined: false, isSuccess: false }
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
- function consumeEventIterator(iterator, options) {
37
- void (async () => {
38
- let onFinishState;
39
- try {
40
- const resolvedIterator = await iterator;
41
- while (true) {
42
- const { done, value } = await resolvedIterator.next();
43
- if (done) {
44
- const realValue = value;
45
- onFinishState = [null, realValue, true];
46
- options.onSuccess?.(realValue);
47
- break;
48
- }
49
- options.onEvent(value);
50
- }
51
- } catch (error) {
52
- onFinishState = [error, void 0, false];
53
- if (!options.onError && !options.onFinish) {
54
- throw error;
55
- }
56
- options.onError?.(error);
57
- } finally {
58
- options.onFinish?.(onFinishState);
59
- }
60
- })();
61
- return async () => {
62
- await (await iterator)?.return?.();
63
- };
64
- }
65
69
 
66
- function createORPCClient(link, options = {}) {
67
- const path = options.path ?? [];
68
- const procedureClient = async (...[input, options2 = {}]) => {
69
- return await link.call(path, input, resolveFriendlyClientOptions(options2));
70
+ function createORPCClient(link, { path = [], ...options } = {}) {
71
+ const procedureClient = (...rest) => {
72
+ const [input, callOptions] = resolveClientRest(rest);
73
+ const interceptors = [
74
+ ...toArray(options.interceptors),
75
+ ...toArray(options.scoped?.interceptors)
76
+ ];
77
+ return intercept(
78
+ interceptors,
79
+ { ...callOptions, input, path },
80
+ ({ path: path2, input: input2, ...callOptions2 }) => link.call(path2, input2, callOptions2)
81
+ );
70
82
  };
71
83
  const recursive = new Proxy(procedureClient, {
72
84
  get(target, key) {
73
- if (typeof key !== "string") {
74
- return Reflect.get(target, key);
85
+ if (typeof key !== "string" || RECURSIVE_CLIENT_UNWRAP_KEYS.has(key)) {
86
+ return getOrBind(target, key);
75
87
  }
88
+ const scoped = options.scoped === void 0 ? void 0 : options.scoped[key];
76
89
  return createORPCClient(link, {
77
90
  ...options,
78
- path: [...path, key]
91
+ path: [...path, key],
92
+ scoped
79
93
  });
80
94
  }
81
95
  });
82
- return preventNativeAwait(recursive);
96
+ return recursive;
83
97
  }
84
98
 
85
99
  function createSafeClient(client) {
86
100
  const proxy = new Proxy((...args) => safe(client(...args)), {
87
- get(_, prop, receiver) {
88
- const value = Reflect.get(client, prop, receiver);
89
- if (typeof prop !== "string") {
90
- return value;
91
- }
101
+ get(_, prop) {
102
+ const value = getOrBind(client, prop);
92
103
  if (!isTypescriptObject(value)) {
93
104
  return value;
94
105
  }
@@ -109,4 +120,4 @@ class DynamicLink {
109
120
  }
110
121
  }
111
122
 
112
- export { DynamicLink, consumeEventIterator, createORPCClient, createSafeClient, isDefinedError, resolveFriendlyClientOptions, safe };
123
+ export { DynamicLink, RECURSIVE_CLIENT_UNWRAP_KEYS, createORPCClient, createSafeClient, isInferableError as isDefinedError, isInferableError, resolveClientRest, resolveFriendlyClientOptions, safe };