@orpc/client 0.0.0-next.cc4cb21 → 0.0.0-next.cc8802c

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/README.md +1 -1
  2. package/dist/adapters/fetch/index.d.mts +29 -0
  3. package/dist/adapters/fetch/index.d.ts +29 -0
  4. package/dist/adapters/fetch/index.mjs +35 -0
  5. package/dist/adapters/standard/index.d.mts +148 -0
  6. package/dist/adapters/standard/index.d.ts +148 -0
  7. package/dist/adapters/standard/index.mjs +4 -0
  8. package/dist/index.d.mts +155 -0
  9. package/dist/index.d.ts +155 -0
  10. package/dist/{index.js → index.mjs} +8 -35
  11. package/dist/shared/client.D_CzLDyB.d.mts +42 -0
  12. package/dist/shared/client.D_CzLDyB.d.ts +42 -0
  13. package/dist/shared/client.Df5pd75N.mjs +320 -0
  14. package/dist/{chunk-7F3XVLRJ.js → shared/client.XAn8cDTM.mjs} +13 -28
  15. package/package.json +16 -26
  16. package/dist/chunk-PGCPKPL5.js +0 -213
  17. package/dist/fetch.js +0 -127
  18. package/dist/openapi.js +0 -232
  19. package/dist/rpc.js +0 -10
  20. package/dist/src/adapters/fetch/index.d.ts +0 -3
  21. package/dist/src/adapters/fetch/rpc-link.d.ts +0 -98
  22. package/dist/src/adapters/fetch/types.d.ts +0 -5
  23. package/dist/src/client.d.ts +0 -9
  24. package/dist/src/dynamic-link.d.ts +0 -12
  25. package/dist/src/error.d.ts +0 -106
  26. package/dist/src/event-iterator-state.d.ts +0 -9
  27. package/dist/src/event-iterator.d.ts +0 -12
  28. package/dist/src/index.d.ts +0 -9
  29. package/dist/src/openapi/bracket-notation.d.ts +0 -9
  30. package/dist/src/openapi/index.d.ts +0 -4
  31. package/dist/src/openapi/json-serializer.d.ts +0 -7
  32. package/dist/src/openapi/serializer.d.ts +0 -11
  33. package/dist/src/rpc/index.d.ts +0 -3
  34. package/dist/src/rpc/json-serializer.d.ts +0 -12
  35. package/dist/src/rpc/serializer.d.ts +0 -9
  36. package/dist/src/types.d.ts +0 -29
  37. package/dist/src/utils.d.ts +0 -17
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <div align="center">
2
- <image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 />
2
+ <image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 alt="oRPC logo" />
3
3
  </div>
4
4
 
5
5
  <h1></h1>
