@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.
- package/README.md +68 -52
- package/dist/adapters/fetch/index.d.mts +35 -54
- package/dist/adapters/fetch/index.d.ts +35 -54
- package/dist/adapters/fetch/index.mjs +27 -74
- package/dist/adapters/message-port/index.d.mts +30 -25
- package/dist/adapters/message-port/index.d.ts +30 -25
- package/dist/adapters/message-port/index.mjs +30 -39
- package/dist/adapters/standard/index.d.mts +9 -59
- package/dist/adapters/standard/index.d.ts +9 -59
- package/dist/adapters/standard/index.mjs +5 -5
- package/dist/adapters/websocket/index.d.mts +21 -113
- package/dist/adapters/websocket/index.d.ts +21 -113
- package/dist/adapters/websocket/index.mjs +37 -95
- package/dist/index.d.mts +184 -75
- package/dist/index.d.ts +184 -75
- package/dist/index.mjs +63 -74
- package/dist/plugins/index.d.mts +122 -191
- package/dist/plugins/index.d.ts +122 -191
- package/dist/plugins/index.mjs +281 -627
- package/dist/shared/client.2jUAqzYU.d.ts +45 -0
- package/dist/shared/client.B3pNRBih.d.ts +91 -0
- package/dist/shared/client.BFAVy68H.d.mts +91 -0
- package/dist/shared/client.BLtwTQUg.mjs +40 -0
- package/dist/shared/client.C1VUaWTu.mjs +404 -0
- package/dist/shared/client.CpCa3si8.d.mts +45 -0
- package/dist/shared/client.DrCRv_sG.mjs +174 -0
- package/dist/shared/client.i2uoJbEp.d.mts +83 -0
- package/dist/shared/client.i2uoJbEp.d.ts +83 -0
- package/package.json +7 -7
- package/dist/shared/client.8f4DNmdE.d.mts +0 -96
- package/dist/shared/client.BBZBQID8.d.mts +0 -167
- package/dist/shared/client.BBZBQID8.d.ts +0 -167
- package/dist/shared/client.BMKYqpdy.d.ts +0 -96
- package/dist/shared/client.BRJnOJ0R.mjs +0 -174
- package/dist/shared/client.BdItY5DT.d.mts +0 -111
- package/dist/shared/client.BdItY5DT.d.ts +0 -111
- package/dist/shared/client.Dnfj8jnT.mjs +0 -92
- package/dist/shared/client.DqYwRDUO.mjs +0 -343
|
@@ -1,110 +1,52 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ClientPeer
|
|
3
|
-
import {
|
|
4
|
-
import '@
|
|
5
|
-
import '
|
|
6
|
-
import '
|
|
7
|
-
import '../../shared/client.
|
|
1
|
+
import { readAsBuffer } from '@orpc/shared';
|
|
2
|
+
import { ClientPeer } from '@orpc/standard-server-peer';
|
|
3
|
+
import { c as StandardRPCLink } from '../../shared/client.C1VUaWTu.mjs';
|
|
4
|
+
import '@orpc/standard-server';
|
|
5
|
+
import '../../shared/client.DrCRv_sG.mjs';
|
|
6
|
+
import '@orpc/standard-server-fetch';
|
|
7
|
+
import '../../shared/client.BLtwTQUg.mjs';
|
|
8
8
|
|
|
9
9
|
const WEBSOCKET_CONNECTING = 0;
|
|
10
10
|
const WEBSOCKET_OPEN = 1;
|
|
11
|
-
class
|
|
12
|
-
|
|
13
|
-
reconnectEnabled;
|
|
14
|
-
reconnectDelay;
|
|
15
|
-
reconnectMaxAttempt;
|
|
16
|
-
reconnectOnCloseEnabled;
|
|
17
|
-
reconnectOnCloseDelay;
|
|
18
|
-
encodePeerMessageOptions;
|
|
19
|
-
decodePeerMessageOptions;
|
|
11
|
+
class LinkWebsocketClient {
|
|
12
|
+
peer;
|
|
20
13
|
constructor(options) {
|
|
21
|
-
this.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
async send(standardRequest, _path, _options) {
|
|
35
|
-
const peer = await runWithSignal(
|
|
36
|
-
standardRequest.signal,
|
|
37
|
-
() => this.getConnectedPeer()
|
|
38
|
-
);
|
|
39
|
-
return peer.request(standardRequest);
|
|
40
|
-
}
|
|
41
|
-
totalAttempt = 0;
|
|
42
|
-
attempt = 0;
|
|
43
|
-
current;
|
|
44
|
-
async getConnectedPeer() {
|
|
45
|
-
const current = this.current;
|
|
46
|
-
const resolved = await current;
|
|
47
|
-
if (resolved && (!this.reconnectEnabled || resolved.websocket.readyState === WEBSOCKET_OPEN)) {
|
|
48
|
-
this.attempt = 0;
|
|
49
|
-
return resolved.peer;
|
|
50
|
-
}
|
|
51
|
-
if (current !== this.current) {
|
|
52
|
-
return this.getConnectedPeer();
|
|
53
|
-
}
|
|
54
|
-
if (this.attempt >= this.reconnectMaxAttempt) {
|
|
55
|
-
throw new AbortError(`WebSocket reconnect failed after ${this.attempt} attempt(s)`);
|
|
56
|
-
}
|
|
57
|
-
this.current = (async () => {
|
|
58
|
-
this.totalAttempt += 1;
|
|
59
|
-
this.attempt += 1;
|
|
60
|
-
const info = { totalAttempt: this.totalAttempt, attempt: this.attempt };
|
|
61
|
-
await sleep(this.reconnectDelay(info));
|
|
62
|
-
const websocket = await this.connect(info);
|
|
63
|
-
const peer = new ClientPeer(async (message) => {
|
|
64
|
-
const encoded = await encodePeerMessage(message, this.encodePeerMessageOptions);
|
|
65
|
-
return websocket.send(encoded);
|
|
66
|
-
});
|
|
67
|
-
let connectingResolvers;
|
|
68
|
-
if (websocket.readyState === WEBSOCKET_CONNECTING) {
|
|
69
|
-
connectingResolvers = promiseWithResolvers();
|
|
70
|
-
websocket.addEventListener("open", () => {
|
|
71
|
-
connectingResolvers?.resolve();
|
|
14
|
+
this.peer = new ClientPeer(async (message) => {
|
|
15
|
+
if (options.websocket.readyState === WEBSOCKET_CONNECTING) {
|
|
16
|
+
await new Promise((resolve) => {
|
|
17
|
+
const settle = () => {
|
|
18
|
+
options.websocket.removeEventListener("open", settle);
|
|
19
|
+
options.websocket.removeEventListener("close", settle);
|
|
20
|
+
resolve();
|
|
21
|
+
};
|
|
22
|
+
options.websocket.addEventListener("open", settle, { once: true });
|
|
23
|
+
options.websocket.addEventListener("close", settle, { once: true });
|
|
72
24
|
});
|
|
73
25
|
}
|
|
74
|
-
websocket.
|
|
75
|
-
|
|
76
|
-
const result = decodePeerMessage(message, this.decodePeerMessageOptions);
|
|
77
|
-
if (result.matched && isServerPeerSendMessage(result.message)) {
|
|
78
|
-
peer.message(result.message);
|
|
79
|
-
}
|
|
80
|
-
}));
|
|
81
|
-
websocket.addEventListener("close", async (event) => {
|
|
82
|
-
connectingResolvers?.resolve();
|
|
83
|
-
if (this.reconnectOnCloseEnabled) {
|
|
84
|
-
sleep(this.reconnectOnCloseDelay).then(() => this.getConnectedPeer()).catch(() => {
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
const reason = new AbortError(`WebSocket closed (code ${event.code}: ${event.reason})`);
|
|
88
|
-
await peer.close(reason);
|
|
89
|
-
});
|
|
90
|
-
await connectingResolvers?.promise;
|
|
91
|
-
connectingResolvers = void 0;
|
|
92
|
-
return { websocket, peer };
|
|
93
|
-
})().catch((error) => {
|
|
94
|
-
if (!this.reconnectEnabled) {
|
|
95
|
-
throw error;
|
|
26
|
+
if (options.websocket.readyState !== WEBSOCKET_OPEN) {
|
|
27
|
+
throw new Error("Cannot send message, WebSocket is not open.");
|
|
96
28
|
}
|
|
29
|
+
return options.websocket.send(message);
|
|
30
|
+
});
|
|
31
|
+
options.websocket.addEventListener("message", async (event) => {
|
|
32
|
+
const message = event.data instanceof Blob ? await readAsBuffer(event.data) : event.data;
|
|
33
|
+
this.peer.message(message);
|
|
97
34
|
});
|
|
98
|
-
|
|
35
|
+
options.websocket.addEventListener("close", () => {
|
|
36
|
+
this.peer.close();
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
async call(request, _options, _path, _input) {
|
|
40
|
+
const response = await this.peer.request(request);
|
|
41
|
+
return { ...response, body: () => Promise.resolve(response.body) };
|
|
99
42
|
}
|
|
100
43
|
}
|
|
101
44
|
|
|
102
|
-
class RPCLink extends
|
|
45
|
+
class RPCLink extends StandardRPCLink {
|
|
103
46
|
constructor(options) {
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
super(codec, transport, options);
|
|
47
|
+
const linkClient = new LinkWebsocketClient(options);
|
|
48
|
+
super(linkClient, { ...options, url: "http://orpc" });
|
|
107
49
|
}
|
|
108
50
|
}
|
|
109
51
|
|
|
110
|
-
export {
|
|
52
|
+
export { LinkWebsocketClient, RPCLink };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,78 +1,197 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
3
|
-
import {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
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.mjs';
|
|
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.mjs';
|
|
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
|
-
|
|
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
|
-
*
|
|
9
|
+
* Use as base path for all procedure, useful when you only want to call a subset of the procedure.
|
|
18
10
|
*/
|
|
19
|
-
|
|
11
|
+
path?: readonly string[];
|
|
20
12
|
}
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
142
|
+
isDefined: false;
|
|
48
143
|
isSuccess: true;
|
|
49
|
-
} | [error: Exclude<TError,
|
|
50
|
-
error: Exclude<TError,
|
|
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
|
-
|
|
147
|
+
isDefined: false;
|
|
53
148
|
isSuccess: false;
|
|
54
|
-
} | [error: Extract<TError,
|
|
55
|
-
error: Extract<TError,
|
|
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
|
-
|
|
152
|
+
isDefined: true;
|
|
58
153
|
isSuccess: false;
|
|
59
154
|
};
|
|
60
155
|
/**
|
|
61
|
-
* Works like try/catch, but
|
|
156
|
+
* Works like try/catch, but can infer error types.
|
|
62
157
|
*
|
|
63
|
-
* @
|
|
64
|
-
*
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
*
|
|
69
|
-
*
|
|
70
|
-
* }
|
|
188
|
+
* @warning If no `onError` or `onFinish` is provided, unhandled rejections will be thrown
|
|
189
|
+
* @return unsubscribe callback
|
|
71
190
|
*/
|
|
72
|
-
declare function
|
|
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
|
|
75
|
-
[K in keyof T]: T[K] extends
|
|
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,
|
|
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
|
|
207
|
+
declare function createSafeClient<T extends NestedClient<any>>(client: T): SafeClient<T>;
|
|
90
208
|
|
|
91
|
-
|
|
92
|
-
|
|
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
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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 {
|
|
121
|
-
export type {
|
|
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 };
|