@orpc/client 1.14.11 → 1.14.12

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 +68 -52
  2. package/dist/adapters/fetch/index.d.mts +35 -54
  3. package/dist/adapters/fetch/index.d.ts +35 -54
  4. package/dist/adapters/fetch/index.mjs +27 -74
  5. package/dist/adapters/message-port/index.d.mts +30 -25
  6. package/dist/adapters/message-port/index.d.ts +30 -25
  7. package/dist/adapters/message-port/index.mjs +30 -39
  8. package/dist/adapters/standard/index.d.mts +9 -59
  9. package/dist/adapters/standard/index.d.ts +9 -59
  10. package/dist/adapters/standard/index.mjs +5 -5
  11. package/dist/adapters/websocket/index.d.mts +21 -113
  12. package/dist/adapters/websocket/index.d.ts +21 -113
  13. package/dist/adapters/websocket/index.mjs +37 -95
  14. package/dist/index.d.mts +184 -75
  15. package/dist/index.d.ts +184 -75
  16. package/dist/index.mjs +63 -74
  17. package/dist/plugins/index.d.mts +122 -191
  18. package/dist/plugins/index.d.ts +122 -191
  19. package/dist/plugins/index.mjs +281 -627
  20. package/dist/shared/client.2jUAqzYU.d.ts +45 -0
  21. package/dist/shared/client.B3pNRBih.d.ts +91 -0
  22. package/dist/shared/client.BFAVy68H.d.mts +91 -0
  23. package/dist/shared/client.BLtwTQUg.mjs +40 -0
  24. package/dist/shared/client.C1VUaWTu.mjs +404 -0
  25. package/dist/shared/client.CpCa3si8.d.mts +45 -0
  26. package/dist/shared/client.DrCRv_sG.mjs +174 -0
  27. package/dist/shared/client.i2uoJbEp.d.mts +83 -0
  28. package/dist/shared/client.i2uoJbEp.d.ts +83 -0
  29. package/package.json +7 -7
  30. package/dist/shared/client.8f4DNmdE.d.mts +0 -96
  31. package/dist/shared/client.BBZBQID8.d.mts +0 -167
  32. package/dist/shared/client.BBZBQID8.d.ts +0 -167
  33. package/dist/shared/client.BMKYqpdy.d.ts +0 -96
  34. package/dist/shared/client.BRJnOJ0R.mjs +0 -174
  35. package/dist/shared/client.BdItY5DT.d.mts +0 -111
  36. package/dist/shared/client.BdItY5DT.d.ts +0 -111
  37. package/dist/shared/client.Dnfj8jnT.mjs +0 -92
  38. package/dist/shared/client.DqYwRDUO.mjs +0 -343
package/dist/index.d.ts CHANGED
@@ -1,78 +1,197 @@
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';
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';
7
6
 
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> {
7
+ interface createORPCClientOptions {
16
8
  /**
17
- * Interceptors that wrap the entire client call lifecycle.
9
+ * Use as base path for all procedure, useful when you only want to call a subset of the procedure.
18
10
  */
19
- interceptors?: ORPCClientInterceptor<TClientContext, TInput, TOutput, TError>[];
11
+ path?: readonly string[];
20
12
  }
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;
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
+ };
23
97
  };
24
- interface ORPCClientOptions<T extends AnyNestedClient> {
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>;
25
118
  /**
26
- * Use as base path for all procedure, useful when you only want to call a subset of the procedure.
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.
27
129
  */
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>;
130
+ static [Symbol.hasInstance](instance: unknown): boolean;
39
131
  }
