@orpc/client 0.0.0-next.b825e0c → 0.0.0-next.b83dcee
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 +98 -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 +45 -0
- package/dist/adapters/message-port/index.d.mts +59 -0
- package/dist/adapters/message-port/index.d.ts +59 -0
- package/dist/adapters/message-port/index.mjs +72 -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 +5 -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 +46 -0
- package/dist/index.d.mts +230 -0
- package/dist/index.d.ts +230 -0
- package/dist/index.mjs +111 -0
- package/dist/plugins/index.d.mts +202 -0
- package/dist/plugins/index.d.ts +202 -0
- package/dist/plugins/index.mjs +406 -0
- package/dist/shared/client.BG98rYdO.d.ts +45 -0
- package/dist/shared/client.BOYsZIRq.d.mts +29 -0
- package/dist/shared/client.BOYsZIRq.d.ts +29 -0
- package/dist/shared/client.Bwgm6dgk.d.mts +45 -0
- package/dist/shared/client.ByFQsV2m.mjs +397 -0
- package/dist/shared/client.CVVVqf1Y.d.ts +91 -0
- package/dist/shared/client._Y_enhib.d.mts +91 -0
- package/dist/shared/client.pA2wFdly.mjs +208 -0
- package/package.json +32 -18
- package/dist/fetch.js +0 -103
- package/dist/index.js +0 -42
- package/dist/src/adapters/fetch/index.d.ts +0 -3
- package/dist/src/adapters/fetch/orpc-link.d.ts +0 -46
- 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 -13
- package/dist/src/index.d.ts +0 -6
- package/dist/src/types.d.ts +0 -5
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { resolveMaybeOptionalOptions, getConstructor, isObject, AsyncIteratorClass, isTypescriptObject } from '@orpc/shared';
|
|
2
|
+
import { getEventMeta, withEventMeta } from '@orpc/standard-server';
|
|
3
|
+
|
|
4
|
+
const ORPC_CLIENT_PACKAGE_NAME = "@orpc/client";
|
|
5
|
+
const ORPC_CLIENT_PACKAGE_VERSION = "0.0.0-next.b83dcee";
|
|
6
|
+
|
|
7
|
+
const COMMON_ORPC_ERROR_DEFS = {
|
|
8
|
+
BAD_REQUEST: {
|
|
9
|
+
status: 400,
|
|
10
|
+
message: "Bad Request"
|
|
11
|
+
},
|
|
12
|
+
UNAUTHORIZED: {
|
|
13
|
+
status: 401,
|
|
14
|
+
message: "Unauthorized"
|
|
15
|
+
},
|
|
16
|
+
FORBIDDEN: {
|
|
17
|
+
status: 403,
|
|
18
|
+
message: "Forbidden"
|
|
19
|
+
},
|
|
20
|
+
NOT_FOUND: {
|
|
21
|
+
status: 404,
|
|
22
|
+
message: "Not Found"
|
|
23
|
+
},
|
|
24
|
+
METHOD_NOT_SUPPORTED: {
|
|
25
|
+
status: 405,
|
|
26
|
+
message: "Method Not Supported"
|
|
27
|
+
},
|
|
28
|
+
NOT_ACCEPTABLE: {
|
|
29
|
+
status: 406,
|
|
30
|
+
message: "Not Acceptable"
|
|
31
|
+
},
|
|
32
|
+
TIMEOUT: {
|
|
33
|
+
status: 408,
|
|
34
|
+
message: "Request Timeout"
|
|
35
|
+
},
|
|
36
|
+
CONFLICT: {
|
|
37
|
+
status: 409,
|
|
38
|
+
message: "Conflict"
|
|
39
|
+
},
|
|
40
|
+
PRECONDITION_FAILED: {
|
|
41
|
+
status: 412,
|
|
42
|
+
message: "Precondition Failed"
|
|
43
|
+
},
|
|
44
|
+
PAYLOAD_TOO_LARGE: {
|
|
45
|
+
status: 413,
|
|
46
|
+
message: "Payload Too Large"
|
|
47
|
+
},
|
|
48
|
+
UNSUPPORTED_MEDIA_TYPE: {
|
|
49
|
+
status: 415,
|
|
50
|
+
message: "Unsupported Media Type"
|
|
51
|
+
},
|
|
52
|
+
UNPROCESSABLE_CONTENT: {
|
|
53
|
+
status: 422,
|
|
54
|
+
message: "Unprocessable Content"
|
|
55
|
+
},
|
|
56
|
+
TOO_MANY_REQUESTS: {
|
|
57
|
+
status: 429,
|
|
58
|
+
message: "Too Many Requests"
|
|
59
|
+
},
|
|
60
|
+
CLIENT_CLOSED_REQUEST: {
|
|
61
|
+
status: 499,
|
|
62
|
+
message: "Client Closed Request"
|
|
63
|
+
},
|
|
64
|
+
INTERNAL_SERVER_ERROR: {
|
|
65
|
+
status: 500,
|
|
66
|
+
message: "Internal Server Error"
|
|
67
|
+
},
|
|
68
|
+
NOT_IMPLEMENTED: {
|
|
69
|
+
status: 501,
|
|
70
|
+
message: "Not Implemented"
|
|
71
|
+
},
|
|
72
|
+
BAD_GATEWAY: {
|
|
73
|
+
status: 502,
|
|
74
|
+
message: "Bad Gateway"
|
|
75
|
+
},
|
|
76
|
+
SERVICE_UNAVAILABLE: {
|
|
77
|
+
status: 503,
|
|
78
|
+
message: "Service Unavailable"
|
|
79
|
+
},
|
|
80
|
+
GATEWAY_TIMEOUT: {
|
|
81
|
+
status: 504,
|
|
82
|
+
message: "Gateway Timeout"
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
function fallbackORPCErrorStatus(code, status) {
|
|
86
|
+
return status ?? COMMON_ORPC_ERROR_DEFS[code]?.status ?? 500;
|
|
87
|
+
}
|
|
88
|
+
function fallbackORPCErrorMessage(code, message) {
|
|
89
|
+
return message || COMMON_ORPC_ERROR_DEFS[code]?.message || code;
|
|
90
|
+
}
|
|
91
|
+
const GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL = Symbol.for(`__${ORPC_CLIENT_PACKAGE_NAME}@${ORPC_CLIENT_PACKAGE_VERSION}/error/ORPC_ERROR_CONSTRUCTORS__`);
|
|
92
|
+
void (globalThis[GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL] ??= /* @__PURE__ */ new WeakSet());
|
|
93
|
+
const globalORPCErrorConstructors = globalThis[GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL];
|
|
94
|
+
class ORPCError extends Error {
|
|
95
|
+
defined;
|
|
96
|
+
code;
|
|
97
|
+
status;
|
|
98
|
+
data;
|
|
99
|
+
constructor(code, ...rest) {
|
|
100
|
+
const options = resolveMaybeOptionalOptions(rest);
|
|
101
|
+
if (options.status !== void 0 && !isORPCErrorStatus(options.status)) {
|
|
102
|
+
throw new Error("[ORPCError] Invalid error status code.");
|
|
103
|
+
}
|
|
104
|
+
const message = fallbackORPCErrorMessage(code, options.message);
|
|
105
|
+
super(message, options);
|
|
106
|
+
this.code = code;
|
|
107
|
+
this.status = fallbackORPCErrorStatus(code, options.status);
|
|
108
|
+
this.defined = options.defined ?? false;
|
|
109
|
+
this.data = options.data;
|
|
110
|
+
}
|
|
111
|
+
toJSON() {
|
|
112
|
+
return {
|
|
113
|
+
defined: this.defined,
|
|
114
|
+
code: this.code,
|
|
115
|
+
status: this.status,
|
|
116
|
+
message: this.message,
|
|
117
|
+
data: this.data
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Workaround for Next.js where different contexts use separate
|
|
122
|
+
* dependency graphs, causing multiple ORPCError constructors existing and breaking
|
|
123
|
+
* `instanceof` checks across contexts.
|
|
124
|
+
*
|
|
125
|
+
* This is particularly problematic with "Optimized SSR", where orpc-client
|
|
126
|
+
* executes in one context but is invoked from another. When an error is thrown
|
|
127
|
+
* in the execution context, `instanceof ORPCError` checks fail in the
|
|
128
|
+
* invocation context due to separate class constructors.
|
|
129
|
+
*
|
|
130
|
+
* @todo Remove this and related code if Next.js resolves the multiple dependency graph issue.
|
|
131
|
+
*/
|
|
132
|
+
static [Symbol.hasInstance](instance) {
|
|
133
|
+
if (globalORPCErrorConstructors.has(this)) {
|
|
134
|
+
const constructor = getConstructor(instance);
|
|
135
|
+
if (constructor && globalORPCErrorConstructors.has(constructor)) {
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return super[Symbol.hasInstance](instance);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
globalORPCErrorConstructors.add(ORPCError);
|
|
143
|
+
function isDefinedError(error) {
|
|
144
|
+
return error instanceof ORPCError && error.defined;
|
|
145
|
+
}
|
|
146
|
+
function toORPCError(error) {
|
|
147
|
+
return error instanceof ORPCError ? error : new ORPCError("INTERNAL_SERVER_ERROR", {
|
|
148
|
+
message: "Internal server error",
|
|
149
|
+
cause: error
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
function isORPCErrorStatus(status) {
|
|
153
|
+
return status < 200 || status >= 400;
|
|
154
|
+
}
|
|
155
|
+
function isORPCErrorJson(json) {
|
|
156
|
+
if (!isObject(json)) {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
const validKeys = ["defined", "code", "status", "message", "data"];
|
|
160
|
+
if (Object.keys(json).some((k) => !validKeys.includes(k))) {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
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";
|
|
164
|
+
}
|
|
165
|
+
function createORPCErrorFromJson(json, options = {}) {
|
|
166
|
+
return new ORPCError(json.code, {
|
|
167
|
+
...options,
|
|
168
|
+
...json
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function mapEventIterator(iterator, maps) {
|
|
173
|
+
const mapError = async (error) => {
|
|
174
|
+
let mappedError = await maps.error(error);
|
|
175
|
+
if (mappedError !== error) {
|
|
176
|
+
const meta = getEventMeta(error);
|
|
177
|
+
if (meta && isTypescriptObject(mappedError)) {
|
|
178
|
+
mappedError = withEventMeta(mappedError, meta);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return mappedError;
|
|
182
|
+
};
|
|
183
|
+
return new AsyncIteratorClass(async () => {
|
|
184
|
+
const { done, value } = await (async () => {
|
|
185
|
+
try {
|
|
186
|
+
return await iterator.next();
|
|
187
|
+
} catch (error) {
|
|
188
|
+
throw await mapError(error);
|
|
189
|
+
}
|
|
190
|
+
})();
|
|
191
|
+
let mappedValue = await maps.value(value, done);
|
|
192
|
+
if (mappedValue !== value) {
|
|
193
|
+
const meta = getEventMeta(value);
|
|
194
|
+
if (meta && isTypescriptObject(mappedValue)) {
|
|
195
|
+
mappedValue = withEventMeta(mappedValue, meta);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return { done, value: mappedValue };
|
|
199
|
+
}, async () => {
|
|
200
|
+
try {
|
|
201
|
+
await iterator.return?.();
|
|
202
|
+
} catch (error) {
|
|
203
|
+
throw await mapError(error);
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
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, mapEventIterator as m, toORPCError as t };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/client",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.b83dcee",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -15,36 +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"
|
|
36
|
+
},
|
|
37
|
+
"./websocket": {
|
|
38
|
+
"types": "./dist/adapters/websocket/index.d.mts",
|
|
39
|
+
"import": "./dist/adapters/websocket/index.mjs",
|
|
40
|
+
"default": "./dist/adapters/websocket/index.mjs"
|
|
26
41
|
},
|
|
27
|
-
"
|
|
28
|
-
"types": "./dist/
|
|
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
51
|
"dependencies": {
|
|
37
|
-
"
|
|
38
|
-
"@orpc/
|
|
39
|
-
"@orpc/server": "0.0.0-next.
|
|
40
|
-
"@orpc/
|
|
52
|
+
"@orpc/standard-server-fetch": "0.0.0-next.b83dcee",
|
|
53
|
+
"@orpc/shared": "0.0.0-next.b83dcee",
|
|
54
|
+
"@orpc/standard-server-peer": "0.0.0-next.b83dcee",
|
|
55
|
+
"@orpc/standard-server": "0.0.0-next.b83dcee"
|
|
41
56
|
},
|
|
42
57
|
"devDependencies": {
|
|
43
|
-
"zod": "^
|
|
44
|
-
"@orpc/openapi": "0.0.0-next.b825e0c"
|
|
58
|
+
"zod": "^4.1.5"
|
|
45
59
|
},
|
|
46
60
|
"scripts": {
|
|
47
|
-
"build": "
|
|
61
|
+
"build": "unbuild",
|
|
48
62
|
"build:watch": "pnpm run build --watch",
|
|
49
63
|
"type:check": "tsc -b"
|
|
50
64
|
}
|
package/dist/fetch.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
// src/adapters/fetch/orpc-link.ts
|
|
2
|
-
import { ORPCError } from "@orpc/contract";
|
|
3
|
-
import { fetchReToStandardBody } from "@orpc/server/fetch";
|
|
4
|
-
import { RPCSerializer } from "@orpc/server/standard";
|
|
5
|
-
import { isPlainObject, trim } from "@orpc/shared";
|
|
6
|
-
import cd from "content-disposition";
|
|
7
|
-
var RPCLink = class {
|
|
8
|
-
fetch;
|
|
9
|
-
rpcSerializer;
|
|
10
|
-
maxURLLength;
|
|
11
|
-
fallbackMethod;
|
|
12
|
-
getMethod;
|
|
13
|
-
getHeaders;
|
|
14
|
-
url;
|
|
15
|
-
constructor(options) {
|
|
16
|
-
this.fetch = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
17
|
-
this.rpcSerializer = options.rpcSerializer ?? new RPCSerializer();
|
|
18
|
-
this.maxURLLength = options.maxURLLength ?? 2083;
|
|
19
|
-
this.fallbackMethod = options.fallbackMethod ?? "POST";
|
|
20
|
-
this.url = options.url;
|
|
21
|
-
this.getMethod = async (path, input, context) => {
|
|
22
|
-
return await options.method?.(path, input, context) ?? this.fallbackMethod;
|
|
23
|
-
};
|
|
24
|
-
this.getHeaders = async (path, input, context) => {
|
|
25
|
-
return new Headers(await options.headers?.(path, input, context));
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
async call(path, input, options) {
|
|
29
|
-
const clientContext = options.context;
|
|
30
|
-
const encoded = await this.encode(path, input, options);
|
|
31
|
-
if (encoded.body instanceof Blob && !encoded.headers.has("content-disposition")) {
|
|
32
|
-
encoded.headers.set("content-disposition", cd(encoded.body instanceof File ? encoded.body.name : "blob"));
|
|
33
|
-
}
|
|
34
|
-
const response = await this.fetch(encoded.url, {
|
|
35
|
-
method: encoded.method,
|
|
36
|
-
headers: encoded.headers,
|
|
37
|
-
body: encoded.body,
|
|
38
|
-
signal: options.signal
|
|
39
|
-
}, clientContext);
|
|
40
|
-
const body = await fetchReToStandardBody(response);
|
|
41
|
-
const deserialized = (() => {
|
|
42
|
-
try {
|
|
43
|
-
return this.rpcSerializer.deserialize(body);
|
|
44
|
-
} catch (error) {
|
|
45
|
-
if (response.ok) {
|
|
46
|
-
throw new ORPCError("INTERNAL_SERVER_ERROR", {
|
|
47
|
-
message: "Invalid RPC response",
|
|
48
|
-
cause: error
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
throw new ORPCError(response.status.toString(), {
|
|
52
|
-
message: response.statusText
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
})();
|
|
56
|
-
if (response.ok) {
|
|
57
|
-
return deserialized;
|
|
58
|
-
}
|
|
59
|
-
throw ORPCError.fromJSON(deserialized);
|
|
60
|
-
}
|
|
61
|
-
async encode(path, input, options) {
|
|
62
|
-
const clientContext = options.context;
|
|
63
|
-
const expectMethod = await this.getMethod(path, input, clientContext);
|
|
64
|
-
const headers = await this.getHeaders(path, input, clientContext);
|
|
65
|
-
const url = new URL(`${trim(this.url, "/")}/${path.map(encodeURIComponent).join("/")}`);
|
|
66
|
-
headers.append("x-orpc-handler", "rpc");
|
|
67
|
-
const serialized = this.rpcSerializer.serialize(input);
|
|
68
|
-
if (expectMethod === "GET" && isPlainObject(serialized)) {
|
|
69
|
-
const tryURL = new URL(url);
|
|
70
|
-
tryURL.searchParams.append("data", JSON.stringify(serialized));
|
|
71
|
-
if (tryURL.toString().length <= this.maxURLLength) {
|
|
72
|
-
return {
|
|
73
|
-
body: void 0,
|
|
74
|
-
method: expectMethod,
|
|
75
|
-
headers,
|
|
76
|
-
url: tryURL
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
const method = expectMethod === "GET" ? this.fallbackMethod : expectMethod;
|
|
81
|
-
if (isPlainObject(serialized)) {
|
|
82
|
-
if (!headers.has("content-type")) {
|
|
83
|
-
headers.set("content-type", "application/json");
|
|
84
|
-
}
|
|
85
|
-
return {
|
|
86
|
-
body: JSON.stringify(serialized),
|
|
87
|
-
method,
|
|
88
|
-
headers,
|
|
89
|
-
url
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
return {
|
|
93
|
-
body: serialized,
|
|
94
|
-
method,
|
|
95
|
-
headers,
|
|
96
|
-
url
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
export {
|
|
101
|
-
RPCLink
|
|
102
|
-
};
|
|
103
|
-
//# sourceMappingURL=fetch.js.map
|
package/dist/index.js
DELETED
|
@@ -1,42 +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.context);
|
|
28
|
-
const output = await resolvedLink.call(path, input, options);
|
|
29
|
-
return output;
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
// src/index.ts
|
|
34
|
-
import { isDefinedError, ORPCError, safe } from "@orpc/contract";
|
|
35
|
-
export {
|
|
36
|
-
DynamicLink,
|
|
37
|
-
ORPCError,
|
|
38
|
-
createORPCClient,
|
|
39
|
-
isDefinedError,
|
|
40
|
-
safe
|
|
41
|
-
};
|
|
42
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import type { ClientOptions, HTTPMethod } from '@orpc/contract';
|
|
2
|
-
import type { Promisable } from '@orpc/shared';
|
|
3
|
-
import type { ClientLink } from '../../types';
|
|
4
|
-
import type { FetchWithContext } from './types';
|
|
5
|
-
import { RPCSerializer } from '@orpc/server/standard';
|
|
6
|
-
export interface RPCLinkOptions<TClientContext> {
|
|
7
|
-
/**
|
|
8
|
-
* Base url for all requests.
|
|
9
|
-
*/
|
|
10
|
-
url: string;
|
|
11
|
-
/**
|
|
12
|
-
* The maximum length of the URL.
|
|
13
|
-
*
|
|
14
|
-
* @default 2083
|
|
15
|
-
*/
|
|
16
|
-
maxURLLength?: number;
|
|
17
|
-
/**
|
|
18
|
-
* The method used to make the request.
|
|
19
|
-
*
|
|
20
|
-
* @default 'POST'
|
|
21
|
-
*/
|
|
22
|
-
method?(path: readonly string[], input: unknown, context: TClientContext): Promisable<HTTPMethod | undefined>;
|
|
23
|
-
/**
|
|
24
|
-
* The method to use when the payload cannot safely pass to the server with method return from method function.
|
|
25
|
-
* GET is not allowed, it's very dangerous.
|
|
26
|
-
*
|
|
27
|
-
* @default 'POST'
|
|
28
|
-
*/
|
|
29
|
-
fallbackMethod?: Exclude<HTTPMethod, 'GET'>;
|
|
30
|
-
headers?(path: readonly string[], input: unknown, context: TClientContext): Promisable<Headers | Record<string, string>>;
|
|
31
|
-
fetch?: FetchWithContext<TClientContext>;
|
|
32
|
-
rpcSerializer?: RPCSerializer;
|
|
33
|
-
}
|
|
34
|
-
export declare class RPCLink<TClientContext> implements ClientLink<TClientContext> {
|
|
35
|
-
private readonly fetch;
|
|
36
|
-
private readonly rpcSerializer;
|
|
37
|
-
private readonly maxURLLength;
|
|
38
|
-
private readonly fallbackMethod;
|
|
39
|
-
private readonly getMethod;
|
|
40
|
-
private readonly getHeaders;
|
|
41
|
-
private readonly url;
|
|
42
|
-
constructor(options: RPCLinkOptions<TClientContext>);
|
|
43
|
-
call(path: readonly string[], input: unknown, options: ClientOptions<TClientContext>): Promise<unknown>;
|
|
44
|
-
private encode;
|
|
45
|
-
}
|
|
46
|
-
//# sourceMappingURL=orpc-link.d.ts.map
|
package/dist/src/client.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { AnyContractRouter, ContractRouterClient } from '@orpc/contract';
|
|
2
|
-
import type { AnyRouter, 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 AnyRouter | AnyContractRouter, TClientContext = unknown>(link: ClientLink<TClientContext>, options?: createORPCClientOptions): TRouter extends AnyRouter ? RouterClient<TRouter, TClientContext> : TRouter extends AnyContractRouter ? ContractRouterClient<TRouter, TClientContext> : never;
|
|
11
|
-
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { ClientOptions } from '@orpc/contract';
|
|
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, context: TClientContext) => Promisable<ClientLink<TClientContext>>);
|
|
11
|
-
call(path: readonly string[], input: unknown, options: ClientOptions<TClientContext>): Promise<unknown>;
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=dynamic-link.d.ts.map
|
package/dist/src/index.d.ts
DELETED
package/dist/src/types.d.ts
DELETED