@orpc/client 0.0.0-next.d7b5662 → 0.0.0-next.d7ee74c
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 +101 -0
- 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.BZsiKGmG.mjs +398 -0
- package/dist/shared/client.CpCa3si8.d.mts +45 -0
- package/dist/shared/client.i2uoJbEp.d.mts +83 -0
- package/dist/shared/client.i2uoJbEp.d.ts +83 -0
- package/dist/shared/client.wwGi6dZj.mjs +171 -0
- package/package.json +33 -20
- package/dist/fetch.js +0 -46
- package/dist/index.js +0 -39
- package/dist/src/adapters/fetch/index.d.ts +0 -3
- package/dist/src/adapters/fetch/orpc-link.d.ts +0 -19
- package/dist/src/adapters/fetch/types.d.ts +0 -4
- package/dist/src/client.d.ts +0 -11
- package/dist/src/dynamic-link.d.ts +0 -15
- package/dist/src/index.d.ts +0 -6
- package/dist/src/types.d.ts +0 -5
|
@@ -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,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.d7ee74c";
|
|
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 };
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/client",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.d7ee74c",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"homepage": "https://orpc.
|
|
6
|
+
"homepage": "https://orpc.dev",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "git+https://github.com/unnoq/orpc.git",
|
|
@@ -15,37 +15,50 @@
|
|
|
15
15
|
],
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
18
|
-
"types": "./dist/
|
|
19
|
-
"import": "./dist/index.
|
|
20
|
-
"default": "./dist/index.
|
|
18
|
+
"types": "./dist/index.d.mts",
|
|
19
|
+
"import": "./dist/index.mjs",
|
|
20
|
+
"default": "./dist/index.mjs"
|
|
21
|
+
},
|
|
22
|
+
"./plugins": {
|
|
23
|
+
"types": "./dist/plugins/index.d.mts",
|
|
24
|
+
"import": "./dist/plugins/index.mjs",
|
|
25
|
+
"default": "./dist/plugins/index.mjs"
|
|
26
|
+
},
|
|
27
|
+
"./standard": {
|
|
28
|
+
"types": "./dist/adapters/standard/index.d.mts",
|
|
29
|
+
"import": "./dist/adapters/standard/index.mjs",
|
|
30
|
+
"default": "./dist/adapters/standard/index.mjs"
|
|
21
31
|
},
|
|
22
32
|
"./fetch": {
|
|
23
|
-
"types": "./dist/
|
|
24
|
-
"import": "./dist/fetch.
|
|
25
|
-
"default": "./dist/fetch.
|
|
33
|
+
"types": "./dist/adapters/fetch/index.d.mts",
|
|
34
|
+
"import": "./dist/adapters/fetch/index.mjs",
|
|
35
|
+
"default": "./dist/adapters/fetch/index.mjs"
|
|
26
36
|
},
|
|
27
|
-
"
|
|
28
|
-
"types": "./dist/
|
|
37
|
+
"./websocket": {
|
|
38
|
+
"types": "./dist/adapters/websocket/index.d.mts",
|
|
39
|
+
"import": "./dist/adapters/websocket/index.mjs",
|
|
40
|
+
"default": "./dist/adapters/websocket/index.mjs"
|
|
41
|
+
},
|
|
42
|
+
"./message-port": {
|
|
43
|
+
"types": "./dist/adapters/message-port/index.d.mts",
|
|
44
|
+
"import": "./dist/adapters/message-port/index.mjs",
|
|
45
|
+
"default": "./dist/adapters/message-port/index.mjs"
|
|
29
46
|
}
|
|
30
47
|
},
|
|
31
48
|
"files": [
|
|
32
|
-
"!**/*.map",
|
|
33
|
-
"!**/*.tsbuildinfo",
|
|
34
49
|
"dist"
|
|
35
50
|
],
|
|
36
|
-
"peerDependencies": {
|
|
37
|
-
"@orpc/contract": "0.0.0-next.d7b5662"
|
|
38
|
-
},
|
|
39
51
|
"dependencies": {
|
|
40
|
-
"@orpc/server": "0.0.0-next.
|
|
41
|
-
"@orpc/shared": "0.0.0-next.
|
|
52
|
+
"@orpc/standard-server-fetch": "0.0.0-next.d7ee74c",
|
|
53
|
+
"@orpc/shared": "0.0.0-next.d7ee74c",
|
|
54
|
+
"@orpc/standard-server-peer": "0.0.0-next.d7ee74c",
|
|
55
|
+
"@orpc/standard-server": "0.0.0-next.d7ee74c"
|
|
42
56
|
},
|
|
43
57
|
"devDependencies": {
|
|
44
|
-
"zod": "^
|
|
45
|
-
"@orpc/openapi": "0.0.0-next.d7b5662"
|
|
58
|
+
"zod": "^4.2.1"
|
|
46
59
|
},
|
|
47
60
|
"scripts": {
|
|
48
|
-
"build": "
|
|
61
|
+
"build": "unbuild",
|
|
49
62
|
"build:watch": "pnpm run build --watch",
|
|
50
63
|
"type:check": "tsc -b"
|
|
51
64
|
}
|
package/dist/fetch.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
// src/adapters/fetch/orpc-link.ts
|
|
2
|
-
import { ORPCPayloadCodec } from "@orpc/server/fetch";
|
|
3
|
-
import { ORPC_HANDLER_HEADER, ORPC_HANDLER_VALUE, trim } from "@orpc/shared";
|
|
4
|
-
import { ORPCError } from "@orpc/shared/error";
|
|
5
|
-
var ORPCLink = class {
|
|
6
|
-
constructor(options) {
|
|
7
|
-
this.options = options;
|
|
8
|
-
this.fetch = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
9
|
-
this.payloadCodec = options.payloadCodec ?? new ORPCPayloadCodec();
|
|
10
|
-
}
|
|
11
|
-
fetch;
|
|
12
|
-
payloadCodec;
|
|
13
|
-
async call(path, input, options) {
|
|
14
|
-
const url = `${trim(this.options.url, "/")}/${path.map(encodeURIComponent).join("/")}`;
|
|
15
|
-
const encoded = this.payloadCodec.encode(input);
|
|
16
|
-
const headers = new Headers(encoded.headers);
|
|
17
|
-
headers.append(ORPC_HANDLER_HEADER, ORPC_HANDLER_VALUE);
|
|
18
|
-
const clientContext = options.context;
|
|
19
|
-
let customHeaders = await this.options.headers?.(input, clientContext);
|
|
20
|
-
customHeaders = customHeaders instanceof Headers ? customHeaders : new Headers(customHeaders);
|
|
21
|
-
for (const [key, value] of customHeaders.entries()) {
|
|
22
|
-
headers.append(key, value);
|
|
23
|
-
}
|
|
24
|
-
const response = await this.fetch(url, {
|
|
25
|
-
method: "POST",
|
|
26
|
-
headers,
|
|
27
|
-
body: encoded.body,
|
|
28
|
-
signal: options.signal
|
|
29
|
-
}, clientContext);
|
|
30
|
-
const decoded = await this.payloadCodec.decode(response);
|
|
31
|
-
if (!response.ok) {
|
|
32
|
-
const error = ORPCError.fromJSON(decoded) ?? new ORPCError({
|
|
33
|
-
status: response.status,
|
|
34
|
-
code: "INTERNAL_SERVER_ERROR",
|
|
35
|
-
message: "Internal server error",
|
|
36
|
-
cause: decoded
|
|
37
|
-
});
|
|
38
|
-
throw error;
|
|
39
|
-
}
|
|
40
|
-
return decoded;
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
export {
|
|
44
|
-
ORPCLink
|
|
45
|
-
};
|
|
46
|
-
//# sourceMappingURL=fetch.js.map
|
package/dist/index.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
// src/client.ts
|
|
2
|
-
function createORPCClient(link, options) {
|
|
3
|
-
const path = options?.path ?? [];
|
|
4
|
-
const procedureClient = async (...[input, options2]) => {
|
|
5
|
-
return await link.call(path, input, options2 ?? {});
|
|
6
|
-
};
|
|
7
|
-
const recursive = new Proxy(procedureClient, {
|
|
8
|
-
get(target, key) {
|
|
9
|
-
if (typeof key !== "string") {
|
|
10
|
-
return Reflect.get(target, key);
|
|
11
|
-
}
|
|
12
|
-
return createORPCClient(link, {
|
|
13
|
-
...options,
|
|
14
|
-
path: [...path, key]
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
return recursive;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// src/dynamic-link.ts
|
|
22
|
-
var DynamicLink = class {
|
|
23
|
-
constructor(linkResolver) {
|
|
24
|
-
this.linkResolver = linkResolver;
|
|
25
|
-
}
|
|
26
|
-
async call(path, input, options) {
|
|
27
|
-
const resolvedLink = await this.linkResolver(path, input, options);
|
|
28
|
-
const output = await resolvedLink.call(path, input, options);
|
|
29
|
-
return output;
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
// src/index.ts
|
|
34
|
-
export * from "@orpc/shared/error";
|
|
35
|
-
export {
|
|
36
|
-
DynamicLink,
|
|
37
|
-
createORPCClient
|
|
38
|
-
};
|
|
39
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { ProcedureClientOptions } from '@orpc/server';
|
|
2
|
-
import type { Promisable } from '@orpc/shared';
|
|
3
|
-
import type { ClientLink } from '../../types';
|
|
4
|
-
import type { FetchWithContext } from './types';
|
|
5
|
-
import { type PublicORPCPayloadCodec } from '@orpc/server/fetch';
|
|
6
|
-
export interface ORPCLinkOptions<TClientContext> {
|
|
7
|
-
url: string;
|
|
8
|
-
headers?: (input: unknown, context: TClientContext) => Promisable<Headers | Record<string, string>>;
|
|
9
|
-
fetch?: FetchWithContext<TClientContext>;
|
|
10
|
-
payloadCodec?: PublicORPCPayloadCodec;
|
|
11
|
-
}
|
|
12
|
-
export declare class ORPCLink<TClientContext> implements ClientLink<TClientContext> {
|
|
13
|
-
private readonly options;
|
|
14
|
-
private readonly fetch;
|
|
15
|
-
private readonly payloadCodec;
|
|
16
|
-
constructor(options: ORPCLinkOptions<TClientContext>);
|
|
17
|
-
call(path: readonly string[], input: unknown, options: ProcedureClientOptions<TClientContext>): Promise<unknown>;
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=orpc-link.d.ts.map
|
package/dist/src/client.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { ContractRouter } from '@orpc/contract';
|
|
2
|
-
import type { ANY_ROUTER, RouterClient } from '@orpc/server';
|
|
3
|
-
import type { ClientLink } from './types';
|
|
4
|
-
export interface createORPCClientOptions {
|
|
5
|
-
/**
|
|
6
|
-
* Use as base path for all procedure, useful when you only want to call a subset of the procedure.
|
|
7
|
-
*/
|
|
8
|
-
path?: string[];
|
|
9
|
-
}
|
|
10
|
-
export declare function createORPCClient<TRouter extends ANY_ROUTER | ContractRouter, TClientContext = unknown>(link: ClientLink<TClientContext>, options?: createORPCClientOptions): RouterClient<TRouter, TClientContext>;
|
|
11
|
-
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { ProcedureClientOptions } from '@orpc/server';
|
|
2
|
-
import type { Promisable } from '@orpc/shared';
|
|
3
|
-
import type { ClientLink } from './types';
|
|
4
|
-
/**
|
|
5
|
-
* DynamicLink provides a way to dynamically resolve and delegate calls to other ClientLinks
|
|
6
|
-
* based on the request path, input, and context.
|
|
7
|
-
*/
|
|
8
|
-
export declare class DynamicLink<TClientContext> implements ClientLink<TClientContext> {
|
|
9
|
-
private readonly linkResolver;
|
|
10
|
-
constructor(linkResolver: (path: readonly string[], input: unknown, options: ProcedureClientOptions<TClientContext> & {
|
|
11
|
-
context: TClientContext;
|
|
12
|
-
}) => Promisable<ClientLink<TClientContext>>);
|
|
13
|
-
call(path: readonly string[], input: unknown, options: ProcedureClientOptions<TClientContext>): Promise<unknown>;
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=dynamic-link.d.ts.map
|
package/dist/src/index.d.ts
DELETED
package/dist/src/types.d.ts
DELETED