@@ -0,0 +1,29 @@
1
+ import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
2
+ import { ToFetchRequestOptions } from '@orpc/standard-server-fetch';
3
+ import { C as ClientContext, a as ClientOptionsOut, b as ClientLink } from '../../shared/client.D_CzLDyB.mjs';
4
+ import { StandardLinkClient, StandardLinkOptions, StandardRPCLinkCodecOptions } from '../standard/index.mjs';
5
+ import '@orpc/shared';
6
+
7
+ interface LinkFetchClientOptions<T extends ClientContext> extends ToFetchRequestOptions {
8
+ fetch?: (request: Request, init: Record<never, never>, options: ClientOptionsOut<T>, path: readonly string[], input: unknown) => Promise<Response>;
9
+ }
10
+ declare class LinkFetchClient<T extends ClientContext> implements StandardLinkClient<T> {
11
+ private readonly fetch;
12
+ private readonly toFetchRequestOptions;
13
+ constructor(options: LinkFetchClientOptions<T>);
14
+ call(request: StandardRequest, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
15
+ }
16
+
17
+ interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardRPCLinkCodecOptions<T>, LinkFetchClientOptions<T> {
18
+ }
19
+ declare class RPCLink<T extends ClientContext> implements ClientLink<T> {
20
+ private readonly standardLink;
21
+ constructor(options: RPCLinkOptions<T>);
22
+ call(path: readonly string[], input: unknown, options: ClientOptionsOut<T>): Promise<unknown>;
23
+ }
24
+
25
+ interface FetchWithContext<TClientContext extends ClientContext> {
26
+ (url: URL, init: RequestInit, options: ClientOptionsOut<TClientContext>, path: readonly string[], input: unknown): Promise<Response>;
27
+ }
28
+
29
+ export { type FetchWithContext, LinkFetchClient, type LinkFetchClientOptions, RPCLink, type RPCLinkOptions };
@@ -0,0 +1,29 @@
1
+ import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
2
+ import { ToFetchRequestOptions } from '@orpc/standard-server-fetch';
3
+ import { C as ClientContext, a as ClientOptionsOut, b as ClientLink } from '../../shared/client.D_CzLDyB.js';
4
+ import { StandardLinkClient, StandardLinkOptions, StandardRPCLinkCodecOptions } from '../standard/index.js';
5
+ import '@orpc/shared';
6
+
7
+ interface LinkFetchClientOptions<T extends ClientContext> extends ToFetchRequestOptions {
8
+ fetch?: (request: Request, init: Record<never, never>, options: ClientOptionsOut<T>, path: readonly string[], input: unknown) => Promise<Response>;
9
+ }
10
+ declare class LinkFetchClient<T extends ClientContext> implements StandardLinkClient<T> {
11
+ private readonly fetch;
12
+ private readonly toFetchRequestOptions;
13
+ constructor(options: LinkFetchClientOptions<T>);
14
+ call(request: StandardRequest, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
15
+ }
16
+
17
+ interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardRPCLinkCodecOptions<T>, LinkFetchClientOptions<T> {
18
+ }
19
+ declare class RPCLink<T extends ClientContext> implements ClientLink<T> {
20
+ private readonly standardLink;
21
+ constructor(options: RPCLinkOptions<T>);
22
+ call(path: readonly string[], input: unknown, options: ClientOptionsOut<T>): Promise<unknown>;
23
+ }
24
+
25
+ interface FetchWithContext<TClientContext extends ClientContext> {
26
+ (url: URL, init: RequestInit, options: ClientOptionsOut<TClientContext>, path: readonly string[], input: unknown): Promise<Response>;
27
+ }
28
+
29
+ export { type FetchWithContext, LinkFetchClient, type LinkFetchClientOptions, RPCLink, type RPCLinkOptions };
@@ -0,0 +1,35 @@
1
+ import { toFetchRequest, toStandardLazyResponse } from '@orpc/standard-server-fetch';
2
+ import { a as StandardRPCLinkCodec, b as RPCSerializer, S as StandardLink } from '../../shared/client.Df5pd75N.mjs';
3
+ import '@orpc/shared';
4
+ import '../../shared/client.XAn8cDTM.mjs';
5
+ import '@orpc/standard-server';
6
+
7
+ class LinkFetchClient {
8
+ fetch;
9
+ toFetchRequestOptions;
10
+ constructor(options) {
11
+ this.fetch = options?.fetch ?? globalThis.fetch.bind(globalThis);
12
+ this.toFetchRequestOptions = options;
13
+ }
14
+ async call(request, options, path, input) {
15
+ const fetchRequest = toFetchRequest(request, this.toFetchRequestOptions);
16
+ const fetchResponse = await this.fetch(fetchRequest, {}, options, path, input);
17
+ const lazyResponse = toStandardLazyResponse(fetchResponse);
18
+ return lazyResponse;
19
+ }
20
+ }
21
+
22
+ class RPCLink {
23
+ standardLink;
24
+ constructor(options) {
25
+ const serializer = new RPCSerializer();
26
+ const linkCodec = new StandardRPCLinkCodec(serializer, options);
27
+ const linkClient = new LinkFetchClient(options);
28
+ this.standardLink = new StandardLink(linkCodec, linkClient, options);
29
+ }
30
+ async call(path, input, options) {
31
+ return this.standardLink.call(path, input, options);
32
+ }
33
+ }
34
+
35
+ export { LinkFetchClient, RPCLink };
@@ -0,0 +1,148 @@
1
+ import { Value, Interceptor, Segment } from '@orpc/shared';
2
+ import { StandardRequest, StandardLazyResponse, StandardHeaders } from '@orpc/standard-server';
3
+ import { C as ClientContext, a as ClientOptionsOut, E as EventIteratorReconnectOptions, b as ClientLink } from '../../shared/client.D_CzLDyB.mjs';
4
+
5
+ interface StandardLinkCodec<T extends ClientContext> {
6
+ encode(path: readonly string[], input: unknown, options: ClientOptionsOut<any>): Promise<StandardRequest>;
7
+ decode(response: StandardLazyResponse, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<unknown>;
8
+ }
9
+ interface StandardLinkClient<T extends ClientContext> {
10
+ call(request: StandardRequest, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
11
+ }
12
+
13
+ declare class InvalidEventIteratorRetryResponse extends Error {
14
+ }
15
+ interface StandardLinkOptions<T extends ClientContext> {
16
+ /**
17
+ * Maximum number of retry attempts for event iterator errors before throwing.
18
+ *
19
+ * @default 5
20
+ */
21
+ eventIteratorMaxRetries?: Value<number, [
22
+ reconnectOptions: EventIteratorReconnectOptions,
23
+ options: ClientOptionsOut<T>,
24
+ path: readonly string[],
25
+ input: unknown
26
+ ]>;
27
+ /**
28
+ * Delay (in ms) before retrying an event iterator call.
29
+ *
30
+ * @default (o) => o.lastRetry ?? (1000 * 2 ** o.retryTimes)
31
+ */
32
+ eventIteratorRetryDelay?: Value<number, [
33
+ reconnectOptions: EventIteratorReconnectOptions,
34
+ options: ClientOptionsOut<T>,
35
+ path: readonly string[],
36
+ input: unknown
37
+ ]>;
38
+ /**
39
+ * Function to determine if an error is retryable.
40
+ *
41
+ * @default true
42
+ */
43
+ eventIteratorShouldRetry?: Value<boolean, [
44
+ reconnectOptions: EventIteratorReconnectOptions,
45
+ options: ClientOptionsOut<T>,
46
+ path: readonly string[],
47
+ input: unknown
48
+ ]>;
49
+ interceptors?: Interceptor<{
50
+ path: readonly string[];
51
+ input: unknown;
52
+ options: ClientOptionsOut<T>;
53
+ }, unknown, unknown>[];
54
+ clientInterceptors?: Interceptor<{
55
+ request: StandardRequest;
56
+ }, StandardLazyResponse, unknown>[];
57
+ }
58
+ declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
59
+ #private;
60
+ readonly codec: StandardLinkCodec<T>;
61
+ readonly sender: StandardLinkClient<T>;
62
+ private readonly eventIteratorMaxRetries;
63
+ private readonly eventIteratorRetryDelay;
64
+ private readonly eventIteratorShouldRetry;
65
+ private readonly interceptors;
66
+ private readonly clientInterceptors;
67
+ constructor(codec: StandardLinkCodec<T>, sender: StandardLinkClient<T>, options: StandardLinkOptions<T>);
68
+ call(path: readonly string[], input: unknown, options: ClientOptionsOut<T>): Promise<unknown>;
69
+ }
70
+
71
+ type RPCJsonSerializedMeta = [
72
+ 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7,
73
+ Segment[]
74
+ ][];
75
+ type RPCJsonSerialized = [json: unknown, meta: RPCJsonSerializedMeta, maps: Segment[][], blobs: Blob[]];
76
+ declare class RPCJsonSerializer {
77
+ serialize(data: unknown, segments?: Segment[], meta?: RPCJsonSerializedMeta, maps?: Segment[][], blobs?: Blob[]): RPCJsonSerialized;
78
+ deserialize(json: unknown, meta: RPCJsonSerializedMeta): unknown;
79
+ deserialize(json: unknown, meta: RPCJsonSerializedMeta, maps: Segment[][], getBlob: (index: number) => Blob): unknown;
80
+ }
81
+
82
+ declare class RPCSerializer {
83
+ #private;
84
+ private readonly jsonSerializer;
85
+ constructor(jsonSerializer?: RPCJsonSerializer);
86
+ serialize(data: unknown): unknown;
87
+ deserialize(data: unknown): unknown;
88
+ }
89
+
90
+ type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
91
+ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
92
+ /**
93
+ * Base url for all requests.
94
+ */
95
+ url: Value<string | URL, [
96
+ options: ClientOptionsOut<T>,
97
+ path: readonly string[],
98
+ input: unknown
99
+ ]>;
100
+ /**
101
+ * The maximum length of the URL.
102
+ *
103
+ * @default 2083
104
+ */
105
+ maxUrlLength?: Value<number, [
106
+ options: ClientOptionsOut<T>,
107
+ path: readonly string[],
108
+ input: unknown
109
+ ]>;
110
+ /**
111
+ * The method used to make the request.
112
+ *
113
+ * @default 'POST'
114
+ */
115
+ method?: Value<HTTPMethod, [
116
+ options: ClientOptionsOut<T>,
117
+ path: readonly string[],
118
+ input: unknown
119
+ ]>;
120
+ /**
121
+ * The method to use when the payload cannot safely pass to the server with method return from method function.
122
+ * GET is not allowed, it's very dangerous.
123
+ *
124
+ * @default 'POST'
125
+ */
126
+ fallbackMethod?: Exclude<HTTPMethod, 'GET'>;
127
+ /**
128
+ * Inject headers to the request.
129
+ */
130
+ headers?: Value<StandardHeaders, [
131
+ options: ClientOptionsOut<T>,
132
+ path: readonly string[],
133
+ input: unknown
134
+ ]>;
135
+ }
136
+ declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
137
+ private readonly serializer;
138
+ private readonly baseUrl;
139
+ private readonly maxUrlLength;
140
+ private readonly fallbackMethod;
141
+ private readonly expectedMethod;
142
+ private readonly headers;
143
+ constructor(serializer: RPCSerializer, options: StandardRPCLinkCodecOptions<T>);
144
+ encode(path: readonly string[], input: unknown, options: ClientOptionsOut<any>): Promise<StandardRequest>;
145
+ decode(response: StandardLazyResponse): Promise<unknown>;
146
+ }
147
+
148
+ export { InvalidEventIteratorRetryResponse, type RPCJsonSerialized, type RPCJsonSerializedMeta, RPCJsonSerializer, RPCSerializer, StandardLink, type StandardLinkClient, type StandardLinkCodec, type StandardLinkOptions, StandardRPCLinkCodec, type StandardRPCLinkCodecOptions };
@@ -0,0 +1,148 @@
1
+ import { Value, Interceptor, Segment } from '@orpc/shared';
2
+ import { StandardRequest, StandardLazyResponse, StandardHeaders } from '@orpc/standard-server';
3
+ import { C as ClientContext, a as ClientOptionsOut, E as EventIteratorReconnectOptions, b as ClientLink } from '../../shared/client.D_CzLDyB.js';
4
+
5
+ interface StandardLinkCodec<T extends ClientContext> {
6
+ encode(path: readonly string[], input: unknown, options: ClientOptionsOut<any>): Promise<StandardRequest>;
7
+ decode(response: StandardLazyResponse, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<unknown>;
8
+ }
9
+ interface StandardLinkClient<T extends ClientContext> {
10
+ call(request: StandardRequest, options: ClientOptionsOut<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
11
+ }
12
+
13
+ declare class InvalidEventIteratorRetryResponse extends Error {
14
+ }
15
+ interface StandardLinkOptions<T extends ClientContext> {
16
+ /**
17
+ * Maximum number of retry attempts for event iterator errors before throwing.
18
+ *
19
+ * @default 5
20
+ */
21
+ eventIteratorMaxRetries?: Value<number, [
22
+ reconnectOptions: EventIteratorReconnectOptions,
23
+ options: ClientOptionsOut<T>,
24
+ path: readonly string[],
25
+ input: unknown
26
+ ]>;
27
+ /**
28
+ * Delay (in ms) before retrying an event iterator call.
29
+ *
30
+ * @default (o) => o.lastRetry ?? (1000 * 2 ** o.retryTimes)
31
+ */
32
+ eventIteratorRetryDelay?: Value<number, [
33
+ reconnectOptions: EventIteratorReconnectOptions,
34
+ options: ClientOptionsOut<T>,
35
+ path: readonly string[],
36
+ input: unknown
37
+ ]>;
38
+ /**
39
+ * Function to determine if an error is retryable.
40
+ *
41
+ * @default true
42
+ */
43
+ eventIteratorShouldRetry?: Value<boolean, [
44
+ reconnectOptions: EventIteratorReconnectOptions,
45
+ options: ClientOptionsOut<T>,
46
+ path: readonly string[],
47
+ input: unknown
48
+ ]>;
49
+ interceptors?: Interceptor<{
50
+ path: readonly string[];
51
+ input: unknown;
52
+ options: ClientOptionsOut<T>;
53
+ }, unknown, unknown>[];
54
+ clientInterceptors?: Interceptor<{
55
+ request: StandardRequest;
56
+ }, StandardLazyResponse, unknown>[];
57
+ }
58
+ declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
59
+ #private;
60
+ readonly codec: StandardLinkCodec<T>;
61
+ readonly sender: StandardLinkClient<T>;
62
+ private readonly eventIteratorMaxRetries;
63
+ private readonly eventIteratorRetryDelay;
64
+ private readonly eventIteratorShouldRetry;
65
+ private readonly interceptors;
66
+ private readonly clientInterceptors;
67
+ constructor(codec: StandardLinkCodec<T>, sender: StandardLinkClient<T>, options: StandardLinkOptions<T>);
68
+ call(path: readonly string[], input: unknown, options: ClientOptionsOut<T>): Promise<unknown>;
69
+ }
70
+
71
+ type RPCJsonSerializedMeta = [
72
+ 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7,
73
+ Segment[]
74
+ ][];
75
+ type RPCJsonSerialized = [json: unknown, meta: RPCJsonSerializedMeta, maps: Segment[][], blobs: Blob[]];
76
+ declare class RPCJsonSerializer {
77
+ serialize(data: unknown, segments?: Segment[], meta?: RPCJsonSerializedMeta, maps?: Segment[][], blobs?: Blob[]): RPCJsonSerialized;
78
+ deserialize(json: unknown, meta: RPCJsonSerializedMeta): unknown;
79
+ deserialize(json: unknown, meta: RPCJsonSerializedMeta, maps: Segment[][], getBlob: (index: number) => Blob): unknown;
80
+ }
81
+
82
+ declare class RPCSerializer {
83
+ #private;
84
+ private readonly jsonSerializer;
85
+ constructor(jsonSerializer?: RPCJsonSerializer);
86
+ serialize(data: unknown): unknown;
87
+ deserialize(data: unknown): unknown;
88
+ }
89
+
90
+ type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
91
+ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
92
+ /**
93
+ * Base url for all requests.
94
+ */
95
+ url: Value<string | URL, [
96
+ options: ClientOptionsOut<T>,
97
+ path: readonly string[],
98
+ input: unknown
99
+ ]>;
100
+ /**
101
+ * The maximum length of the URL.
102
+ *
103
+ * @default 2083
104
+ */
105
+ maxUrlLength?: Value<number, [
106
+ options: ClientOptionsOut<T>,
107
+ path: readonly string[],
108
+ input: unknown
109
+ ]>;
110
+ /**
111
+ * The method used to make the request.
112
+ *
113
+ * @default 'POST'
114
+ */
115
+ method?: Value<HTTPMethod, [
116
+ options: ClientOptionsOut<T>,
117
+ path: readonly string[],
118
+ input: unknown
119
+ ]>;
120
+ /**
121
+ * The method to use when the payload cannot safely pass to the server with method return from method function.
122
+ * GET is not allowed, it's very dangerous.
123
+ *
124
+ * @default 'POST'
125
+ */
126
+ fallbackMethod?: Exclude<HTTPMethod, 'GET'>;
127
+ /**
128
+ * Inject headers to the request.
129
+ */
130
+ headers?: Value<StandardHeaders, [
131
+ options: ClientOptionsOut<T>,
132
+ path: readonly string[],
133
+ input: unknown
134
+ ]>;
135
+ }
136
+ declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
137
+ private readonly serializer;
138
+ private readonly baseUrl;
139
+ private readonly maxUrlLength;
140
+ private readonly fallbackMethod;
141
+ private readonly expectedMethod;
142
+ private readonly headers;
143
+ constructor(serializer: RPCSerializer, options: StandardRPCLinkCodecOptions<T>);
144
+ encode(path: readonly string[], input: unknown, options: ClientOptionsOut<any>): Promise<StandardRequest>;
145
+ decode(response: StandardLazyResponse): Promise<unknown>;
146
+ }
147
+
148
+ export { InvalidEventIteratorRetryResponse, type RPCJsonSerialized, type RPCJsonSerializedMeta, RPCJsonSerializer, RPCSerializer, StandardLink, type StandardLinkClient, type StandardLinkCodec, type StandardLinkOptions, StandardRPCLinkCodec, type StandardRPCLinkCodecOptions };
@@ -0,0 +1,4 @@
1
+ export { I as InvalidEventIteratorRetryResponse, R as RPCJsonSerializer, b as RPCSerializer, S as StandardLink, a as StandardRPCLinkCodec } from '../../shared/client.Df5pd75N.mjs';
2
+ import '@orpc/shared';
3
+ import '../../shared/client.XAn8cDTM.mjs';
4
+ import '@orpc/standard-server';
@@ -0,0 +1,155 @@
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, options?: {
137
+ notifyImmediately?: boolean;
138
+ }): () => void;
139
+
140
+ type SafeResult<TOutput, TError extends Error> = [error: null, data: TOutput, isDefined: false] & {
141
+ error: null;
142
+ data: TOutput;
143
+ isDefined: false;
144
+ } | [error: Exclude<TError, ORPCError<any, any>>, data: undefined, isDefined: false] & {
145
+ error: Exclude<TError, ORPCError<any, any>>;
146
+ data: undefined;
147
+ isDefined: false;
148
+ } | [error: Extract<TError, ORPCError<any, any>>, data: undefined, isDefined: true] & {
149
+ error: Extract<TError, ORPCError<any, any>>;
150
+ data: undefined;
151
+ isDefined: true;
152
+ };
153
+ declare function safe<TOutput, TError extends Error>(promise: ClientPromiseResult<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
154
+
155
+ 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 };