40
- declare function createORPCClient<T extends AnyNestedClient>(link: ClientLink<InferClientContext<T>>, { path, ...options }?: NoInfer<ORPCClientOptions<T>>): T;
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>;
41
138
 
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] & {
139
+ type SafeResult<TOutput, TError> = [error: null, data: TOutput, isDefined: false, isSuccess: true] & {
45
140
  error: null;
46
141
  data: TOutput;
47
- inferableError: null;
142
+ isDefined: false;
48
143
  isSuccess: true;
49
- } | [error: Exclude<TError, AnyORPCError>, data: undefined, inferableError: null, isSuccess: false] & {
50
- error: Exclude<TError, AnyORPCError>;
144
+ } | [error: Exclude<TError, ORPCError<any, any>>, data: undefined, isDefined: false, isSuccess: false] & {
145
+ error: Exclude<TError, ORPCError<any, any>>;
51
146
  data: undefined;
52
- inferableError: null;
147
+ isDefined: false;
53
148
  isSuccess: false;
54
- } | [error: Extract<TError, AnyORPCError>, data: undefined, inferableError: Extract<TError, AnyORPCError>, isSuccess: false] & {
55
- error: Extract<TError, AnyORPCError>;
149
+ } | [error: Extract<TError, ORPCError<any, any>>, data: undefined, isDefined: true, isSuccess: false] & {
150
+ error: Extract<TError, ORPCError<any, any>>;
56
151
  data: undefined;
57
- inferableError: Extract<TError, AnyORPCError>;
152
+ isDefined: true;
58
153
  isSuccess: false;
59
154
  };
60
155
  /**
61
- * Works like try/catch, but help you infer the error type if it is inferable ORPCError.
156
+ * Works like try/catch, but can infer error types.
62
157
  *
63
- * @example
64
- * ```ts
65
- * const [error, data, inferableError, isSuccess] = await safe(client(...))
66
- * // or const { error, data, inferableError, isSuccess } = await safe(client(...))
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
67
187
  *
68
- * if (inferableError) {
69
- * console.log(inferableError) // or error, both are well typed
70
- * }
188
+ * @warning If no `onError` or `onFinish` is provided, unhandled rejections will be thrown
189
+ * @return unsubscribe callback
71
190
  */
72
- declare function safe<TOutput, TError = ThrowableError>(promise: PromiseWithError<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
191
+ declare function consumeEventIterator<T, TReturn, TError = ThrowableError>(iterator: AsyncIterator<T, TReturn> | ClientPromiseResult<AsyncIterator<T, TReturn>, TError>, options: ConsumeEventIteratorOptions<T, TReturn, TError>): () => Promise<void>;
73
192
 
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;
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;
76
195
  };
77
196
  /**
78
197
  * Create a safe client that automatically wraps all procedure calls with the `safe` util.
@@ -80,24 +199,15 @@ type SafeClient<T extends AnyNestedClient> = T extends Client<infer UContext, in
80
199
  * @example
81
200
  * ```ts
82
201
  * const safeClient = createSafeClient(client)
83
- * const { error, data, inferrableError, isSuccess } = await safeClient.doSomething({ id: '123' })
84
- * // or const [error, data, inferrableError, isSuccess] = await safeClient.doSomething({ id: '123' })
202
+ * const { error, data, isDefined } = await safeClient.doSomething({ id: '123' })
85
203
  * ```
86
204
  *
87
205
  * @see {@link https://orpc.dev/docs/client/error-handling#using-createsafeclient Safe Client Docs}
88
206
  */
89
- declare function createSafeClient<T extends AnyNestedClient>(client: T): SafeClient<T>;
207
+ declare function createSafeClient<T extends NestedClient<any>>(client: T): SafeClient<T>;
90
208
 
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>;
209
+ declare const ORPC_CLIENT_PACKAGE_NAME = "@orpc/client";
210
+ declare const ORPC_CLIENT_PACKAGE_VERSION = "1.14.12";
101
211
 
102
212
  /**
103
213
  * DynamicLink provides a way to dynamically resolve and delegate calls to other ClientLinks
@@ -107,15 +217,14 @@ declare const RECURSIVE_CLIENT_UNWRAP_KEYS: Set<string>;
107
217
  */
108
218
  declare class DynamicLink<TClientContext extends ClientContext> implements ClientLink<TClientContext> {
109
219
  private readonly linkResolver;
110
- constructor(linkResolver: (options: ClientOptions<TClientContext>, path: string[], input: unknown) => Promisable<ClientLink<TClientContext>>);
111
- call(path: string[], input: unknown, options: ClientOptions<TClientContext>): Promise<unknown>;
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>;
112
222
  }
113
223
 
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>;
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>;
119
228
 
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 };
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 };
package/dist/index.mjs CHANGED
@@ -1,105 +1,94 @@
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';
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.DrCRv_sG.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.DrCRv_sG.mjs';
5
+ export { m as mapEventIterator } from './shared/client.BLtwTQUg.mjs';
6
+ export { ErrorEvent, getEventMeta, withEventMeta } from '@orpc/standard-server';
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
- }
48
8
  async function safe(promise) {
49
9
  try {
50
10
  const output = await promise;
51
11
  return Object.assign(
52
- [null, output, null, true],
53
- { error: null, data: output, inferableError: null, isSuccess: true }
12
+ [null, output, false, true],
13
+ { error: null, data: output, isDefined: false, isSuccess: true }
54
14
  );
55
15
  } catch (e) {
56
16
  const error = e;
57
- if (isInferableError(error)) {
17
+ if (isDefinedError(error)) {
58
18
  return Object.assign(
59
- [error, void 0, error, false],
60
- { error, data: void 0, inferableError: error, isSuccess: false }
19
+ [error, void 0, true, false],
20
+ { error, data: void 0, isDefined: true, isSuccess: false }
61
21
  );
62
22
  }
63
23
  return Object.assign(
64
- [error, void 0, null, false],
65
- { error, data: void 0, inferableError: null, isSuccess: false }
24
+ [error, void 0, false, false],
25
+ { error, data: void 0, isDefined: false, isSuccess: false }
66
26
  );
67
27
  }
68
28
  }
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
+ }
69
65
 
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
- );
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));
82
70
  };
83
71
  const recursive = new Proxy(procedureClient, {
84
72
  get(target, key) {
85
- if (typeof key !== "string" || RECURSIVE_CLIENT_UNWRAP_KEYS.has(key)) {
86
- return getOrBind(target, key);
73
+ if (typeof key !== "string") {
74
+ return Reflect.get(target, key);
87
75
  }
88
- const scoped = options.scoped === void 0 ? void 0 : options.scoped[key];
89
76
  return createORPCClient(link, {
90
77
  ...options,
91
- path: [...path, key],
92
- scoped
78
+ path: [...path, key]
93
79
  });
94
80
  }
95
81
  });
96
- return recursive;
82
+ return preventNativeAwait(recursive);
97
83
  }
98
84
 
99
85
  function createSafeClient(client) {
100
86
  const proxy = new Proxy((...args) => safe(client(...args)), {
101
- get(_, prop) {
102
- const value = getOrBind(client, prop);
87
+ get(_, prop, receiver) {
88
+ const value = Reflect.get(client, prop, receiver);
89
+ if (typeof prop !== "string") {
90
+ return value;
91
+ }
103
92
  if (!isTypescriptObject(value)) {
104
93
  return value;
105
94
  }
@@ -120,4 +109,4 @@ class DynamicLink {
120
109
  }
121
110
  }
122
111
 
123
- export { DynamicLink, RECURSIVE_CLIENT_UNWRAP_KEYS, createORPCClient, createSafeClient, isInferableError as isDefinedError, isInferableError, resolveClientRest, resolveFriendlyClientOptions, safe };
112
+ export { DynamicLink, consumeEventIterator, createORPCClient, createSafeClient, isDefinedError, resolveFriendlyClientOptions, safe };