@orpc/client 0.43.0 → 0.44.0
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 +1 -1
- package/dist/adapters/fetch/index.d.mts +103 -0
- package/dist/{src/adapters/fetch/rpc-link.d.ts → adapters/fetch/index.d.ts} +15 -10
- package/dist/{fetch.js → adapters/fetch/index.mjs} +15 -22
- package/dist/adapters/standard/index.d.mts +22 -0
- package/dist/adapters/standard/index.d.ts +22 -0
- package/dist/adapters/standard/index.mjs +4 -0
- package/dist/index.d.mts +153 -0
- package/dist/index.d.ts +153 -0
- package/dist/{index.js → index.mjs} +8 -35
- package/dist/{chunk-4HZVK3GJ.js → shared/client.DHJ8vRIG.mjs} +9 -29
- package/dist/shared/client.D_CzLDyB.d.mts +42 -0
- package/dist/shared/client.D_CzLDyB.d.ts +42 -0
- package/dist/{chunk-X34KXUAJ.js → shared/client.Ly4zGQrc.mjs} +12 -28
- package/package.json +15 -25
- package/dist/openapi.js +0 -231
- package/dist/rpc.js +0 -10
- package/dist/src/adapters/fetch/index.d.ts +0 -3
- package/dist/src/adapters/fetch/types.d.ts +0 -5
- package/dist/src/client.d.ts +0 -9
- package/dist/src/dynamic-link.d.ts +0 -12
- package/dist/src/error.d.ts +0 -106
- package/dist/src/event-iterator-state.d.ts +0 -9
- package/dist/src/event-iterator.d.ts +0 -12
- package/dist/src/index.d.ts +0 -9
- package/dist/src/openapi/bracket-notation.d.ts +0 -9
- package/dist/src/openapi/index.d.ts +0 -4
- package/dist/src/openapi/json-serializer.d.ts +0 -7
- package/dist/src/openapi/serializer.d.ts +0 -11
- package/dist/src/rpc/index.d.ts +0 -3
- package/dist/src/rpc/json-serializer.d.ts +0 -12
- package/dist/src/rpc/serializer.d.ts +0 -9
- package/dist/src/types.d.ts +0 -29
- package/dist/src/utils.d.ts +0 -17
package/README.md
CHANGED
@@ -0,0 +1,103 @@
|
|
1
|
+
import { Value } from '@orpc/shared';
|
2
|
+
import { ToFetchBodyOptions } from '@orpc/standard-server-fetch';
|
3
|
+
import { C as ClientContext, a as ClientOptionsOut, E as EventIteratorReconnectOptions, b as ClientLink } from '../../shared/client.D_CzLDyB.mjs';
|
4
|
+
import { RPCSerializer } from '../standard/index.mjs';
|
5
|
+
|
6
|
+
interface FetchWithContext<TClientContext extends ClientContext> {
|
7
|
+
(url: URL, init: RequestInit, options: ClientOptionsOut<TClientContext>, path: readonly string[], input: unknown): Promise<Response>;
|
8
|
+
}
|
9
|
+
|
10
|
+
type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
11
|
+
declare class InvalidEventSourceRetryResponse extends Error {
|
12
|
+
}
|
13
|
+
interface RPCLinkOptions<TClientContext extends ClientContext> extends ToFetchBodyOptions {
|
14
|
+
/**
|
15
|
+
* Base url for all requests.
|
16
|
+
*/
|
17
|
+
url: string;
|
18
|
+
/**
|
19
|
+
* The maximum length of the URL.
|
20
|
+
*
|
21
|
+
* @default 2083
|
22
|
+
*/
|
23
|
+
maxUrlLength?: number;
|
24
|
+
/**
|
25
|
+
* The method used to make the request.
|
26
|
+
*
|
27
|
+
* @default 'POST'
|
28
|
+
*/
|
29
|
+
method?: Value<HTTPMethod, [
|
30
|
+
options: ClientOptionsOut<TClientContext>,
|
31
|
+
path: readonly string[],
|
32
|
+
input: unknown
|
33
|
+
]>;
|
34
|
+
/**
|
35
|
+
* The method to use when the payload cannot safely pass to the server with method return from method function.
|
36
|
+
* GET is not allowed, it's very dangerous.
|
37
|
+
*
|
38
|
+
* @default 'POST'
|
39
|
+
*/
|
40
|
+
fallbackMethod?: Exclude<HTTPMethod, 'GET'>;
|
41
|
+
/**
|
42
|
+
* Inject headers to the request.
|
43
|
+
*/
|
44
|
+
headers?: Value<[string, string][] | Record<string, string> | Headers, [
|
45
|
+
options: ClientOptionsOut<TClientContext>,
|
46
|
+
path: readonly string[],
|
47
|
+
input: unknown
|
48
|
+
]>;
|
49
|
+
/**
|
50
|
+
* Custom fetch implementation.
|
51
|
+
*
|
52
|
+
* @default globalThis.fetch.bind(globalThis)
|
53
|
+
*/
|
54
|
+
fetch?: FetchWithContext<TClientContext>;
|
55
|
+
rpcSerializer?: RPCSerializer;
|
56
|
+
/**
|
57
|
+
* Maximum number of retry attempts for EventSource errors before throwing.
|
58
|
+
*
|
59
|
+
* @default 5
|
60
|
+
*/
|
61
|
+
eventSourceMaxNumberOfRetries?: number;
|
62
|
+
/**
|
63
|
+
* Delay (in ms) before retrying an EventSource call.
|
64
|
+
*
|
65
|
+
* @default ({retryTimes, lastRetry}) => lastRetry ?? (1000 * 2 ** retryTimes)
|
66
|
+
*/
|
67
|
+
eventSourceRetryDelay?: Value<number, [
|
68
|
+
reconnectOptions: EventIteratorReconnectOptions,
|
69
|
+
options: ClientOptionsOut<TClientContext>,
|
70
|
+
path: readonly string[],
|
71
|
+
input: unknown
|
72
|
+
]>;
|
73
|
+
/**
|
74
|
+
* Function to determine if an error is retryable.
|
75
|
+
*
|
76
|
+
* @default true
|
77
|
+
*/
|
78
|
+
eventSourceRetry?: Value<boolean, [
|
79
|
+
reconnectOptions: EventIteratorReconnectOptions,
|
80
|
+
options: ClientOptionsOut<TClientContext>,
|
81
|
+
path: readonly string[],
|
82
|
+
input: unknown
|
83
|
+
]>;
|
84
|
+
}
|
85
|
+
declare class RPCLink<TClientContext extends ClientContext> implements ClientLink<TClientContext> {
|
86
|
+
private readonly fetch;
|
87
|
+
private readonly rpcSerializer;
|
88
|
+
private readonly maxUrlLength;
|
89
|
+
private readonly fallbackMethod;
|
90
|
+
private readonly method;
|
91
|
+
private readonly headers;
|
92
|
+
private readonly url;
|
93
|
+
private readonly eventSourceMaxNumberOfRetries;
|
94
|
+
private readonly eventSourceRetryDelay;
|
95
|
+
private readonly eventSourceRetry;
|
96
|
+
private readonly toFetchBodyOptions;
|
97
|
+
constructor(options: RPCLinkOptions<TClientContext>);
|
98
|
+
call(path: readonly string[], input: unknown, options: ClientOptionsOut<TClientContext>): Promise<unknown>;
|
99
|
+
private performCall;
|
100
|
+
private encodeRequest;
|
101
|
+
}
|
102
|
+
|
103
|
+
export { type FetchWithContext, InvalidEventSourceRetryResponse, RPCLink, type RPCLinkOptions };
|
@@ -1,12 +1,16 @@
|
|
1
|
-
import
|
2
|
-
import
|
3
|
-
import
|
4
|
-
import {
|
5
|
-
|
1
|
+
import { Value } from '@orpc/shared';
|
2
|
+
import { ToFetchBodyOptions } from '@orpc/standard-server-fetch';
|
3
|
+
import { C as ClientContext, a as ClientOptionsOut, E as EventIteratorReconnectOptions, b as ClientLink } from '../../shared/client.D_CzLDyB.js';
|
4
|
+
import { RPCSerializer } from '../standard/index.js';
|
5
|
+
|
6
|
+
interface FetchWithContext<TClientContext extends ClientContext> {
|
7
|
+
(url: URL, init: RequestInit, options: ClientOptionsOut<TClientContext>, path: readonly string[], input: unknown): Promise<Response>;
|
8
|
+
}
|
9
|
+
|
6
10
|
type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
7
|
-
|
11
|
+
declare class InvalidEventSourceRetryResponse extends Error {
|
8
12
|
}
|
9
|
-
|
13
|
+
interface RPCLinkOptions<TClientContext extends ClientContext> extends ToFetchBodyOptions {
|
10
14
|
/**
|
11
15
|
* Base url for all requests.
|
12
16
|
*/
|
@@ -78,7 +82,7 @@ export interface RPCLinkOptions<TClientContext extends ClientContext> {
|
|
78
82
|
input: unknown
|
79
83
|
]>;
|
80
84
|
}
|
81
|
-
|
85
|
+
declare class RPCLink<TClientContext extends ClientContext> implements ClientLink<TClientContext> {
|
82
86
|
private readonly fetch;
|
83
87
|
private readonly rpcSerializer;
|
84
88
|
private readonly maxUrlLength;
|
@@ -89,10 +93,11 @@ export declare class RPCLink<TClientContext extends ClientContext> implements Cl
|
|
89
93
|
private readonly eventSourceMaxNumberOfRetries;
|
90
94
|
private readonly eventSourceRetryDelay;
|
91
95
|
private readonly eventSourceRetry;
|
96
|
+
private readonly toFetchBodyOptions;
|
92
97
|
constructor(options: RPCLinkOptions<TClientContext>);
|
93
98
|
call(path: readonly string[], input: unknown, options: ClientOptionsOut<TClientContext>): Promise<unknown>;
|
94
99
|
private performCall;
|
95
100
|
private encodeRequest;
|
96
101
|
}
|
97
|
-
|
98
|
-
|
102
|
+
|
103
|
+
export { type FetchWithContext, InvalidEventSourceRetryResponse, RPCLink, type RPCLinkOptions };
|
@@ -1,18 +1,12 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
} from
|
4
|
-
import {
|
5
|
-
|
6
|
-
createAutoRetryEventIterator
|
7
|
-
} from "./chunk-X34KXUAJ.js";
|
1
|
+
import { isAsyncIteratorObject, value, trim, stringifyJSON } from '@orpc/shared';
|
2
|
+
import { toFetchBody, toStandardBody } from '@orpc/standard-server-fetch';
|
3
|
+
import { c as createAutoRetryEventIterator, O as ORPCError } from '../../shared/client.Ly4zGQrc.mjs';
|
4
|
+
import { a as RPCSerializer } from '../../shared/client.DHJ8vRIG.mjs';
|
5
|
+
import '@orpc/standard-server';
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
import { toFetchBody, toStandardBody } from "@orpc/standard-server-fetch";
|
13
|
-
var InvalidEventSourceRetryResponse = class extends Error {
|
14
|
-
};
|
15
|
-
var RPCLink = class {
|
7
|
+
class InvalidEventSourceRetryResponse extends Error {
|
8
|
+
}
|
9
|
+
class RPCLink {
|
16
10
|
fetch;
|
17
11
|
rpcSerializer;
|
18
12
|
maxUrlLength;
|
@@ -23,6 +17,7 @@ var RPCLink = class {
|
|
23
17
|
eventSourceMaxNumberOfRetries;
|
24
18
|
eventSourceRetryDelay;
|
25
19
|
eventSourceRetry;
|
20
|
+
toFetchBodyOptions;
|
26
21
|
constructor(options) {
|
27
22
|
this.fetch = options.fetch ?? globalThis.fetch.bind(globalThis);
|
28
23
|
this.rpcSerializer = options.rpcSerializer ?? new RPCSerializer();
|
@@ -34,6 +29,7 @@ var RPCLink = class {
|
|
34
29
|
this.headers = options.headers ?? {};
|
35
30
|
this.eventSourceRetry = options.eventSourceRetry ?? true;
|
36
31
|
this.eventSourceRetryDelay = options.eventSourceRetryDelay ?? (({ retryTimes, lastRetry }) => lastRetry ?? 1e3 * 2 ** retryTimes);
|
32
|
+
this.toFetchBodyOptions = options;
|
37
33
|
}
|
38
34
|
async call(path, input, options) {
|
39
35
|
const output = await this.performCall(path, input, options);
|
@@ -59,7 +55,7 @@ var RPCLink = class {
|
|
59
55
|
}
|
60
56
|
async performCall(path, input, options) {
|
61
57
|
const encoded = await this.encodeRequest(path, input, options);
|
62
|
-
const fetchBody = toFetchBody(encoded.body, encoded.headers);
|
58
|
+
const fetchBody = toFetchBody(encoded.body, encoded.headers, this.toFetchBodyOptions);
|
63
59
|
if (options.lastEventId !== void 0) {
|
64
60
|
encoded.headers.set("last-event-id", options.lastEventId);
|
65
61
|
}
|
@@ -103,7 +99,7 @@ var RPCLink = class {
|
|
103
99
|
const serialized = this.rpcSerializer.serialize(input);
|
104
100
|
if (expectedMethod === "GET" && !(serialized instanceof FormData) && !(serialized instanceof Blob) && !isAsyncIteratorObject(serialized)) {
|
105
101
|
const getUrl = new URL(url);
|
106
|
-
getUrl.searchParams.append("data",
|
102
|
+
getUrl.searchParams.append("data", stringifyJSON(serialized) ?? "");
|
107
103
|
if (getUrl.toString().length <= this.maxUrlLength) {
|
108
104
|
return {
|
109
105
|
body: void 0,
|
@@ -120,9 +116,6 @@ var RPCLink = class {
|
|
120
116
|
body: serialized
|
121
117
|
};
|
122
118
|
}
|
123
|
-
}
|
124
|
-
|
125
|
-
|
126
|
-
RPCLink
|
127
|
-
};
|
128
|
-
//# sourceMappingURL=fetch.js.map
|
119
|
+
}
|
120
|
+
|
121
|
+
export { InvalidEventSourceRetryResponse, RPCLink };
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { Segment } from '@orpc/shared';
|
2
|
+
|
3
|
+
type RPCJsonSerializedMeta = [
|
4
|
+
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7,
|
5
|
+
Segment[]
|
6
|
+
][];
|
7
|
+
type RPCJsonSerialized = [json: unknown, meta: RPCJsonSerializedMeta, maps: Segment[][], blobs: Blob[]];
|
8
|
+
declare class RPCJsonSerializer {
|
9
|
+
serialize(data: unknown, segments?: Segment[], meta?: RPCJsonSerializedMeta, maps?: Segment[][], blobs?: Blob[]): RPCJsonSerialized;
|
10
|
+
deserialize(json: unknown, meta: RPCJsonSerializedMeta): unknown;
|
11
|
+
deserialize(json: unknown, meta: RPCJsonSerializedMeta, maps: Segment[][], getBlob: (index: number) => Blob): unknown;
|
12
|
+
}
|
13
|
+
|
14
|
+
declare class RPCSerializer {
|
15
|
+
#private;
|
16
|
+
private readonly jsonSerializer;
|
17
|
+
constructor(jsonSerializer?: RPCJsonSerializer);
|
18
|
+
serialize(data: unknown): unknown;
|
19
|
+
deserialize(data: unknown): unknown;
|
20
|
+
}
|
21
|
+
|
22
|
+
export { type RPCJsonSerialized, type RPCJsonSerializedMeta, RPCJsonSerializer, RPCSerializer };
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { Segment } from '@orpc/shared';
|
2
|
+
|
3
|
+
type RPCJsonSerializedMeta = [
|
4
|
+
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7,
|
5
|
+
Segment[]
|
6
|
+
][];
|
7
|
+
type RPCJsonSerialized = [json: unknown, meta: RPCJsonSerializedMeta, maps: Segment[][], blobs: Blob[]];
|
8
|
+
declare class RPCJsonSerializer {
|
9
|
+
serialize(data: unknown, segments?: Segment[], meta?: RPCJsonSerializedMeta, maps?: Segment[][], blobs?: Blob[]): RPCJsonSerialized;
|
10
|
+
deserialize(json: unknown, meta: RPCJsonSerializedMeta): unknown;
|
11
|
+
deserialize(json: unknown, meta: RPCJsonSerializedMeta, maps: Segment[][], getBlob: (index: number) => Blob): unknown;
|
12
|
+
}
|
13
|
+
|
14
|
+
declare class RPCSerializer {
|
15
|
+
#private;
|
16
|
+
private readonly jsonSerializer;
|
17
|
+
constructor(jsonSerializer?: RPCJsonSerializer);
|
18
|
+
serialize(data: unknown): unknown;
|
19
|
+
deserialize(data: unknown): unknown;
|
20
|
+
}
|
21
|
+
|
22
|
+
export { type RPCJsonSerialized, type RPCJsonSerializedMeta, RPCJsonSerializer, RPCSerializer };
|
package/dist/index.d.mts
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
import { N as NestedClient, b as ClientLink, I as InferClientContext, C as ClientContext, a as ClientOptionsOut, c as ClientPromiseResult } from './shared/client.D_CzLDyB.mjs';
|
2
|
+
export { g as Client, e as ClientOptions, f as ClientRest, E as EventIteratorReconnectOptions, d as createAutoRetryEventIterator, m as mapEventIterator } from './shared/client.D_CzLDyB.mjs';
|
3
|
+
import { Promisable, MaybeOptionalOptions } from '@orpc/shared';
|
4
|
+
export { ErrorEvent } from '@orpc/standard-server';
|
5
|
+
|
6
|
+
interface createORPCClientOptions {
|
7
|
+
/**
|
8
|
+
* Use as base path for all procedure, useful when you only want to call a subset of the procedure.
|
9
|
+
*/
|
10
|
+
path?: string[];
|
11
|
+
}
|
12
|
+
declare function createORPCClient<T extends NestedClient<any>>(link: ClientLink<InferClientContext<T>>, options?: createORPCClientOptions): T;
|
13
|
+
|
14
|
+
/**
|
15
|
+
* DynamicLink provides a way to dynamically resolve and delegate calls to other ClientLinks
|
16
|
+
* based on the request path, input, and context.
|
17
|
+
*/
|
18
|
+
declare class DynamicLink<TClientContext extends ClientContext> implements ClientLink<TClientContext> {
|
19
|
+
private readonly linkResolver;
|
20
|
+
constructor(linkResolver: (options: ClientOptionsOut<TClientContext>, path: readonly string[], input: unknown) => Promisable<ClientLink<TClientContext>>);
|
21
|
+
call(path: readonly string[], input: unknown, options: ClientOptionsOut<TClientContext>): Promise<unknown>;
|
22
|
+
}
|
23
|
+
|
24
|
+
declare const COMMON_ORPC_ERROR_DEFS: {
|
25
|
+
readonly BAD_REQUEST: {
|
26
|
+
readonly status: 400;
|
27
|
+
readonly message: "Bad Request";
|
28
|
+
};
|
29
|
+
readonly UNAUTHORIZED: {
|
30
|
+
readonly status: 401;
|
31
|
+
readonly message: "Unauthorized";
|
32
|
+
};
|
33
|
+
readonly FORBIDDEN: {
|
34
|
+
readonly status: 403;
|
35
|
+
readonly message: "Forbidden";
|
36
|
+
};
|
37
|
+
readonly NOT_FOUND: {
|
38
|
+
readonly status: 404;
|
39
|
+
readonly message: "Not Found";
|
40
|
+
};
|
41
|
+
readonly METHOD_NOT_SUPPORTED: {
|
42
|
+
readonly status: 405;
|
43
|
+
readonly message: "Method Not Supported";
|
44
|
+
};
|
45
|
+
readonly NOT_ACCEPTABLE: {
|
46
|
+
readonly status: 406;
|
47
|
+
readonly message: "Not Acceptable";
|
48
|
+
};
|
49
|
+
readonly TIMEOUT: {
|
50
|
+
readonly status: 408;
|
51
|
+
readonly message: "Request Timeout";
|
52
|
+
};
|
53
|
+
readonly CONFLICT: {
|
54
|
+
readonly status: 409;
|
55
|
+
readonly message: "Conflict";
|
56
|
+
};
|
57
|
+
readonly PRECONDITION_FAILED: {
|
58
|
+
readonly status: 412;
|
59
|
+
readonly message: "Precondition Failed";
|
60
|
+
};
|
61
|
+
readonly PAYLOAD_TOO_LARGE: {
|
62
|
+
readonly status: 413;
|
63
|
+
readonly message: "Payload Too Large";
|
64
|
+
};
|
65
|
+
readonly UNSUPPORTED_MEDIA_TYPE: {
|
66
|
+
readonly status: 415;
|
67
|
+
readonly message: "Unsupported Media Type";
|
68
|
+
};
|
69
|
+
readonly UNPROCESSABLE_CONTENT: {
|
70
|
+
readonly status: 422;
|
71
|
+
readonly message: "Unprocessable Content";
|
72
|
+
};
|
73
|
+
readonly TOO_MANY_REQUESTS: {
|
74
|
+
readonly status: 429;
|
75
|
+
readonly message: "Too Many Requests";
|
76
|
+
};
|
77
|
+
readonly CLIENT_CLOSED_REQUEST: {
|
78
|
+
readonly status: 499;
|
79
|
+
readonly message: "Client Closed Request";
|
80
|
+
};
|
81
|
+
readonly INTERNAL_SERVER_ERROR: {
|
82
|
+
readonly status: 500;
|
83
|
+
readonly message: "Internal Server Error";
|
84
|
+
};
|
85
|
+
readonly NOT_IMPLEMENTED: {
|
86
|
+
readonly status: 501;
|
87
|
+
readonly message: "Not Implemented";
|
88
|
+
};
|
89
|
+
readonly BAD_GATEWAY: {
|
90
|
+
readonly status: 502;
|
91
|
+
readonly message: "Bad Gateway";
|
92
|
+
};
|
93
|
+
readonly SERVICE_UNAVAILABLE: {
|
94
|
+
readonly status: 503;
|
95
|
+
readonly message: "Service Unavailable";
|
96
|
+
};
|
97
|
+
readonly GATEWAY_TIMEOUT: {
|
98
|
+
readonly status: 504;
|
99
|
+
readonly message: "Gateway Timeout";
|
100
|
+
};
|
101
|
+
};
|
102
|
+
type CommonORPCErrorCode = keyof typeof COMMON_ORPC_ERROR_DEFS;
|
103
|
+
type ORPCErrorCode = CommonORPCErrorCode | (string & {});
|
104
|
+
declare function fallbackORPCErrorStatus(code: ORPCErrorCode, status: number | undefined): number;
|
105
|
+
declare function fallbackORPCErrorMessage(code: ORPCErrorCode, message: string | undefined): string;
|
106
|
+
type ORPCErrorOptions<TData> = ErrorOptions & {
|
107
|
+
defined?: boolean;
|
108
|
+
status?: number;
|
109
|
+
message?: string;
|
110
|
+
} & (undefined extends TData ? {
|
111
|
+
data?: TData;
|
112
|
+
} : {
|
113
|
+
data: TData;
|
114
|
+
});
|
115
|
+
declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error {
|
116
|
+
readonly defined: boolean;
|
117
|
+
readonly code: TCode;
|
118
|
+
readonly status: number;
|
119
|
+
readonly data: TData;
|
120
|
+
constructor(code: TCode, ...[options]: MaybeOptionalOptions<ORPCErrorOptions<TData>>);
|
121
|
+
toJSON(): ORPCErrorJSON<TCode, TData>;
|
122
|
+
static fromJSON<TCode extends ORPCErrorCode, TData>(json: ORPCErrorJSON<TCode, TData>, options?: ErrorOptions): ORPCError<TCode, TData>;
|
123
|
+
static isValidJSON(json: unknown): json is ORPCErrorJSON<ORPCErrorCode, unknown>;
|
124
|
+
}
|
125
|
+
type ORPCErrorJSON<TCode extends string, TData> = Pick<ORPCError<TCode, TData>, 'defined' | 'code' | 'status' | 'message' | 'data'>;
|
126
|
+
declare function isDefinedError<T>(error: T): error is Extract<T, ORPCError<any, any>>;
|
127
|
+
declare function toORPCError(error: unknown): ORPCError<any, any>;
|
128
|
+
|
129
|
+
type ConnectionStatus = 'reconnecting' | 'connected' | 'closed';
|
130
|
+
interface EventIteratorState {
|
131
|
+
status: ConnectionStatus;
|
132
|
+
listeners: Array<(newStatus: ConnectionStatus) => void>;
|
133
|
+
}
|
134
|
+
declare function registerEventIteratorState(iterator: AsyncIteratorObject<unknown, unknown, void>, state: EventIteratorState): void;
|
135
|
+
declare function updateEventIteratorStatus(state: EventIteratorState, status: ConnectionStatus): void;
|
136
|
+
declare function onEventIteratorStatusChange(iterator: AsyncIteratorObject<unknown, unknown, void>, callback: (status: ConnectionStatus) => void, notifyImmediately?: boolean): () => void;
|
137
|
+
|
138
|
+
type SafeResult<TOutput, TError extends Error> = [error: null, data: TOutput, isDefined: false] & {
|
139
|
+
error: null;
|
140
|
+
data: TOutput;
|
141
|
+
isDefined: false;
|
142
|
+
} | [error: Exclude<TError, ORPCError<any, any>>, data: undefined, isDefined: false] & {
|
143
|
+
error: Exclude<TError, ORPCError<any, any>>;
|
144
|
+
data: undefined;
|
145
|
+
isDefined: false;
|
146
|
+
} | [error: Extract<TError, ORPCError<any, any>>, data: undefined, isDefined: true] & {
|
147
|
+
error: Extract<TError, ORPCError<any, any>>;
|
148
|
+
data: undefined;
|
149
|
+
isDefined: true;
|
150
|
+
};
|
151
|
+
declare function safe<TOutput, TError extends Error>(promise: ClientPromiseResult<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
|
152
|
+
|
153
|
+
export { COMMON_ORPC_ERROR_DEFS, ClientContext, ClientLink, ClientOptionsOut, ClientPromiseResult, type CommonORPCErrorCode, type ConnectionStatus, DynamicLink, type EventIteratorState, InferClientContext, NestedClient, ORPCError, type ORPCErrorCode, type ORPCErrorJSON, type ORPCErrorOptions, type SafeResult, createORPCClient, type createORPCClientOptions, fallbackORPCErrorMessage, fallbackORPCErrorStatus, isDefinedError, onEventIteratorStatusChange, registerEventIteratorState, safe, toORPCError, updateEventIteratorStatus };
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
import { N as NestedClient, b as ClientLink, I as InferClientContext, C as ClientContext, a as ClientOptionsOut, c as ClientPromiseResult } from './shared/client.D_CzLDyB.js';
|
2
|
+
export { g as Client, e as ClientOptions, f as ClientRest, E as EventIteratorReconnectOptions, d as createAutoRetryEventIterator, m as mapEventIterator } from './shared/client.D_CzLDyB.js';
|
3
|
+
import { Promisable, MaybeOptionalOptions } from '@orpc/shared';
|
4
|
+
export { ErrorEvent } from '@orpc/standard-server';
|
5
|
+
|
6
|
+
interface createORPCClientOptions {
|
7
|
+
/**
|
8
|
+
* Use as base path for all procedure, useful when you only want to call a subset of the procedure.
|
9
|
+
*/
|
10
|
+
path?: string[];
|
11
|
+
}
|
12
|
+
declare function createORPCClient<T extends NestedClient<any>>(link: ClientLink<InferClientContext<T>>, options?: createORPCClientOptions): T;
|
13
|
+
|
14
|
+
/**
|
15
|
+
* DynamicLink provides a way to dynamically resolve and delegate calls to other ClientLinks
|
16
|
+
* based on the request path, input, and context.
|
17
|
+
*/
|
18
|
+
declare class DynamicLink<TClientContext extends ClientContext> implements ClientLink<TClientContext> {
|
19
|
+
private readonly linkResolver;
|
20
|
+
constructor(linkResolver: (options: ClientOptionsOut<TClientContext>, path: readonly string[], input: unknown) => Promisable<ClientLink<TClientContext>>);
|
21
|
+
call(path: readonly string[], input: unknown, options: ClientOptionsOut<TClientContext>): Promise<unknown>;
|
22
|
+
}
|
23
|
+
|
24
|
+
declare const COMMON_ORPC_ERROR_DEFS: {
|
25
|
+
readonly BAD_REQUEST: {
|
26
|
+
readonly status: 400;
|
27
|
+
readonly message: "Bad Request";
|
28
|
+
};
|
29
|
+
readonly UNAUTHORIZED: {
|
30
|
+
readonly status: 401;
|
31
|
+
readonly message: "Unauthorized";
|
32
|
+
};
|
33
|
+
readonly FORBIDDEN: {
|
34
|
+
readonly status: 403;
|
35
|
+
readonly message: "Forbidden";
|
36
|
+
};
|
37
|
+
readonly NOT_FOUND: {
|
38
|
+
readonly status: 404;
|
39
|
+
readonly message: "Not Found";
|
40
|
+
};
|
41
|
+
readonly METHOD_NOT_SUPPORTED: {
|
42
|
+
readonly status: 405;
|
43
|
+
readonly message: "Method Not Supported";
|
44
|
+
};
|
45
|
+
readonly NOT_ACCEPTABLE: {
|
46
|
+
readonly status: 406;
|
47
|
+
readonly message: "Not Acceptable";
|
48
|
+
};
|
49
|
+
readonly TIMEOUT: {
|
50
|
+
readonly status: 408;
|
51
|
+
readonly message: "Request Timeout";
|
52
|
+
};
|
53
|
+
readonly CONFLICT: {
|
54
|
+
readonly status: 409;
|
55
|
+
readonly message: "Conflict";
|
56
|
+
};
|
57
|
+
readonly PRECONDITION_FAILED: {
|
58
|
+
readonly status: 412;
|
59
|
+
readonly message: "Precondition Failed";
|
60
|
+
};
|
61
|
+
readonly PAYLOAD_TOO_LARGE: {
|
62
|
+
readonly status: 413;
|
63
|
+
readonly message: "Payload Too Large";
|
64
|
+
};
|
65
|
+
readonly UNSUPPORTED_MEDIA_TYPE: {
|
66
|
+
readonly status: 415;
|
67
|
+
readonly message: "Unsupported Media Type";
|
68
|
+
};
|
69
|
+
readonly UNPROCESSABLE_CONTENT: {
|
70
|
+
readonly status: 422;
|
71
|
+
readonly message: "Unprocessable Content";
|
72
|
+
};
|
73
|
+
readonly TOO_MANY_REQUESTS: {
|
74
|
+
readonly status: 429;
|
75
|
+
readonly message: "Too Many Requests";
|
76
|
+
};
|
77
|
+
readonly CLIENT_CLOSED_REQUEST: {
|
78
|
+
readonly status: 499;
|
79
|
+
readonly message: "Client Closed Request";
|
80
|
+
};
|
81
|
+
readonly INTERNAL_SERVER_ERROR: {
|
82
|
+
readonly status: 500;
|
83
|
+
readonly message: "Internal Server Error";
|
84
|
+
};
|
85
|
+
readonly NOT_IMPLEMENTED: {
|
86
|
+
readonly status: 501;
|
87
|
+
readonly message: "Not Implemented";
|
88
|
+
};
|
89
|
+
readonly BAD_GATEWAY: {
|
90
|
+
readonly status: 502;
|
91
|
+
readonly message: "Bad Gateway";
|
92
|
+
};
|
93
|
+
readonly SERVICE_UNAVAILABLE: {
|
94
|
+
readonly status: 503;
|
95
|
+
readonly message: "Service Unavailable";
|
96
|
+
};
|
97
|
+
readonly GATEWAY_TIMEOUT: {
|
98
|
+
readonly status: 504;
|
99
|
+
readonly message: "Gateway Timeout";
|
100
|
+
};
|
101
|
+
};
|
102
|
+
type CommonORPCErrorCode = keyof typeof COMMON_ORPC_ERROR_DEFS;
|
103
|
+
type ORPCErrorCode = CommonORPCErrorCode | (string & {});
|
104
|
+
declare function fallbackORPCErrorStatus(code: ORPCErrorCode, status: number | undefined): number;
|
105
|
+
declare function fallbackORPCErrorMessage(code: ORPCErrorCode, message: string | undefined): string;
|
106
|
+
type ORPCErrorOptions<TData> = ErrorOptions & {
|
107
|
+
defined?: boolean;
|
108
|
+
status?: number;
|
109
|
+
message?: string;
|
110
|
+
} & (undefined extends TData ? {
|
111
|
+
data?: TData;
|
112
|
+
} : {
|
113
|
+
data: TData;
|
114
|
+
});
|
115
|
+
declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error {
|
116
|
+
readonly defined: boolean;
|
117
|
+
readonly code: TCode;
|
118
|
+
readonly status: number;
|
119
|
+
readonly data: TData;
|
120
|
+
constructor(code: TCode, ...[options]: MaybeOptionalOptions<ORPCErrorOptions<TData>>);
|
121
|
+
toJSON(): ORPCErrorJSON<TCode, TData>;
|
122
|
+
static fromJSON<TCode extends ORPCErrorCode, TData>(json: ORPCErrorJSON<TCode, TData>, options?: ErrorOptions): ORPCError<TCode, TData>;
|
123
|
+
static isValidJSON(json: unknown): json is ORPCErrorJSON<ORPCErrorCode, unknown>;
|
124
|
+
}
|
125
|
+
type ORPCErrorJSON<TCode extends string, TData> = Pick<ORPCError<TCode, TData>, 'defined' | 'code' | 'status' | 'message' | 'data'>;
|
126
|
+
declare function isDefinedError<T>(error: T): error is Extract<T, ORPCError<any, any>>;
|
127
|
+
declare function toORPCError(error: unknown): ORPCError<any, any>;
|
128
|
+
|
129
|
+
type ConnectionStatus = 'reconnecting' | 'connected' | 'closed';
|
130
|
+
interface EventIteratorState {
|
131
|
+
status: ConnectionStatus;
|
132
|
+
listeners: Array<(newStatus: ConnectionStatus) => void>;
|
133
|
+
}
|
134
|
+
declare function registerEventIteratorState(iterator: AsyncIteratorObject<unknown, unknown, void>, state: EventIteratorState): void;
|
135
|
+
declare function updateEventIteratorStatus(state: EventIteratorState, status: ConnectionStatus): void;
|
136
|
+
declare function onEventIteratorStatusChange(iterator: AsyncIteratorObject<unknown, unknown, void>, callback: (status: ConnectionStatus) => void, notifyImmediately?: boolean): () => void;
|
137
|
+
|
138
|
+
type SafeResult<TOutput, TError extends Error> = [error: null, data: TOutput, isDefined: false] & {
|
139
|
+
error: null;
|
140
|
+
data: TOutput;
|
141
|
+
isDefined: false;
|
142
|
+
} | [error: Exclude<TError, ORPCError<any, any>>, data: undefined, isDefined: false] & {
|
143
|
+
error: Exclude<TError, ORPCError<any, any>>;
|
144
|
+
data: undefined;
|
145
|
+
isDefined: false;
|
146
|
+
} | [error: Extract<TError, ORPCError<any, any>>, data: undefined, isDefined: true] & {
|
147
|
+
error: Extract<TError, ORPCError<any, any>>;
|
148
|
+
data: undefined;
|
149
|
+
isDefined: true;
|
150
|
+
};
|
151
|
+
declare function safe<TOutput, TError extends Error>(promise: ClientPromiseResult<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
|
152
|
+
|
153
|
+
export { COMMON_ORPC_ERROR_DEFS, ClientContext, ClientLink, ClientOptionsOut, ClientPromiseResult, type CommonORPCErrorCode, type ConnectionStatus, DynamicLink, type EventIteratorState, InferClientContext, NestedClient, ORPCError, type ORPCErrorCode, type ORPCErrorJSON, type ORPCErrorOptions, type SafeResult, createORPCClient, type createORPCClientOptions, fallbackORPCErrorMessage, fallbackORPCErrorStatus, isDefinedError, onEventIteratorStatusChange, registerEventIteratorState, safe, toORPCError, updateEventIteratorStatus };
|
@@ -1,18 +1,8 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
fallbackORPCErrorMessage,
|
6
|
-
fallbackORPCErrorStatus,
|
7
|
-
isDefinedError,
|
8
|
-
mapEventIterator,
|
9
|
-
onEventIteratorStatusChange,
|
10
|
-
registerEventIteratorState,
|
11
|
-
toORPCError,
|
12
|
-
updateEventIteratorStatus
|
13
|
-
} from "./chunk-X34KXUAJ.js";
|
1
|
+
import { i as isDefinedError } from './shared/client.Ly4zGQrc.mjs';
|
2
|
+
export { C as COMMON_ORPC_ERROR_DEFS, O as ORPCError, c as createAutoRetryEventIterator, a as fallbackORPCErrorMessage, f as fallbackORPCErrorStatus, m as mapEventIterator, o as onEventIteratorStatusChange, r as registerEventIteratorState, t as toORPCError, u as updateEventIteratorStatus } from './shared/client.Ly4zGQrc.mjs';
|
3
|
+
export { ErrorEvent } from '@orpc/standard-server';
|
4
|
+
import '@orpc/shared';
|
14
5
|
|
15
|
-
// src/client.ts
|
16
6
|
function createORPCClient(link, options) {
|
17
7
|
const path = options?.path ?? [];
|
18
8
|
const procedureClient = async (...[input, options2]) => {
|
@@ -37,8 +27,7 @@ function createORPCClient(link, options) {
|
|
37
27
|
return recursive;
|
38
28
|
}
|
39
29
|
|
40
|
-
|
41
|
-
var DynamicLink = class {
|
30
|
+
class DynamicLink {
|
42
31
|
constructor(linkResolver) {
|
43
32
|
this.linkResolver = linkResolver;
|
44
33
|
}
|
@@ -47,9 +36,8 @@ var DynamicLink = class {
|
|
47
36
|
const output = await resolvedLink.call(path, input, options);
|
48
37
|
return output;
|
49
38
|
}
|
50
|
-
}
|
39
|
+
}
|
51
40
|
|
52
|
-
// src/utils.ts
|
53
41
|
async function safe(promise) {
|
54
42
|
try {
|
55
43
|
const output = await promise;
|
@@ -71,20 +59,5 @@ async function safe(promise) {
|
|
71
59
|
);
|
72
60
|
}
|
73
61
|
}
|
74
|
-
|
75
|
-
|
76
|
-
DynamicLink,
|
77
|
-
ORPCError,
|
78
|
-
createAutoRetryEventIterator,
|
79
|
-
createORPCClient,
|
80
|
-
fallbackORPCErrorMessage,
|
81
|
-
fallbackORPCErrorStatus,
|
82
|
-
isDefinedError,
|
83
|
-
mapEventIterator,
|
84
|
-
onEventIteratorStatusChange,
|
85
|
-
registerEventIteratorState,
|
86
|
-
safe,
|
87
|
-
toORPCError,
|
88
|
-
updateEventIteratorStatus
|
89
|
-
};
|
90
|
-
//# sourceMappingURL=index.js.map
|
62
|
+
|
63
|
+
export { DynamicLink, createORPCClient, isDefinedError, safe };
|