@orpc/client 0.0.0-next.b2e67f7 → 0.0.0-next.b2ee3f3
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 +41 -28
- package/dist/adapters/fetch/index.d.mts +46 -0
- package/dist/adapters/fetch/index.d.ts +46 -0
- package/dist/adapters/fetch/index.mjs +46 -0
- package/dist/adapters/message-port/index.d.mts +80 -0
- package/dist/adapters/message-port/index.d.ts +80 -0
- package/dist/adapters/message-port/index.mjs +87 -0
- package/dist/adapters/standard/index.d.mts +11 -0
- package/dist/adapters/standard/index.d.ts +11 -0
- package/dist/adapters/standard/index.mjs +6 -0
- package/dist/adapters/websocket/index.d.mts +29 -0
- package/dist/adapters/websocket/index.d.ts +29 -0
- package/dist/adapters/websocket/index.mjs +47 -0
- package/dist/index.d.mts +230 -0
- package/dist/index.d.ts +230 -0
- package/dist/index.mjs +112 -0
- package/dist/plugins/index.d.mts +249 -0
- package/dist/plugins/index.d.ts +249 -0
- package/dist/plugins/index.mjs +485 -0
- package/dist/shared/client.2jUAqzYU.d.ts +45 -0
- package/dist/shared/client.B3pNRBih.d.ts +91 -0
- package/dist/shared/client.BFAVy68H.d.mts +91 -0
- package/dist/shared/client.BLtwTQUg.mjs +40 -0
- package/dist/shared/client.CpCa3si8.d.mts +45 -0
- package/dist/shared/client.D19SrzQ-.mjs +398 -0
- package/dist/shared/client.DfCB32pI.mjs +171 -0
- package/dist/shared/client.i2uoJbEp.d.mts +83 -0
- package/dist/shared/client.i2uoJbEp.d.ts +83 -0
- package/package.json +32 -27
- package/dist/chunk-4HZVK3GJ.js +0 -212
- package/dist/chunk-X34KXUAJ.js +0 -281
- package/dist/fetch.js +0 -128
- package/dist/index.js +0 -90
- 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/rpc-link.d.ts +0 -98
- 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
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { resolveMaybeOptionalOptions, getConstructor, isObject } from '@orpc/shared';
|
|
2
|
+
|
|
3
|
+
const ORPC_CLIENT_PACKAGE_NAME = "@orpc/client";
|
|
4
|
+
const ORPC_CLIENT_PACKAGE_VERSION = "0.0.0-next.b2ee3f3";
|
|
5
|
+
|
|
6
|
+
const COMMON_ORPC_ERROR_DEFS = {
|
|
7
|
+
BAD_REQUEST: {
|
|
8
|
+
status: 400,
|
|
9
|
+
message: "Bad Request"
|
|
10
|
+
},
|
|
11
|
+
UNAUTHORIZED: {
|
|
12
|
+
status: 401,
|
|
13
|
+
message: "Unauthorized"
|
|
14
|
+
},
|
|
15
|
+
FORBIDDEN: {
|
|
16
|
+
status: 403,
|
|
17
|
+
message: "Forbidden"
|
|
18
|
+
},
|
|
19
|
+
NOT_FOUND: {
|
|
20
|
+
status: 404,
|
|
21
|
+
message: "Not Found"
|
|
22
|
+
},
|
|
23
|
+
METHOD_NOT_SUPPORTED: {
|
|
24
|
+
status: 405,
|
|
25
|
+
message: "Method Not Supported"
|
|
26
|
+
},
|
|
27
|
+
NOT_ACCEPTABLE: {
|
|
28
|
+
status: 406,
|
|
29
|
+
message: "Not Acceptable"
|
|
30
|
+
},
|
|
31
|
+
TIMEOUT: {
|
|
32
|
+
status: 408,
|
|
33
|
+
message: "Request Timeout"
|
|
34
|
+
},
|
|
35
|
+
CONFLICT: {
|
|
36
|
+
status: 409,
|
|
37
|
+
message: "Conflict"
|
|
38
|
+
},
|
|
39
|
+
PRECONDITION_FAILED: {
|
|
40
|
+
status: 412,
|
|
41
|
+
message: "Precondition Failed"
|
|
42
|
+
},
|
|
43
|
+
PAYLOAD_TOO_LARGE: {
|
|
44
|
+
status: 413,
|
|
45
|
+
message: "Payload Too Large"
|
|
46
|
+
},
|
|
47
|
+
UNSUPPORTED_MEDIA_TYPE: {
|
|
48
|
+
status: 415,
|
|
49
|
+
message: "Unsupported Media Type"
|
|
50
|
+
},
|
|
51
|
+
UNPROCESSABLE_CONTENT: {
|
|
52
|
+
status: 422,
|
|
53
|
+
message: "Unprocessable Content"
|
|
54
|
+
},
|
|
55
|
+
TOO_MANY_REQUESTS: {
|
|
56
|
+
status: 429,
|
|
57
|
+
message: "Too Many Requests"
|
|
58
|
+
},
|
|
59
|
+
CLIENT_CLOSED_REQUEST: {
|
|
60
|
+
status: 499,
|
|
61
|
+
message: "Client Closed Request"
|
|
62
|
+
},
|
|
63
|
+
INTERNAL_SERVER_ERROR: {
|
|
64
|
+
status: 500,
|
|
65
|
+
message: "Internal Server Error"
|
|
66
|
+
},
|
|
67
|
+
NOT_IMPLEMENTED: {
|
|
68
|
+
status: 501,
|
|
69
|
+
message: "Not Implemented"
|
|
70
|
+
},
|
|
71
|
+
BAD_GATEWAY: {
|
|
72
|
+
status: 502,
|
|
73
|
+
message: "Bad Gateway"
|
|
74
|
+
},
|
|
75
|
+
SERVICE_UNAVAILABLE: {
|
|
76
|
+
status: 503,
|
|
77
|
+
message: "Service Unavailable"
|
|
78
|
+
},
|
|
79
|
+
GATEWAY_TIMEOUT: {
|
|
80
|
+
status: 504,
|
|
81
|
+
message: "Gateway Timeout"
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
function fallbackORPCErrorStatus(code, status) {
|
|
85
|
+
return status ?? COMMON_ORPC_ERROR_DEFS[code]?.status ?? 500;
|
|
86
|
+
}
|
|
87
|
+
function fallbackORPCErrorMessage(code, message) {
|
|
88
|
+
return message || COMMON_ORPC_ERROR_DEFS[code]?.message || code;
|
|
89
|
+
}
|
|
90
|
+
const GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL = Symbol.for(`__${ORPC_CLIENT_PACKAGE_NAME}@${ORPC_CLIENT_PACKAGE_VERSION}/error/ORPC_ERROR_CONSTRUCTORS__`);
|
|
91
|
+
void (globalThis[GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL] ??= /* @__PURE__ */ new WeakSet());
|
|
92
|
+
const globalORPCErrorConstructors = globalThis[GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL];
|
|
93
|
+
class ORPCError extends Error {
|
|
94
|
+
defined;
|
|
95
|
+
code;
|
|
96
|
+
status;
|
|
97
|
+
data;
|
|
98
|
+
constructor(code, ...rest) {
|
|
99
|
+
const options = resolveMaybeOptionalOptions(rest);
|
|
100
|
+
if (options.status !== void 0 && !isORPCErrorStatus(options.status)) {
|
|
101
|
+
throw new Error("[ORPCError] Invalid error status code.");
|
|
102
|
+
}
|
|
103
|
+
const message = fallbackORPCErrorMessage(code, options.message);
|
|
104
|
+
super(message, options);
|
|
105
|
+
this.code = code;
|
|
106
|
+
this.status = fallbackORPCErrorStatus(code, options.status);
|
|
107
|
+
this.defined = options.defined ?? false;
|
|
108
|
+
this.data = options.data;
|
|
109
|
+
}
|
|
110
|
+
toJSON() {
|
|
111
|
+
return {
|
|
112
|
+
defined: this.defined,
|
|
113
|
+
code: this.code,
|
|
114
|
+
status: this.status,
|
|
115
|
+
message: this.message,
|
|
116
|
+
data: this.data
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Workaround for Next.js where different contexts use separate
|
|
121
|
+
* dependency graphs, causing multiple ORPCError constructors existing and breaking
|
|
122
|
+
* `instanceof` checks across contexts.
|
|
123
|
+
*
|
|
124
|
+
* This is particularly problematic with "Optimized SSR", where orpc-client
|
|
125
|
+
* executes in one context but is invoked from another. When an error is thrown
|
|
126
|
+
* in the execution context, `instanceof ORPCError` checks fail in the
|
|
127
|
+
* invocation context due to separate class constructors.
|
|
128
|
+
*
|
|
129
|
+
* @todo Remove this and related code if Next.js resolves the multiple dependency graph issue.
|
|
130
|
+
*/
|
|
131
|
+
static [Symbol.hasInstance](instance) {
|
|
132
|
+
if (globalORPCErrorConstructors.has(this)) {
|
|
133
|
+
const constructor = getConstructor(instance);
|
|
134
|
+
if (constructor && globalORPCErrorConstructors.has(constructor)) {
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return super[Symbol.hasInstance](instance);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
globalORPCErrorConstructors.add(ORPCError);
|
|
142
|
+
function isDefinedError(error) {
|
|
143
|
+
return error instanceof ORPCError && error.defined;
|
|
144
|
+
}
|
|
145
|
+
function toORPCError(error) {
|
|
146
|
+
return error instanceof ORPCError ? error : new ORPCError("INTERNAL_SERVER_ERROR", {
|
|
147
|
+
message: "Internal server error",
|
|
148
|
+
cause: error
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
function isORPCErrorStatus(status) {
|
|
152
|
+
return status < 200 || status >= 400;
|
|
153
|
+
}
|
|
154
|
+
function isORPCErrorJson(json) {
|
|
155
|
+
if (!isObject(json)) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
const validKeys = ["defined", "code", "status", "message", "data"];
|
|
159
|
+
if (Object.keys(json).some((k) => !validKeys.includes(k))) {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
return "defined" in json && typeof json.defined === "boolean" && "code" in json && typeof json.code === "string" && "status" in json && typeof json.status === "number" && isORPCErrorStatus(json.status) && "message" in json && typeof json.message === "string";
|
|
163
|
+
}
|
|
164
|
+
function createORPCErrorFromJson(json, options = {}) {
|
|
165
|
+
return new ORPCError(json.code, {
|
|
166
|
+
...options,
|
|
167
|
+
...json
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export { COMMON_ORPC_ERROR_DEFS as C, ORPC_CLIENT_PACKAGE_NAME as O, ORPC_CLIENT_PACKAGE_VERSION as a, fallbackORPCErrorMessage as b, ORPCError as c, isORPCErrorStatus as d, isORPCErrorJson as e, fallbackORPCErrorStatus as f, createORPCErrorFromJson as g, isDefinedError as i, toORPCError as t };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { PromiseWithError } from '@orpc/shared';
|
|
2
|
+
|
|
3
|
+
type HTTPPath = `/${string}`;
|
|
4
|
+
type HTTPMethod = 'HEAD' | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
5
|
+
type ClientContext = Record<PropertyKey, any>;
|
|
6
|
+
interface ClientOptions<T extends ClientContext> {
|
|
7
|
+
signal?: AbortSignal;
|
|
8
|
+
lastEventId?: string | undefined;
|
|
9
|
+
context: T;
|
|
10
|
+
}
|
|
11
|
+
type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
|
12
|
+
context?: T;
|
|
13
|
+
} : {
|
|
14
|
+
context: T;
|
|
15
|
+
});
|
|
16
|
+
type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>];
|
|
17
|
+
type ClientPromiseResult<TOutput, TError> = PromiseWithError<TOutput, TError>;
|
|
18
|
+
interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> {
|
|
19
|
+
(...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
|
|
20
|
+
}
|
|
21
|
+
type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
|
|
22
|
+
[k: string]: NestedClient<TClientContext>;
|
|
23
|
+
};
|
|
24
|
+
type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
|
|
25
|
+
interface ClientLink<TClientContext extends ClientContext> {
|
|
26
|
+
call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Recursively infers the **input types** from a client.
|
|
30
|
+
*
|
|
31
|
+
* Produces a nested map where each endpoint's input type is preserved.
|
|
32
|
+
*/
|
|
33
|
+
type InferClientInputs<T extends NestedClient<any>> = T extends Client<any, infer U, any, any> ? U : {
|
|
34
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? InferClientInputs<T[K]> : never;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Recursively infers the **body input types** from a client.
|
|
38
|
+
*
|
|
39
|
+
* If an endpoint's input includes `{ body: ... }`, only the `body` portion is extracted.
|
|
40
|
+
* Produces a nested map of body input types.
|
|
41
|
+
*/
|
|
42
|
+
type InferClientBodyInputs<T extends NestedClient<any>> = T extends Client<any, infer U, any, any> ? U extends {
|
|
43
|
+
body: infer UBody;
|
|
44
|
+
} ? UBody : U : {
|
|
45
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? InferClientBodyInputs<T[K]> : never;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Recursively infers the **output types** from a client.
|
|
49
|
+
*
|
|
50
|
+
* Produces a nested map where each endpoint's output type is preserved.
|
|
51
|
+
*/
|
|
52
|
+
type InferClientOutputs<T extends NestedClient<any>> = T extends Client<any, any, infer U, any> ? U : {
|
|
53
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? InferClientOutputs<T[K]> : never;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Recursively infers the **body output types** from a client.
|
|
57
|
+
*
|
|
58
|
+
* If an endpoint's output includes `{ body: ... }`, only the `body` portion is extracted.
|
|
59
|
+
* Produces a nested map of body output types.
|
|
60
|
+
*/
|
|
61
|
+
type InferClientBodyOutputs<T extends NestedClient<any>> = T extends Client<any, any, infer U, any> ? U extends {
|
|
62
|
+
body: infer UBody;
|
|
63
|
+
} ? UBody : U : {
|
|
64
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? InferClientBodyOutputs<T[K]> : never;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Recursively infers the **error types** from a client when you use [type-safe errors](https://orpc.dev/docs/error-handling#type‐safe-error-handling).
|
|
68
|
+
*
|
|
69
|
+
* Produces a nested map where each endpoint's error type is preserved.
|
|
70
|
+
*/
|
|
71
|
+
type InferClientErrors<T extends NestedClient<any>> = T extends Client<any, any, any, infer U> ? U : {
|
|
72
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? InferClientErrors<T[K]> : never;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Recursively infers a **union of all error types** from a client when you use [type-safe errors](https://orpc.dev/docs/error-handling#type‐safe-error-handling).
|
|
76
|
+
*
|
|
77
|
+
* Useful when you want to handle all possible errors from any endpoint at once.
|
|
78
|
+
*/
|
|
79
|
+
type InferClientErrorUnion<T extends NestedClient<any>> = T extends Client<any, any, any, infer U> ? U : {
|
|
80
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? InferClientErrorUnion<T[K]> : never;
|
|
81
|
+
}[keyof T];
|
|
82
|
+
|
|
83
|
+
export type { ClientLink as C, FriendlyClientOptions as F, HTTPPath as H, InferClientContext as I, NestedClient as N, ClientPromiseResult as a, ClientContext as b, ClientOptions as c, Client as d, ClientRest as e, HTTPMethod as f, InferClientInputs as g, InferClientBodyInputs as h, InferClientOutputs as i, InferClientBodyOutputs as j, InferClientErrors as k, InferClientErrorUnion as l };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { PromiseWithError } from '@orpc/shared';
|
|
2
|
+
|
|
3
|
+
type HTTPPath = `/${string}`;
|
|
4
|
+
type HTTPMethod = 'HEAD' | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
5
|
+
type ClientContext = Record<PropertyKey, any>;
|
|
6
|
+
interface ClientOptions<T extends ClientContext> {
|
|
7
|
+
signal?: AbortSignal;
|
|
8
|
+
lastEventId?: string | undefined;
|
|
9
|
+
context: T;
|
|
10
|
+
}
|
|
11
|
+
type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
|
12
|
+
context?: T;
|
|
13
|
+
} : {
|
|
14
|
+
context: T;
|
|
15
|
+
});
|
|
16
|
+
type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>];
|
|
17
|
+
type ClientPromiseResult<TOutput, TError> = PromiseWithError<TOutput, TError>;
|
|
18
|
+
interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> {
|
|
19
|
+
(...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
|
|
20
|
+
}
|
|
21
|
+
type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
|
|
22
|
+
[k: string]: NestedClient<TClientContext>;
|
|
23
|
+
};
|
|
24
|
+
type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
|
|
25
|
+
interface ClientLink<TClientContext extends ClientContext> {
|
|
26
|
+
call: (path: readonly string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Recursively infers the **input types** from a client.
|
|
30
|
+
*
|
|
31
|
+
* Produces a nested map where each endpoint's input type is preserved.
|
|
32
|
+
*/
|
|
33
|
+
type InferClientInputs<T extends NestedClient<any>> = T extends Client<any, infer U, any, any> ? U : {
|
|
34
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? InferClientInputs<T[K]> : never;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Recursively infers the **body input types** from a client.
|
|
38
|
+
*
|
|
39
|
+
* If an endpoint's input includes `{ body: ... }`, only the `body` portion is extracted.
|
|
40
|
+
* Produces a nested map of body input types.
|
|
41
|
+
*/
|
|
42
|
+
type InferClientBodyInputs<T extends NestedClient<any>> = T extends Client<any, infer U, any, any> ? U extends {
|
|
43
|
+
body: infer UBody;
|
|
44
|
+
} ? UBody : U : {
|
|
45
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? InferClientBodyInputs<T[K]> : never;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Recursively infers the **output types** from a client.
|
|
49
|
+
*
|
|
50
|
+
* Produces a nested map where each endpoint's output type is preserved.
|
|
51
|
+
*/
|
|
52
|
+
type InferClientOutputs<T extends NestedClient<any>> = T extends Client<any, any, infer U, any> ? U : {
|
|
53
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? InferClientOutputs<T[K]> : never;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Recursively infers the **body output types** from a client.
|
|
57
|
+
*
|
|
58
|
+
* If an endpoint's output includes `{ body: ... }`, only the `body` portion is extracted.
|
|
59
|
+
* Produces a nested map of body output types.
|
|
60
|
+
*/
|
|
61
|
+
type InferClientBodyOutputs<T extends NestedClient<any>> = T extends Client<any, any, infer U, any> ? U extends {
|
|
62
|
+
body: infer UBody;
|
|
63
|
+
} ? UBody : U : {
|
|
64
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? InferClientBodyOutputs<T[K]> : never;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Recursively infers the **error types** from a client when you use [type-safe errors](https://orpc.dev/docs/error-handling#type‐safe-error-handling).
|
|
68
|
+
*
|
|
69
|
+
* Produces a nested map where each endpoint's error type is preserved.
|
|
70
|
+
*/
|
|
71
|
+
type InferClientErrors<T extends NestedClient<any>> = T extends Client<any, any, any, infer U> ? U : {
|
|
72
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? InferClientErrors<T[K]> : never;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Recursively infers a **union of all error types** from a client when you use [type-safe errors](https://orpc.dev/docs/error-handling#type‐safe-error-handling).
|
|
76
|
+
*
|
|
77
|
+
* Useful when you want to handle all possible errors from any endpoint at once.
|
|
78
|
+
*/
|
|
79
|
+
type InferClientErrorUnion<T extends NestedClient<any>> = T extends Client<any, any, any, infer U> ? U : {
|
|
80
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? InferClientErrorUnion<T[K]> : never;
|
|
81
|
+
}[keyof T];
|
|
82
|
+
|
|
83
|
+
export type { ClientLink as C, FriendlyClientOptions as F, HTTPPath as H, InferClientContext as I, NestedClient as N, ClientPromiseResult as a, ClientContext as b, ClientOptions as c, Client as d, ClientRest as e, HTTPMethod as f, InferClientInputs as g, InferClientBodyInputs as h, InferClientOutputs as i, InferClientBodyOutputs as j, InferClientErrors as k, InferClientErrorUnion as l };
|
package/package.json
CHANGED
|
@@ -1,58 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/client",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.b2ee3f3",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"homepage": "https://orpc.
|
|
6
|
+
"homepage": "https://orpc.dev",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/
|
|
9
|
+
"url": "git+https://github.com/middleapi/orpc.git",
|
|
10
10
|
"directory": "packages/client"
|
|
11
11
|
},
|
|
12
12
|
"keywords": [
|
|
13
|
-
"unnoq",
|
|
14
13
|
"orpc"
|
|
15
14
|
],
|
|
16
15
|
"exports": {
|
|
17
16
|
".": {
|
|
18
|
-
"types": "./dist/
|
|
19
|
-
"import": "./dist/index.
|
|
20
|
-
"default": "./dist/index.
|
|
17
|
+
"types": "./dist/index.d.mts",
|
|
18
|
+
"import": "./dist/index.mjs",
|
|
19
|
+
"default": "./dist/index.mjs"
|
|
21
20
|
},
|
|
22
|
-
"./
|
|
23
|
-
"types": "./dist/
|
|
24
|
-
"import": "./dist/
|
|
25
|
-
"default": "./dist/
|
|
21
|
+
"./plugins": {
|
|
22
|
+
"types": "./dist/plugins/index.d.mts",
|
|
23
|
+
"import": "./dist/plugins/index.mjs",
|
|
24
|
+
"default": "./dist/plugins/index.mjs"
|
|
26
25
|
},
|
|
27
|
-
"./
|
|
28
|
-
"types": "./dist/
|
|
29
|
-
"import": "./dist/
|
|
30
|
-
"default": "./dist/
|
|
26
|
+
"./standard": {
|
|
27
|
+
"types": "./dist/adapters/standard/index.d.mts",
|
|
28
|
+
"import": "./dist/adapters/standard/index.mjs",
|
|
29
|
+
"default": "./dist/adapters/standard/index.mjs"
|
|
31
30
|
},
|
|
32
31
|
"./fetch": {
|
|
33
|
-
"types": "./dist/
|
|
34
|
-
"import": "./dist/fetch.
|
|
35
|
-
"default": "./dist/fetch.
|
|
32
|
+
"types": "./dist/adapters/fetch/index.d.mts",
|
|
33
|
+
"import": "./dist/adapters/fetch/index.mjs",
|
|
34
|
+
"default": "./dist/adapters/fetch/index.mjs"
|
|
36
35
|
},
|
|
37
|
-
"
|
|
38
|
-
"types": "./dist/
|
|
36
|
+
"./websocket": {
|
|
37
|
+
"types": "./dist/adapters/websocket/index.d.mts",
|
|
38
|
+
"import": "./dist/adapters/websocket/index.mjs",
|
|
39
|
+
"default": "./dist/adapters/websocket/index.mjs"
|
|
40
|
+
},
|
|
41
|
+
"./message-port": {
|
|
42
|
+
"types": "./dist/adapters/message-port/index.d.mts",
|
|
43
|
+
"import": "./dist/adapters/message-port/index.mjs",
|
|
44
|
+
"default": "./dist/adapters/message-port/index.mjs"
|
|
39
45
|
}
|
|
40
46
|
},
|
|
41
47
|
"files": [
|
|
42
|
-
"!**/*.map",
|
|
43
|
-
"!**/*.tsbuildinfo",
|
|
44
48
|
"dist"
|
|
45
49
|
],
|
|
46
50
|
"dependencies": {
|
|
47
|
-
"@orpc/
|
|
48
|
-
"@orpc/
|
|
49
|
-
"@orpc/standard-server": "0.0.0-next.
|
|
51
|
+
"@orpc/shared": "0.0.0-next.b2ee3f3",
|
|
52
|
+
"@orpc/standard-server-fetch": "0.0.0-next.b2ee3f3",
|
|
53
|
+
"@orpc/standard-server-peer": "0.0.0-next.b2ee3f3",
|
|
54
|
+
"@orpc/standard-server": "0.0.0-next.b2ee3f3"
|
|
50
55
|
},
|
|
51
56
|
"devDependencies": {
|
|
52
|
-
"zod": "^3.
|
|
57
|
+
"zod": "^4.3.6"
|
|
53
58
|
},
|
|
54
59
|
"scripts": {
|
|
55
|
-
"build": "
|
|
60
|
+
"build": "unbuild",
|
|
56
61
|
"build:watch": "pnpm run build --watch",
|
|
57
62
|
"type:check": "tsc -b"
|
|
58
63
|
}
|
package/dist/chunk-4HZVK3GJ.js
DELETED
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ORPCError,
|
|
3
|
-
mapEventIterator,
|
|
4
|
-
toORPCError
|
|
5
|
-
} from "./chunk-X34KXUAJ.js";
|
|
6
|
-
|
|
7
|
-
// src/rpc/json-serializer.ts
|
|
8
|
-
import { isObject } from "@orpc/shared";
|
|
9
|
-
var RPCJsonSerializer = class {
|
|
10
|
-
serialize(data, segments = [], meta = [], maps = [], blobs = []) {
|
|
11
|
-
if (data instanceof Blob) {
|
|
12
|
-
maps.push(segments);
|
|
13
|
-
blobs.push(data);
|
|
14
|
-
return [data, meta, maps, blobs];
|
|
15
|
-
}
|
|
16
|
-
if (typeof data === "bigint") {
|
|
17
|
-
meta.push([0, segments]);
|
|
18
|
-
return [data.toString(), meta, maps, blobs];
|
|
19
|
-
}
|
|
20
|
-
if (data instanceof Date) {
|
|
21
|
-
meta.push([1, segments]);
|
|
22
|
-
if (Number.isNaN(data.getTime())) {
|
|
23
|
-
return [null, meta, maps, blobs];
|
|
24
|
-
}
|
|
25
|
-
return [data.toISOString(), meta, maps, blobs];
|
|
26
|
-
}
|
|
27
|
-
if (Number.isNaN(data)) {
|
|
28
|
-
meta.push([2, segments]);
|
|
29
|
-
return [null, meta, maps, blobs];
|
|
30
|
-
}
|
|
31
|
-
if (data instanceof URL) {
|
|
32
|
-
meta.push([4, segments]);
|
|
33
|
-
return [data.toString(), meta, maps, blobs];
|
|
34
|
-
}
|
|
35
|
-
if (data instanceof RegExp) {
|
|
36
|
-
meta.push([5, segments]);
|
|
37
|
-
return [data.toString(), meta, maps, blobs];
|
|
38
|
-
}
|
|
39
|
-
if (data instanceof Set) {
|
|
40
|
-
const result = this.serialize(Array.from(data), segments, meta, maps, blobs);
|
|
41
|
-
meta.push([6, segments]);
|
|
42
|
-
return result;
|
|
43
|
-
}
|
|
44
|
-
if (data instanceof Map) {
|
|
45
|
-
const result = this.serialize(Array.from(data.entries()), segments, meta, maps, blobs);
|
|
46
|
-
meta.push([7, segments]);
|
|
47
|
-
return result;
|
|
48
|
-
}
|
|
49
|
-
if (Array.isArray(data)) {
|
|
50
|
-
const json = data.map((v, i) => {
|
|
51
|
-
if (v === void 0) {
|
|
52
|
-
meta.push([3, [...segments, i]]);
|
|
53
|
-
return v;
|
|
54
|
-
}
|
|
55
|
-
return this.serialize(v, [...segments, i], meta, maps, blobs)[0];
|
|
56
|
-
});
|
|
57
|
-
return [json, meta, maps, blobs];
|
|
58
|
-
}
|
|
59
|
-
if (isObject(data)) {
|
|
60
|
-
const json = {};
|
|
61
|
-
for (const k in data) {
|
|
62
|
-
json[k] = this.serialize(data[k], [...segments, k], meta, maps, blobs)[0];
|
|
63
|
-
}
|
|
64
|
-
return [json, meta, maps, blobs];
|
|
65
|
-
}
|
|
66
|
-
return [data, meta, maps, blobs];
|
|
67
|
-
}
|
|
68
|
-
deserialize(json, meta, maps, getBlob) {
|
|
69
|
-
const ref = { data: json };
|
|
70
|
-
if (maps && getBlob) {
|
|
71
|
-
maps.forEach((segments, i) => {
|
|
72
|
-
let currentRef = ref;
|
|
73
|
-
let preSegment = "data";
|
|
74
|
-
segments.forEach((segment) => {
|
|
75
|
-
currentRef = currentRef[preSegment];
|
|
76
|
-
preSegment = segment;
|
|
77
|
-
});
|
|
78
|
-
currentRef[preSegment] = getBlob(i);
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
for (const [type, segments] of meta) {
|
|
82
|
-
let currentRef = ref;
|
|
83
|
-
let preSegment = "data";
|
|
84
|
-
segments.forEach((segment) => {
|
|
85
|
-
currentRef = currentRef[preSegment];
|
|
86
|
-
preSegment = segment;
|
|
87
|
-
});
|
|
88
|
-
switch (type) {
|
|
89
|
-
case 0:
|
|
90
|
-
currentRef[preSegment] = BigInt(currentRef[preSegment]);
|
|
91
|
-
break;
|
|
92
|
-
case 1:
|
|
93
|
-
currentRef[preSegment] = new Date(currentRef[preSegment] ?? "Invalid Date");
|
|
94
|
-
break;
|
|
95
|
-
case 2:
|
|
96
|
-
currentRef[preSegment] = Number.NaN;
|
|
97
|
-
break;
|
|
98
|
-
case 3:
|
|
99
|
-
currentRef[preSegment] = void 0;
|
|
100
|
-
break;
|
|
101
|
-
case 4:
|
|
102
|
-
currentRef[preSegment] = new URL(currentRef[preSegment]);
|
|
103
|
-
break;
|
|
104
|
-
case 5: {
|
|
105
|
-
const [, pattern, flags] = currentRef[preSegment].match(/^\/(.*)\/([a-z]*)$/);
|
|
106
|
-
currentRef[preSegment] = new RegExp(pattern, flags);
|
|
107
|
-
break;
|
|
108
|
-
}
|
|
109
|
-
case 6:
|
|
110
|
-
currentRef[preSegment] = new Set(currentRef[preSegment]);
|
|
111
|
-
break;
|
|
112
|
-
case 7:
|
|
113
|
-
currentRef[preSegment] = new Map(currentRef[preSegment]);
|
|
114
|
-
break;
|
|
115
|
-
/* v8 ignore next 3 */
|
|
116
|
-
default: {
|
|
117
|
-
const _expected = type;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
return ref.data;
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
// src/rpc/serializer.ts
|
|
126
|
-
import { ErrorEvent, isAsyncIteratorObject } from "@orpc/standard-server";
|
|
127
|
-
var RPCSerializer = class {
|
|
128
|
-
constructor(jsonSerializer = new RPCJsonSerializer()) {
|
|
129
|
-
this.jsonSerializer = jsonSerializer;
|
|
130
|
-
}
|
|
131
|
-
serialize(data) {
|
|
132
|
-
if (isAsyncIteratorObject(data)) {
|
|
133
|
-
return mapEventIterator(data, {
|
|
134
|
-
value: async (value) => this.#serialize(value, false),
|
|
135
|
-
error: async (e) => {
|
|
136
|
-
if (e instanceof ErrorEvent) {
|
|
137
|
-
return new ErrorEvent({
|
|
138
|
-
data: this.#serialize(e.data, false),
|
|
139
|
-
cause: e
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
return new ErrorEvent({
|
|
143
|
-
data: this.#serialize(toORPCError(e).toJSON(), false),
|
|
144
|
-
cause: e
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
return this.#serialize(data, true);
|
|
150
|
-
}
|
|
151
|
-
#serialize(data, enableFormData) {
|
|
152
|
-
if (data === void 0 || data instanceof Blob) {
|
|
153
|
-
return data;
|
|
154
|
-
}
|
|
155
|
-
const [json, meta_, maps, blobs] = this.jsonSerializer.serialize(data);
|
|
156
|
-
const meta = meta_.length === 0 ? void 0 : meta_;
|
|
157
|
-
if (!enableFormData || blobs.length === 0) {
|
|
158
|
-
return {
|
|
159
|
-
json,
|
|
160
|
-
meta
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
const form = new FormData();
|
|
164
|
-
form.set("data", JSON.stringify({ json, meta, maps }));
|
|
165
|
-
blobs.forEach((blob, i) => {
|
|
166
|
-
form.set(i.toString(), blob);
|
|
167
|
-
});
|
|
168
|
-
return form;
|
|
169
|
-
}
|
|
170
|
-
deserialize(data) {
|
|
171
|
-
if (isAsyncIteratorObject(data)) {
|
|
172
|
-
return mapEventIterator(data, {
|
|
173
|
-
value: async (value) => this.#deserialize(value),
|
|
174
|
-
error: async (e) => {
|
|
175
|
-
if (!(e instanceof ErrorEvent)) {
|
|
176
|
-
return e;
|
|
177
|
-
}
|
|
178
|
-
const deserialized = this.#deserialize(e.data);
|
|
179
|
-
if (ORPCError.isValidJSON(deserialized)) {
|
|
180
|
-
return ORPCError.fromJSON(deserialized, { cause: e });
|
|
181
|
-
}
|
|
182
|
-
return new ErrorEvent({
|
|
183
|
-
data: deserialized,
|
|
184
|
-
cause: e
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
return this.#deserialize(data);
|
|
190
|
-
}
|
|
191
|
-
#deserialize(data) {
|
|
192
|
-
if (data === void 0 || data instanceof Blob) {
|
|
193
|
-
return data;
|
|
194
|
-
}
|
|
195
|
-
if (!(data instanceof FormData)) {
|
|
196
|
-
return this.jsonSerializer.deserialize(data.json, data.meta ?? []);
|
|
197
|
-
}
|
|
198
|
-
const serialized = JSON.parse(data.get("data"));
|
|
199
|
-
return this.jsonSerializer.deserialize(
|
|
200
|
-
serialized.json,
|
|
201
|
-
serialized.meta ?? [],
|
|
202
|
-
serialized.maps,
|
|
203
|
-
(i) => data.get(i.toString())
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
export {
|
|
209
|
-
RPCJsonSerializer,
|
|
210
|
-
RPCSerializer
|
|
211
|
-
};
|
|
212
|
-
//# sourceMappingURL=chunk-4HZVK3GJ.js.map
|