@orpc/client 2.0.0-beta.46 → 2.0.0-beta.48
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 +6 -4
- package/dist/adapters/fetch/index.d.mts +2 -48
- package/dist/adapters/fetch/index.mjs +2 -77
- package/dist/adapters/fetch/rpc-link.d.mts +13 -0
- package/dist/adapters/fetch/rpc-link.mjs +10 -0
- package/dist/adapters/fetch/transport.d.mts +31 -0
- package/dist/adapters/fetch/transport.mjs +65 -0
- package/dist/adapters/message-port/index.d.mts +3 -80
- package/dist/adapters/message-port/index.mjs +3 -101
- package/dist/adapters/message-port/message-port.d.mts +29 -0
- package/dist/adapters/message-port/message-port.mjs +43 -0
- package/dist/adapters/message-port/rpc-link.d.mts +14 -0
- package/dist/adapters/message-port/rpc-link.mjs +10 -0
- package/dist/adapters/message-port/transport.d.mts +35 -0
- package/dist/adapters/message-port/transport.mjs +47 -0
- package/dist/adapters/standard/codec.d.mts +14 -0
- package/dist/adapters/standard/codec.mjs +1 -0
- package/dist/adapters/standard/index.d.mts +5 -60
- package/dist/adapters/standard/index.mjs +4 -6
- package/dist/adapters/standard/link.d.mts +40 -0
- package/dist/adapters/standard/link.mjs +79 -0
- package/dist/adapters/standard/plugin.d.mts +32 -0
- package/dist/adapters/standard/plugin.mjs +16 -0
- package/dist/adapters/standard/rpc-link-codec.d.mts +55 -0
- package/dist/adapters/standard/rpc-link-codec.mjs +104 -0
- package/dist/adapters/standard/transport.d.mts +14 -0
- package/dist/adapters/standard/transport.mjs +1 -0
- package/dist/adapters/websocket/index.d.mts +2 -136
- package/dist/adapters/websocket/index.mjs +2 -131
- package/dist/adapters/websocket/rpc-link.d.mts +13 -0
- package/dist/adapters/websocket/rpc-link.mjs +10 -0
- package/dist/adapters/websocket/transport.d.mts +119 -0
- package/dist/adapters/websocket/transport.mjs +123 -0
- package/dist/async-iterator-object.d.mts +7 -0
- package/dist/async-iterator-object.mjs +30 -0
- package/dist/client-safe.d.mts +16 -0
- package/dist/client-safe.mjs +23 -0
- package/dist/client.d.mts +51 -0
- package/dist/client.mjs +32 -0
- package/dist/consts.d.mts +10 -0
- package/dist/consts.mjs +10 -0
- package/dist/dynamic-link.d.mts +13 -0
- package/dist/dynamic-link.mjs +12 -0
- package/dist/error-utils.d.mts +24 -0
- package/dist/error-utils.mjs +44 -0
- package/dist/error.d.mts +138 -0
- package/dist/error.mjs +105 -0
- package/dist/index.d.mts +42 -137
- package/dist/index.mjs +18 -142
- package/dist/plugins/batch.d.mts +150 -0
- package/dist/plugins/batch.mjs +339 -0
- package/dist/plugins/cookie-jar.d.mts +82 -0
- package/dist/plugins/cookie-jar.mjs +229 -0
- package/dist/plugins/dedupe.d.mts +58 -0
- package/dist/plugins/dedupe.mjs +199 -0
- package/dist/plugins/index.d.mts +28 -420
- package/dist/plugins/index.mjs +17 -971
- package/dist/plugins/request-compression.d.mts +44 -0
- package/dist/plugins/request-compression.mjs +150 -0
- package/dist/plugins/response-compression.d.mts +28 -0
- package/dist/plugins/response-compression.mjs +78 -0
- package/dist/plugins/retry-after.d.mts +41 -0
- package/dist/plugins/retry-after.mjs +71 -0
- package/dist/plugins/retry.d.mts +82 -0
- package/dist/plugins/retry.mjs +127 -0
- package/dist/plugins/timeout.d.mts +25 -0
- package/dist/plugins/timeout.mjs +36 -0
- package/dist/rpc-json-serializer.d.mts +99 -0
- package/dist/rpc-json-serializer.mjs +365 -0
- package/dist/rpc-serializer.d.mts +32 -0
- package/dist/rpc-serializer.mjs +100 -0
- package/dist/types.d.mts +93 -0
- package/dist/types.mjs +1 -0
- package/dist/utils.d.mts +46 -0
- package/dist/utils.mjs +53 -0
- package/package.json +5 -5
- package/dist/adapters/fetch/index.d.ts +0 -48
- package/dist/adapters/message-port/index.d.ts +0 -80
- package/dist/adapters/standard/index.d.ts +0 -60
- package/dist/adapters/websocket/index.d.ts +0 -136
- package/dist/index.d.ts +0 -144
- package/dist/plugins/index.d.ts +0 -420
- package/dist/shared/client.BoHJeq15.d.mts +0 -233
- package/dist/shared/client.BoHJeq15.d.ts +0 -233
- package/dist/shared/client.CKQeJJ2U.mjs +0 -172
- package/dist/shared/client.DqIWeNhQ.d.mts +0 -131
- package/dist/shared/client.DqIWeNhQ.d.ts +0 -131
- package/dist/shared/client.JBJwBhR8.d.ts +0 -90
- package/dist/shared/client.LF04eOvL.mjs +0 -115
- package/dist/shared/client._wG5INmC.mjs +0 -505
- package/dist/shared/client.euYjjcFz.d.mts +0 -90
package/dist/utils.d.mts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { PromiseWithError, ThrowableError } from "@orpc/shared";
|
|
2
|
+
import type { AnyORPCError } from "./error.mjs";
|
|
3
|
+
import type { ClientContext, ClientOptions, ClientRest, FriendlyClientOptions } from "./types.mjs";
|
|
4
|
+
export declare function resolveFriendlyClientOptions<T extends ClientContext>(options: FriendlyClientOptions<T>): ClientOptions<T>;
|
|
5
|
+
export declare function resolveClientRest<
|
|
6
|
+
TClientContext extends ClientContext,
|
|
7
|
+
TInput
|
|
8
|
+
>(rest: ClientRest<TClientContext, TInput>): [input: TInput, options: ClientOptions<TClientContext>];
|
|
9
|
+
export type SafeResult<
|
|
10
|
+
TOutput,
|
|
11
|
+
TError
|
|
12
|
+
> = [error: null, data: TOutput, definedError: null, isSuccess: true] & {
|
|
13
|
+
error: null;
|
|
14
|
+
data: TOutput;
|
|
15
|
+
definedError: null;
|
|
16
|
+
isSuccess: true;
|
|
17
|
+
} | [error: Exclude<TError, AnyORPCError>, data: undefined, definedError: null, isSuccess: false] & {
|
|
18
|
+
error: Exclude<TError, AnyORPCError>;
|
|
19
|
+
data: undefined;
|
|
20
|
+
definedError: null;
|
|
21
|
+
isSuccess: false;
|
|
22
|
+
} | [error: Extract<TError, AnyORPCError>, data: undefined, definedError: Extract<TError, AnyORPCError>, isSuccess: false] & {
|
|
23
|
+
error: Extract<TError, AnyORPCError>;
|
|
24
|
+
data: undefined;
|
|
25
|
+
definedError: Extract<TError, AnyORPCError>;
|
|
26
|
+
isSuccess: false;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Works like try/catch, but help you infer the error type if it is a defined ORPCError.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* const [error, data, definedError, isSuccess] = await safe(client(...))
|
|
34
|
+
* // or const { error, data, definedError, isSuccess } = await safe(client(...))
|
|
35
|
+
*
|
|
36
|
+
* if (definedError) {
|
|
37
|
+
* console.log(definedError) // or error, both are well typed
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @see {@link https://orpc.dev/docs/client/error-handling#using-safe-and-isdefinederror | Client Error Handling - Using safe and isDefinedError}
|
|
42
|
+
*/
|
|
43
|
+
export declare function safe<
|
|
44
|
+
TOutput,
|
|
45
|
+
TError = ThrowableError
|
|
46
|
+
>(promise: PromiseWithError<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
|
package/dist/utils.mjs
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { isDefinedError } from "./error-utils.mjs";
|
|
2
|
+
export function resolveFriendlyClientOptions(options) {
|
|
3
|
+
return {
|
|
4
|
+
...options,
|
|
5
|
+
context: options.context ?? {}
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export function resolveClientRest(rest) {
|
|
9
|
+
return [rest[0], resolveFriendlyClientOptions(rest[1] ?? {})];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export async function safe(promise) {
|
|
13
|
+
try {
|
|
14
|
+
const output = await promise;
|
|
15
|
+
return Object.assign([
|
|
16
|
+
null,
|
|
17
|
+
output,
|
|
18
|
+
null,
|
|
19
|
+
true
|
|
20
|
+
], {
|
|
21
|
+
error: null,
|
|
22
|
+
data: output,
|
|
23
|
+
definedError: null,
|
|
24
|
+
isSuccess: true
|
|
25
|
+
});
|
|
26
|
+
} catch (e) {
|
|
27
|
+
const error = e;
|
|
28
|
+
if (isDefinedError(error)) {
|
|
29
|
+
return Object.assign([
|
|
30
|
+
error,
|
|
31
|
+
undefined,
|
|
32
|
+
error,
|
|
33
|
+
false
|
|
34
|
+
], {
|
|
35
|
+
error,
|
|
36
|
+
data: undefined,
|
|
37
|
+
definedError: error,
|
|
38
|
+
isSuccess: false
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return Object.assign([
|
|
42
|
+
error,
|
|
43
|
+
undefined,
|
|
44
|
+
null,
|
|
45
|
+
false
|
|
46
|
+
], {
|
|
47
|
+
error,
|
|
48
|
+
data: undefined,
|
|
49
|
+
definedError: null,
|
|
50
|
+
isSuccess: false
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/client",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.48",
|
|
5
5
|
"description": "Consume oRPC and OpenAPI APIs with end-to-end type safety over HTTP, WebSocket, or message ports",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": [
|
|
@@ -63,10 +63,10 @@
|
|
|
63
63
|
"dist"
|
|
64
64
|
],
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@orpc/shared": "2.0.0-beta.
|
|
67
|
-
"@standard-server/core": "~0.
|
|
68
|
-
"@standard-server/fetch": "~0.
|
|
69
|
-
"@standard-server/peer": "~0.
|
|
66
|
+
"@orpc/shared": "2.0.0-beta.48",
|
|
67
|
+
"@standard-server/core": "~0.14.0",
|
|
68
|
+
"@standard-server/fetch": "~0.14.0",
|
|
69
|
+
"@standard-server/peer": "~0.14.0"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
72
|
"@types/ws": "^8.18.2",
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { ClientContext, ClientOptions } from '../../index.js';
|
|
2
|
-
import { Value, Promisable } from '@orpc/shared';
|
|
3
|
-
import { StandardRequest, StandardLazyResponse } from '@standard-server/core';
|
|
4
|
-
import { ToFetchBodyOptions } from '@standard-server/fetch';
|
|
5
|
-
import { StandardLinkTransport, StandardLink, StandardLinkOptions } from '../standard/index.js';
|
|
6
|
-
import { RPCLinkCodecOptions } from '../standard/index.js';
|
|
7
|
-
import '../../shared/client.DqIWeNhQ.js';
|
|
8
|
-
|
|
9
|
-
interface FetchLinkTransportOptions<T extends ClientContext> {
|
|
10
|
-
/**
|
|
11
|
-
* The origin to prepend to all request URLs, useful for CORS requests.
|
|
12
|
-
*
|
|
13
|
-
* @example 'https://api.example.com'
|
|
14
|
-
* @example 'http://localhost:3000'
|
|
15
|
-
*/
|
|
16
|
-
origin?: Value<Promisable<`https://${string}` | `http://${string}` | ({} & string) | undefined>, [options: ClientOptions<T>, path: string[]]> | undefined;
|
|
17
|
-
/**
|
|
18
|
-
* Options for how to convert the Standard Request to a Fetch Request, like event stream options, etc.
|
|
19
|
-
*/
|
|
20
|
-
toFetchRequest?: ToFetchBodyOptions | undefined;
|
|
21
|
-
/**
|
|
22
|
-
* Override the default fetch implementation.
|
|
23
|
-
*
|
|
24
|
-
* @default (url, init) => globalThis.fetch(url, init)
|
|
25
|
-
*/
|
|
26
|
-
fetch?(url: string, init: RequestInit, options: ClientOptions<T>, path: string[]): Promise<Response>;
|
|
27
|
-
}
|
|
28
|
-
declare class FetchLinkTransport<T extends ClientContext> implements StandardLinkTransport<T> {
|
|
29
|
-
private readonly origin;
|
|
30
|
-
private readonly fetch;
|
|
31
|
-
private readonly toFetchRequestOptions;
|
|
32
|
-
constructor(options: FetchLinkTransportOptions<T>);
|
|
33
|
-
send(standardRequest: StandardRequest, path: string[], options: ClientOptions<T>): Promise<StandardLazyResponse>;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, FetchLinkTransportOptions<T>, RPCLinkCodecOptions<T> {
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Client link that communicates with an RPC Handler over the Fetch API (HTTP).
|
|
40
|
-
*
|
|
41
|
-
* @see {@link https://orpc.dev/docs/adapters/fetch-api | Fetch API Adapter}
|
|
42
|
-
*/
|
|
43
|
-
declare class RPCLink<T extends ClientContext> extends StandardLink<T> {
|
|
44
|
-
constructor(options: RPCLinkOptions<T>);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export { FetchLinkTransport, RPCLink };
|
|
48
|
-
export type { FetchLinkTransportOptions, RPCLinkOptions };
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { ClientContext, ClientOptions } from '../../index.js';
|
|
2
|
-
import { Value, Promisable } from '@orpc/shared';
|
|
3
|
-
import { StandardRequest, StandardLazyResponse } from '@standard-server/core';
|
|
4
|
-
import { ClientPeer, EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standard-server/peer';
|
|
5
|
-
import { StandardLinkTransport, StandardLink, StandardLinkOptions } from '../standard/index.js';
|
|
6
|
-
import { RPCLinkCodecOptions } from '../standard/index.js';
|
|
7
|
-
import '../../shared/client.DqIWeNhQ.js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* The message port used by electron in main process
|
|
11
|
-
*/
|
|
12
|
-
interface MessagePortMainLike {
|
|
13
|
-
on: <T extends string>(event: T, callback: (event?: {
|
|
14
|
-
data: any;
|
|
15
|
-
}) => void) => void;
|
|
16
|
-
postMessage: (data: any, transfer?: any[]) => void;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* The message port used by browser extension
|
|
20
|
-
*/
|
|
21
|
-
interface BrowserPortLike {
|
|
22
|
-
onMessage: {
|
|
23
|
-
addListener: (callback: (data: any) => void) => void;
|
|
24
|
-
};
|
|
25
|
-
onDisconnect: {
|
|
26
|
-
addListener: (callback: () => void) => void;
|
|
27
|
-
};
|
|
28
|
-
postMessage: (data: any) => void;
|
|
29
|
-
}
|
|
30
|
-
type SupportedMessagePort = Pick<MessagePort, 'addEventListener' | 'postMessage'> | MessagePortMainLike | BrowserPortLike;
|
|
31
|
-
/**
|
|
32
|
-
* Message port can support [The structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm)
|
|
33
|
-
*/
|
|
34
|
-
type SupportedMessagePortData = any;
|
|
35
|
-
declare function postMessagePortMessage(port: SupportedMessagePort, data: SupportedMessagePortData, transfer?: any[]): void;
|
|
36
|
-
declare function onMessagePortMessage(port: SupportedMessagePort, callback: (data: SupportedMessagePortData) => void): void;
|
|
37
|
-
declare function onMessagePortClose(port: SupportedMessagePort, callback: () => void): void;
|
|
38
|
-
|
|
39
|
-
type DecodedRequestMessage = ConstructorParameters<typeof ClientPeer>[0] extends (message: infer TMessage) => unknown ? TMessage : never;
|
|
40
|
-
interface MessagePortLinkTransportOptions<_T extends ClientContext> {
|
|
41
|
-
port: SupportedMessagePort;
|
|
42
|
-
/**
|
|
43
|
-
* By default, oRPC serializes request/response messages to string/binary data before sending over message port.
|
|
44
|
-
* If needed, define this option to utilize full power of [MessagePort: postMessage() method](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort/postMessage),
|
|
45
|
-
* such as transferring ownership of objects to the other side or support unserializable objects like `OffscreenCanvas`.
|
|
46
|
-
*
|
|
47
|
-
* @remarks
|
|
48
|
-
* **Note**: Returning `null` or `undefined` disables this feature.
|
|
49
|
-
* **Warning**: Make sure your message port supports `transfer` before using this feature.
|
|
50
|
-
*/
|
|
51
|
-
experimental_transfer?: Value<Promisable<object[] | null | undefined>, [message: DecodedRequestMessage, port: SupportedMessagePort]> | undefined;
|
|
52
|
-
/**
|
|
53
|
-
* Options for encoding peer messages. such as `prefix` for distinguishing messages on the same channel..
|
|
54
|
-
*/
|
|
55
|
-
encodePeerMessage?: EncodePeerMessageOptions | undefined;
|
|
56
|
-
/**
|
|
57
|
-
* Options for decoding peer messages, such as `prefix` for distinguishing messages on the same channel.
|
|
58
|
-
*/
|
|
59
|
-
decodePeerMessage?: DecodePeerMessageOptions | undefined;
|
|
60
|
-
}
|
|
61
|
-
declare class MessagePortLinkTransport<T extends ClientContext> implements StandardLinkTransport<T> {
|
|
62
|
-
private readonly peer;
|
|
63
|
-
constructor({ port, experimental_transfer, encodePeerMessage: encodePeerMessageOptions, decodePeerMessage: decodePeerMessageOptions }: MessagePortLinkTransportOptions<T>);
|
|
64
|
-
send(standardRequest: StandardRequest, _path: string[], _options: ClientOptions<T>): Promise<StandardLazyResponse>;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, MessagePortLinkTransportOptions<T>, RPCLinkCodecOptions<T> {
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Client link that communicates with an RPC Handler over a Message Port
|
|
71
|
-
* (e.g. workers, iframes, browser extensions, Electron).
|
|
72
|
-
*
|
|
73
|
-
* @see {@link https://orpc.dev/docs/adapters/message-port | Message Port Adapter}
|
|
74
|
-
*/
|
|
75
|
-
declare class RPCLink<T extends ClientContext> extends StandardLink<T> {
|
|
76
|
-
constructor(options: RPCLinkOptions<T>);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export { MessagePortLinkTransport, RPCLink, onMessagePortClose, onMessagePortMessage, postMessagePortMessage };
|
|
80
|
-
export type { BrowserPortLike, MessagePortLinkTransportOptions, MessagePortMainLike, RPCLinkOptions, SupportedMessagePort, SupportedMessagePortData };
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { f as StandardLinkCodec, g as StandardLinkCodecDecodedResponse } from '../../shared/client.JBJwBhR8.js';
|
|
2
|
-
export { a as StandardLink, h as StandardLinkInterceptor, e as StandardLinkInterceptorOptions, b as StandardLinkOptions, c as StandardLinkPlugin, S as StandardLinkTransport, i as StandardLinkTransportInterceptor, d as StandardLinkTransportInterceptorOptions } from '../../shared/client.JBJwBhR8.js';
|
|
3
|
-
import { Value, Promisable, Public } from '@orpc/shared';
|
|
4
|
-
import { StandardUrl, StandardHeaders, StandardRequest, StandardLazyResponse } from '@standard-server/core';
|
|
5
|
-
import { ClientContext, ClientOptions } from '../../index.js';
|
|
6
|
-
import { RPCSerializer } from '../../index.js';
|
|
7
|
-
|
|
8
|
-
interface RPCLinkCodecOptions<T extends ClientContext> {
|
|
9
|
-
/**
|
|
10
|
-
* Base url for all requests (without origin). Should match with handler's prefix.
|
|
11
|
-
*
|
|
12
|
-
* @example '/rpc?base=1'
|
|
13
|
-
*
|
|
14
|
-
* @default '/'
|
|
15
|
-
*/
|
|
16
|
-
url?: Value<Promisable<StandardUrl>, [options: ClientOptions<T>, path: string[], input: unknown]> | undefined;
|
|
17
|
-
/**
|
|
18
|
-
* The maximum length of the URL.
|
|
19
|
-
*
|
|
20
|
-
* If the URL exceeds this length, the codec should use the `fallbackMethod` to send the request with the payload in the body instead of the URL.
|
|
21
|
-
*
|
|
22
|
-
* @default 2083
|
|
23
|
-
*/
|
|
24
|
-
maxUrlLength?: Value<Promisable<number>, [options: ClientOptions<T>, path: string[], input: unknown]> | undefined;
|
|
25
|
-
/**
|
|
26
|
-
* The method used to make the request.
|
|
27
|
-
*
|
|
28
|
-
* @default 'POST'
|
|
29
|
-
*/
|
|
30
|
-
method?: Value<Promisable<'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'QUERY'>, [options: ClientOptions<T>, path: string[], input: unknown]> | undefined;
|
|
31
|
-
/**
|
|
32
|
-
* The method to use when the payload cannot safely pass to the server with method return from method function.
|
|
33
|
-
* GET is not allowed, it's very dangerous.
|
|
34
|
-
*
|
|
35
|
-
* @default 'POST'
|
|
36
|
-
*/
|
|
37
|
-
fallbackMethod?: 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'QUERY' | undefined;
|
|
38
|
-
/**
|
|
39
|
-
* Inject headers to the request.
|
|
40
|
-
*/
|
|
41
|
-
headers?: Value<Promisable<StandardHeaders | Headers>, [options: ClientOptions<T>, path: string[], input: unknown]> | undefined;
|
|
42
|
-
/**
|
|
43
|
-
* Override the default RPC serializer.
|
|
44
|
-
*/
|
|
45
|
-
serializer?: Public<RPCSerializer> | undefined;
|
|
46
|
-
}
|
|
47
|
-
declare class RPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
|
|
48
|
-
private readonly baseUrl;
|
|
49
|
-
private readonly maxUrlLength;
|
|
50
|
-
private readonly fallbackMethod;
|
|
51
|
-
private readonly expectedMethod;
|
|
52
|
-
private readonly headers;
|
|
53
|
-
private readonly serializer;
|
|
54
|
-
constructor(options: RPCLinkCodecOptions<T>);
|
|
55
|
-
encodeInput(input: unknown, path: string[], options: ClientOptions<T>): Promise<StandardRequest>;
|
|
56
|
-
decodeResponse(response: StandardLazyResponse): Promise<StandardLinkCodecDecodedResponse>;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export { RPCLinkCodec, StandardLinkCodec, StandardLinkCodecDecodedResponse };
|
|
60
|
-
export type { RPCLinkCodecOptions };
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { ClientContext, ClientOptions } from '../../index.js';
|
|
2
|
-
import { Promisable } from '@orpc/shared';
|
|
3
|
-
import { StandardRequest, StandardLazyResponse } from '@standard-server/core';
|
|
4
|
-
import { EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standard-server/peer';
|
|
5
|
-
import { StandardLinkTransport, StandardLink, StandardLinkOptions } from '../standard/index.js';
|
|
6
|
-
import { RPCLinkCodecOptions } from '../standard/index.js';
|
|
7
|
-
import '../../shared/client.DqIWeNhQ.js';
|
|
8
|
-
|
|
9
|
-
type WebSocketLike = Pick<WebSocket, 'addEventListener' | 'removeEventListener' | 'send' | 'readyState'>;
|
|
10
|
-
interface WebSocketLinkTransportAttemptInfo {
|
|
11
|
-
/**
|
|
12
|
-
* Total number of connection attempts for this transport's lifetime.
|
|
13
|
-
* Starts at 1 on the first attempt, increments on every subsequent
|
|
14
|
-
* attempt, and never resets.
|
|
15
|
-
*/
|
|
16
|
-
totalAttempt: number;
|
|
17
|
-
/**
|
|
18
|
-
* Attempt number within the current (re)connect cycle.
|
|
19
|
-
* Starts at 1, increments on each consecutive failure, and resets to 1
|
|
20
|
-
* once a connection succeeds or the cycle gives up. Use this for backoff calculations.
|
|
21
|
-
*/
|
|
22
|
-
attempt: number;
|
|
23
|
-
}
|
|
24
|
-
interface WebSocketLinkTransportReconnectOptions {
|
|
25
|
-
/**
|
|
26
|
-
* Whether to automatically reconnect when the connection is lost.
|
|
27
|
-
*
|
|
28
|
-
* @default false
|
|
29
|
-
*/
|
|
30
|
-
enabled: boolean;
|
|
31
|
-
/**
|
|
32
|
-
* Delay before a (re)connect attempt, in milliseconds.
|
|
33
|
-
*
|
|
34
|
-
* @default info => info.attempt === 1 ? 0 : 2_000
|
|
35
|
-
*/
|
|
36
|
-
delay?: ((info: WebSocketLinkTransportAttemptInfo) => number) | undefined;
|
|
37
|
-
/**
|
|
38
|
-
* Maximum number of consecutive failed attempts before giving up.
|
|
39
|
-
* When reached, calls waiting for the connection fail, and the next
|
|
40
|
-
* call starts a new reconnect cycle.
|
|
41
|
-
* Should greater than 1
|
|
42
|
-
*
|
|
43
|
-
* @default Infinity
|
|
44
|
-
*/
|
|
45
|
-
maxAttempt?: number | undefined;
|
|
46
|
-
/**
|
|
47
|
-
* Maximum number of connection attempts over the transport's lifetime,
|
|
48
|
-
* successful ones included (see `totalAttempt`).
|
|
49
|
-
* When reached, calls that need a new connection fail instead of connecting.
|
|
50
|
-
*
|
|
51
|
-
* @default Infinity
|
|
52
|
-
*/
|
|
53
|
-
maxTotalAttempt?: number | undefined;
|
|
54
|
-
/**
|
|
55
|
-
* Whether to proactively reconnect right after the socket closes,
|
|
56
|
-
* rather than waiting for the next call to trigger reconnection.
|
|
57
|
-
* Reduces latency for the next request.
|
|
58
|
-
*
|
|
59
|
-
* @default { enabled: false }
|
|
60
|
-
*/
|
|
61
|
-
onClose?: {
|
|
62
|
-
/**
|
|
63
|
-
* Whether to proactively reconnect right after the socket closes,
|
|
64
|
-
* rather than waiting for the next call to trigger reconnection.
|
|
65
|
-
* Reduces latency for the next request.
|
|
66
|
-
*
|
|
67
|
-
* @default false
|
|
68
|
-
*/
|
|
69
|
-
enabled: boolean;
|
|
70
|
-
/**
|
|
71
|
-
* Delay before reconnecting after the socket closes, in milliseconds.
|
|
72
|
-
*
|
|
73
|
-
* @default 0
|
|
74
|
-
*/
|
|
75
|
-
delay?: number | undefined;
|
|
76
|
-
} | undefined;
|
|
77
|
-
}
|
|
78
|
-
interface WebSocketLinkTransportOptions<_T extends ClientContext> {
|
|
79
|
-
/**
|
|
80
|
-
* Returns a WebSocket instance for peer communication.
|
|
81
|
-
* Can be async for lazy resolution.
|
|
82
|
-
*/
|
|
83
|
-
connect: (info: WebSocketLinkTransportAttemptInfo) => Promisable<WebSocketLike>;
|
|
84
|
-
/**
|
|
85
|
-
* Whether to connect immediately on initialization, instead of waiting
|
|
86
|
-
* for the first call. Reduces latency for the first request.
|
|
87
|
-
*
|
|
88
|
-
* @default false
|
|
89
|
-
*/
|
|
90
|
-
connectOnInit?: boolean | undefined;
|
|
91
|
-
/**
|
|
92
|
-
* Reconnection behavior when the connection is lost.
|
|
93
|
-
*
|
|
94
|
-
* @default { enabled: false }
|
|
95
|
-
*/
|
|
96
|
-
reconnect?: WebSocketLinkTransportReconnectOptions | undefined;
|
|
97
|
-
/**
|
|
98
|
-
* Options for encoding peer messages. such as `prefix` for distinguishing messages on the same channel..
|
|
99
|
-
*/
|
|
100
|
-
encodePeerMessage?: EncodePeerMessageOptions | undefined;
|
|
101
|
-
/**
|
|
102
|
-
* Options for decoding peer messages. such as `prefix` for distinguishing messages on the same channel..
|
|
103
|
-
*/
|
|
104
|
-
decodePeerMessage?: DecodePeerMessageOptions | undefined;
|
|
105
|
-
}
|
|
106
|
-
declare class WebSocketLinkTransport<T extends ClientContext> implements StandardLinkTransport<T> {
|
|
107
|
-
private readonly connect;
|
|
108
|
-
private readonly reconnectEnabled;
|
|
109
|
-
private readonly reconnectDelay;
|
|
110
|
-
private readonly reconnectMaxAttempt;
|
|
111
|
-
private readonly reconnectMaxTotalAttempt;
|
|
112
|
-
private readonly reconnectOnCloseEnabled;
|
|
113
|
-
private readonly reconnectOnCloseDelay;
|
|
114
|
-
private readonly encodePeerMessageOptions;
|
|
115
|
-
private readonly decodePeerMessageOptions;
|
|
116
|
-
constructor(options: WebSocketLinkTransportOptions<T>);
|
|
117
|
-
send(standardRequest: StandardRequest, _path: string[], _options: ClientOptions<T>): Promise<StandardLazyResponse>;
|
|
118
|
-
private totalAttempt;
|
|
119
|
-
private attempt;
|
|
120
|
-
private current;
|
|
121
|
-
private getConnectedPeer;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, WebSocketLinkTransportOptions<T>, RPCLinkCodecOptions<T> {
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Client link that communicates with an RPC Handler over a WebSocket connection.
|
|
128
|
-
*
|
|
129
|
-
* @see {@link https://orpc.dev/docs/adapters/websocket | WebSocket Adapters}
|
|
130
|
-
*/
|
|
131
|
-
declare class RPCLink<T extends ClientContext> extends StandardLink<T> {
|
|
132
|
-
constructor(options: RPCLinkOptions<T>);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export { RPCLink, WebSocketLinkTransport };
|
|
136
|
-
export type { RPCLinkOptions, WebSocketLike, WebSocketLinkTransportAttemptInfo, WebSocketLinkTransportOptions, WebSocketLinkTransportReconnectOptions };
|
package/dist/index.d.ts
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { WrapAsyncIteratorOptions, AsyncIteratorClass, Interceptor, PromiseWithError, ThrowableError, Promisable } from '@orpc/shared';
|
|
2
|
-
export { AsyncCleanupFn, AsyncIteratorClass, AsyncIteratorClassNextFn, PromiseWithError as ClientPromiseResult, 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, O as ORPCErrorCode, g as ORPCErrorJSON, h as ORPCError } from './shared/client.BoHJeq15.js';
|
|
4
|
-
export { i as AnyORPCErrorJSON, j as COMMON_ERROR_STATUS_MAP, F as FriendlyClientOptions, k as InferClientBodyInputs, l as InferClientBodyOutputs, m as InferClientErrors, n as InferClientInputs, o as InferClientOutputs, M as MalformedResponseError, p as MalformedResponseErrorOptions, N as NestedClient, q as ORPCErrorOptions, R as ResponseError, r as ResponseErrorOptions } from './shared/client.BoHJeq15.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.DqIWeNhQ.js';
|
|
6
|
-
export { ErrorEvent, EventMeta, StandardBody, StandardBodyHint, StandardHeaders, StandardLazyRequest, StandardLazyResponse, StandardMethod, StandardRequest, StandardResponse, StandardUrl, getEventMeta, unwrapEvent, withEventMeta } from '@standard-server/core';
|
|
7
|
-
|
|
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> {
|
|
16
|
-
/**
|
|
17
|
-
* Interceptors that wrap the entire client call lifecycle.
|
|
18
|
-
*/
|
|
19
|
-
interceptors?: ORPCClientInterceptor<TClientContext, TInput, TOutput, TError>[] | undefined;
|
|
20
|
-
}
|
|
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) | undefined;
|
|
23
|
-
};
|
|
24
|
-
interface ORPCClientOptions<T extends AnyNestedClient> {
|
|
25
|
-
/**
|
|
26
|
-
* Use as base path for all procedure, useful when you only want to call a subset of the procedure.
|
|
27
|
-
*/
|
|
28
|
-
path?: string[] | undefined;
|
|
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>>[] | undefined;
|
|
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> | undefined;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Creates a fully typed oRPC client from a link.
|
|
42
|
-
* The returned client mirrors the shape of your router or contract,
|
|
43
|
-
* so calling a procedure is as simple as calling a function.
|
|
44
|
-
*
|
|
45
|
-
* @see {@link https://orpc.dev/docs/client/client-side | Client-Side Clients}
|
|
46
|
-
*/
|
|
47
|
-
declare function createORPCClient<T extends AnyNestedClient>(link: ClientLink<InferClientContext<T>>, { path, ...options }?: NoInfer<ORPCClientOptions<T>>): T;
|
|
48
|
-
|
|
49
|
-
declare function resolveClientRest<TClientContext extends ClientContext, TInput>(rest: ClientRest<TClientContext, TInput>): [input: TInput, options: ClientOptions<TClientContext>];
|
|
50
|
-
type SafeResult<TOutput, TError> = [error: null, data: TOutput, definedError: null, isSuccess: true] & {
|
|
51
|
-
error: null;
|
|
52
|
-
data: TOutput;
|
|
53
|
-
definedError: null;
|
|
54
|
-
isSuccess: true;
|
|
55
|
-
} | [error: Exclude<TError, AnyORPCError>, data: undefined, definedError: null, isSuccess: false] & {
|
|
56
|
-
error: Exclude<TError, AnyORPCError>;
|
|
57
|
-
data: undefined;
|
|
58
|
-
definedError: null;
|
|
59
|
-
isSuccess: false;
|
|
60
|
-
} | [error: Extract<TError, AnyORPCError>, data: undefined, definedError: Extract<TError, AnyORPCError>, isSuccess: false] & {
|
|
61
|
-
error: Extract<TError, AnyORPCError>;
|
|
62
|
-
data: undefined;
|
|
63
|
-
definedError: Extract<TError, AnyORPCError>;
|
|
64
|
-
isSuccess: false;
|
|
65
|
-
};
|
|
66
|
-
/**
|
|
67
|
-
* Works like try/catch, but help you infer the error type if it is a defined ORPCError.
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* ```ts
|
|
71
|
-
* const [error, data, definedError, isSuccess] = await safe(client(...))
|
|
72
|
-
* // or const { error, data, definedError, isSuccess } = await safe(client(...))
|
|
73
|
-
*
|
|
74
|
-
* if (definedError) {
|
|
75
|
-
* console.log(definedError) // or error, both are well typed
|
|
76
|
-
* }
|
|
77
|
-
* ```
|
|
78
|
-
*
|
|
79
|
-
* @see {@link https://orpc.dev/docs/client/error-handling#using-safe-and-isdefinederror | Client Error Handling - Using safe and isDefinedError}
|
|
80
|
-
*/
|
|
81
|
-
declare function safe<TOutput, TError = ThrowableError>(promise: PromiseWithError<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
|
|
82
|
-
|
|
83
|
-
type SafeClient<T extends AnyNestedClient> = T extends Client<infer UContext, infer UInput, infer UOutput, infer UError> ? (...rest: ClientRest<UContext, UInput>) => Promise<SafeResult<UOutput, UError>> : {
|
|
84
|
-
[K in keyof T]: T[K] extends AnyNestedClient ? SafeClient<T[K]> : never;
|
|
85
|
-
};
|
|
86
|
-
/**
|
|
87
|
-
* Create a safe client that automatically wraps all procedure calls with the `safe` util.
|
|
88
|
-
*
|
|
89
|
-
* @example
|
|
90
|
-
* ```ts
|
|
91
|
-
* const safeClient = createSafeClient(client)
|
|
92
|
-
* const { error, data, definedError, isSuccess } = await safeClient.doSomething({ id: '123' })
|
|
93
|
-
* // or const [error, data, definedError, isSuccess] = await safeClient.doSomething({ id: '123' })
|
|
94
|
-
* ```
|
|
95
|
-
*
|
|
96
|
-
* @see {@link https://orpc.dev/docs/client/error-handling#safe-client | Client Error Handling - Safe Client}
|
|
97
|
-
*/
|
|
98
|
-
declare function createSafeClient<T extends AnyNestedClient>(client: T): SafeClient<T>;
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Property names that should resolve to the underlying value instead of
|
|
102
|
-
* continuing recursive proxy traversal.
|
|
103
|
-
*
|
|
104
|
-
* These properties are commonly accessed automatically by JavaScript runtimes,
|
|
105
|
-
* language features, or third-party libraries. Returning another recursive
|
|
106
|
-
* proxy for them can cause unexpected behavior, compatibility issues, or
|
|
107
|
-
* infinite proxy chains.
|
|
108
|
-
*/
|
|
109
|
-
declare const RECURSIVE_CLIENT_UNWRAP_KEYS: Set<PropertyKey>;
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* DynamicLink provides a way to dynamically resolve and delegate calls to other ClientLinks
|
|
113
|
-
* based on the request path, input, and context.
|
|
114
|
-
*
|
|
115
|
-
* @see {@link https://orpc.dev/docs/client/dynamic-link | DynamicLink}
|
|
116
|
-
*/
|
|
117
|
-
declare class DynamicLink<TClientContext extends ClientContext> implements ClientLink<TClientContext> {
|
|
118
|
-
private readonly linkResolver;
|
|
119
|
-
constructor(linkResolver: (options: ClientOptions<TClientContext>, path: string[], input: unknown) => Promisable<ClientLink<TClientContext>>);
|
|
120
|
-
call(path: string[], input: unknown, options: ClientOptions<TClientContext>): Promise<unknown>;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Checks if an error is an `ORPCError` that matches a definition in the procedure's `.errors` map,
|
|
125
|
-
* narrowing it so `code` and `data` are fully typed.
|
|
126
|
-
*
|
|
127
|
-
* @see {@link https://orpc.dev/docs/client/error-handling#using-safe-and-isdefinederror | Client Error Handling - Using safe and isDefinedError}
|
|
128
|
-
*/
|
|
129
|
-
declare function isDefinedError<T>(error: T): error is Extract<T, AnyORPCError>;
|
|
130
|
-
declare function toORPCError<T>(error: T): Extract<T, AnyORPCError> | ORPCError<'INTERNAL_SERVER_ERROR', undefined>;
|
|
131
|
-
declare function isORPCErrorJson(json: unknown): json is ORPCErrorJSON<ORPCErrorCode, unknown>;
|
|
132
|
-
declare function createORPCErrorFromJson<TCode extends ORPCErrorCode, TData>(json: ORPCErrorJSON<TCode, TData>, options?: ErrorOptions): ORPCError<TCode, TData>;
|
|
133
|
-
/**
|
|
134
|
-
* Clones an `ORPCError` while preserving its prototype chain, so instances of
|
|
135
|
-
* `ORPCError` subclasses remain `instanceof` their class.
|
|
136
|
-
*
|
|
137
|
-
* Limitation: subclass constructors are not re-run, so private fields
|
|
138
|
-
* (`#field`) are not carried over and subclass members that read them
|
|
139
|
-
* will throw on the clone.
|
|
140
|
-
*/
|
|
141
|
-
declare function cloneORPCError<T extends AnyORPCError>(error: T): T;
|
|
142
|
-
|
|
143
|
-
export { AnyNestedClient, AnyORPCError, Client, ClientContext, ClientLink, ClientOptions, ClientRest, DynamicLink, InferClientContext, InferClientError, InferClientError as InferClientErrorUnion, ORPCError, ORPCErrorCode, ORPCErrorJSON, RECURSIVE_CLIENT_UNWRAP_KEYS, cloneORPCError, createORPCClient, createORPCErrorFromJson, createSafeClient, isDefinedError, isORPCErrorJson, resolveClientRest, safe, toORPCError, wrapAsyncIteratorPreservingEventMeta };
|
|
144
|
-
export type { ORPCClientInterceptor, ORPCClientInterceptorOptions, ORPCClientOptions, ORPCClientScoped, ORPCClientScopedOptions, SafeClient, SafeResult };
|