@orpc/client 0.0.0-next.b15d206 → 0.0.0-next.b1b9914
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 +45 -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 +86 -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 +203 -0
- package/dist/plugins/index.d.ts +203 -0
- package/dist/plugins/index.mjs +407 -0
- package/dist/shared/client.BH1AYT_p.d.mts +83 -0
- package/dist/shared/client.BH1AYT_p.d.ts +83 -0
- package/dist/shared/client.BxV-mzeR.d.ts +91 -0
- package/dist/shared/client.CPgZaUox.d.mts +45 -0
- package/dist/shared/client.Cjojmy1X.mjs +397 -0
- package/dist/shared/client.D8lMmWVC.d.mts +91 -0
- package/dist/shared/client.De8SW4Kw.d.ts +45 -0
- package/dist/shared/client.gS0zIx6W.mjs +208 -0
- package/package.json +39 -24
- package/dist/index.js +0 -83
- package/dist/index.js.map +0 -1
- package/dist/src/index.d.ts +0 -7
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/procedure.d.ts +0 -27
- package/dist/src/procedure.d.ts.map +0 -1
- package/dist/src/router.d.ts +0 -34
- package/dist/src/router.d.ts.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/src/index.ts +0 -9
- package/src/procedure.test.ts +0 -245
- package/src/procedure.ts +0 -108
- package/src/router.test.ts +0 -148
- package/src/router.ts +0 -96
|
@@ -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.b1b9914";
|
|
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,49 +1,64 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/client",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-next.
|
|
5
|
-
"author": {
|
|
6
|
-
"name": "unnoq",
|
|
7
|
-
"email": "contact@unnoq.com",
|
|
8
|
-
"url": "https://unnoq.com"
|
|
9
|
-
},
|
|
4
|
+
"version": "0.0.0-next.b1b9914",
|
|
10
5
|
"license": "MIT",
|
|
11
|
-
"homepage": "https://
|
|
6
|
+
"homepage": "https://orpc.unnoq.com",
|
|
12
7
|
"repository": {
|
|
13
8
|
"type": "git",
|
|
14
|
-
"url": "https://github.com/unnoq/orpc.git",
|
|
9
|
+
"url": "git+https://github.com/unnoq/orpc.git",
|
|
15
10
|
"directory": "packages/client"
|
|
16
11
|
},
|
|
17
12
|
"keywords": [
|
|
18
|
-
"unnoq"
|
|
13
|
+
"unnoq",
|
|
14
|
+
"orpc"
|
|
19
15
|
],
|
|
20
16
|
"exports": {
|
|
21
17
|
".": {
|
|
22
|
-
"types": "./dist/
|
|
23
|
-
"import": "./dist/index.
|
|
24
|
-
"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"
|
|
25
31
|
},
|
|
26
|
-
"
|
|
27
|
-
"types": "./dist/
|
|
32
|
+
"./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"
|
|
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"
|
|
28
46
|
}
|
|
29
47
|
},
|
|
30
48
|
"files": [
|
|
31
|
-
"dist"
|
|
32
|
-
"src"
|
|
49
|
+
"dist"
|
|
33
50
|
],
|
|
34
|
-
"peerDependencies": {
|
|
35
|
-
"@orpc/contract": "0.0.0-next.b15d206",
|
|
36
|
-
"@orpc/server": "0.0.0-next.b15d206"
|
|
37
|
-
},
|
|
38
51
|
"dependencies": {
|
|
39
|
-
"@orpc/
|
|
40
|
-
"@orpc/
|
|
52
|
+
"@orpc/shared": "0.0.0-next.b1b9914",
|
|
53
|
+
"@orpc/standard-server": "0.0.0-next.b1b9914",
|
|
54
|
+
"@orpc/standard-server-fetch": "0.0.0-next.b1b9914",
|
|
55
|
+
"@orpc/standard-server-peer": "0.0.0-next.b1b9914"
|
|
41
56
|
},
|
|
42
57
|
"devDependencies": {
|
|
43
|
-
"zod": "^
|
|
58
|
+
"zod": "^4.1.12"
|
|
44
59
|
},
|
|
45
60
|
"scripts": {
|
|
46
|
-
"build": "
|
|
61
|
+
"build": "unbuild",
|
|
47
62
|
"build:watch": "pnpm run build --watch",
|
|
48
63
|
"type:check": "tsc -b"
|
|
49
64
|
}
|
package/dist/index.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
// src/procedure.ts
|
|
2
|
-
import {
|
|
3
|
-
ORPC_HEADER,
|
|
4
|
-
ORPC_HEADER_VALUE
|
|
5
|
-
} from "@orpc/contract";
|
|
6
|
-
import { trim } from "@orpc/shared";
|
|
7
|
-
import { ORPCError } from "@orpc/shared/error";
|
|
8
|
-
import { ORPCDeserializer, ORPCSerializer } from "@orpc/transformer";
|
|
9
|
-
function createProcedureClient(options) {
|
|
10
|
-
const serializer = new ORPCSerializer();
|
|
11
|
-
const deserializer = new ORPCDeserializer();
|
|
12
|
-
const client = async (input) => {
|
|
13
|
-
const fetch_ = options.fetch ?? fetch;
|
|
14
|
-
const url = `${trim(options.baseURL, "/")}/${options.path.map(encodeURIComponent).join("/")}`;
|
|
15
|
-
let headers = await options.headers?.(input);
|
|
16
|
-
headers = headers instanceof Headers ? headers : new Headers(headers);
|
|
17
|
-
const { body, headers: headers_ } = serializer.serialize(input);
|
|
18
|
-
for (const [key, value] of headers_.entries()) {
|
|
19
|
-
headers.set(key, value);
|
|
20
|
-
}
|
|
21
|
-
headers.set(ORPC_HEADER, ORPC_HEADER_VALUE);
|
|
22
|
-
const response = await fetch_(url, {
|
|
23
|
-
method: "POST",
|
|
24
|
-
headers,
|
|
25
|
-
body
|
|
26
|
-
});
|
|
27
|
-
const json = await (async () => {
|
|
28
|
-
try {
|
|
29
|
-
return await deserializer.deserialize(response);
|
|
30
|
-
} catch (e) {
|
|
31
|
-
throw new ORPCError({
|
|
32
|
-
code: "INTERNAL_SERVER_ERROR",
|
|
33
|
-
message: "Cannot parse response.",
|
|
34
|
-
cause: e
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
})();
|
|
38
|
-
if (!response.ok) {
|
|
39
|
-
throw ORPCError.fromJSON(json) ?? new ORPCError({
|
|
40
|
-
status: response.status,
|
|
41
|
-
code: "INTERNAL_SERVER_ERROR",
|
|
42
|
-
message: "Internal server error"
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
return json;
|
|
46
|
-
};
|
|
47
|
-
return client;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// src/router.ts
|
|
51
|
-
function createRouterClient(options) {
|
|
52
|
-
const path = options?.path ?? [];
|
|
53
|
-
const client = new Proxy(
|
|
54
|
-
createProcedureClient({
|
|
55
|
-
baseURL: options.baseURL,
|
|
56
|
-
fetch: options.fetch,
|
|
57
|
-
headers: options.headers,
|
|
58
|
-
path
|
|
59
|
-
}),
|
|
60
|
-
{
|
|
61
|
-
get(target, key) {
|
|
62
|
-
if (typeof key !== "string") {
|
|
63
|
-
return Reflect.get(target, key);
|
|
64
|
-
}
|
|
65
|
-
return createRouterClient({
|
|
66
|
-
...options,
|
|
67
|
-
path: [...path, key]
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
);
|
|
72
|
-
return client;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// src/index.ts
|
|
76
|
-
export * from "@orpc/shared/error";
|
|
77
|
-
var createORPCClient = createRouterClient;
|
|
78
|
-
export {
|
|
79
|
-
createORPCClient,
|
|
80
|
-
createProcedureClient,
|
|
81
|
-
createRouterClient
|
|
82
|
-
};
|
|
83
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/procedure.ts","../src/router.ts","../src/index.ts"],"sourcesContent":["/// <reference lib=\"dom\" />\n/// <reference lib=\"dom.iterable\" />\n\nimport type { Promisable } from '@orpc/shared'\nimport {\n ORPC_HEADER,\n ORPC_HEADER_VALUE,\n type Schema,\n type SchemaInput,\n type SchemaOutput,\n} from '@orpc/contract'\nimport { trim } from '@orpc/shared'\nimport { ORPCError } from '@orpc/shared/error'\nimport { ORPCDeserializer, ORPCSerializer } from '@orpc/transformer'\n\nexport interface ProcedureClient<\n TInputSchema extends Schema,\n TOutputSchema extends Schema,\n TFuncOutput extends SchemaOutput<TOutputSchema>,\n> {\n (\n input: SchemaInput<TInputSchema>,\n ): Promise<SchemaOutput<TOutputSchema, TFuncOutput>>\n}\n\nexport interface CreateProcedureClientOptions {\n /**\n * The base url of the server.\n */\n baseURL: string\n\n /**\n * The fetch function used to make the request.\n * @default global fetch\n */\n fetch?: typeof fetch\n\n /**\n * The headers used to make the request.\n * Invoked before the request is made.\n */\n headers?: (input: unknown) => Promisable<Headers | Record<string, string>>\n\n /**\n * The path of the procedure on server.\n */\n path: string[]\n}\n\nexport function createProcedureClient<\n TInputSchema extends Schema,\n TOutputSchema extends Schema,\n TFuncOutput extends SchemaOutput<TOutputSchema>,\n>(\n options: CreateProcedureClientOptions,\n): ProcedureClient<TInputSchema, TOutputSchema, TFuncOutput> {\n const serializer = new ORPCSerializer()\n const deserializer = new ORPCDeserializer()\n\n const client = async (input: unknown): Promise<unknown> => {\n const fetch_ = options.fetch ?? fetch\n const url = `${trim(options.baseURL, '/')}/${options.path.map(encodeURIComponent).join('/')}`\n let headers = await options.headers?.(input)\n headers = headers instanceof Headers ? headers : new Headers(headers)\n\n const { body, headers: headers_ } = serializer.serialize(input)\n\n for (const [key, value] of headers_.entries()) {\n headers.set(key, value)\n }\n\n headers.set(ORPC_HEADER, ORPC_HEADER_VALUE)\n\n const response = await fetch_(url, {\n method: 'POST',\n headers,\n body,\n })\n\n const json = await (async () => {\n try {\n return await deserializer.deserialize(response)\n }\n catch (e) {\n throw new ORPCError({\n code: 'INTERNAL_SERVER_ERROR',\n message: 'Cannot parse response.',\n cause: e,\n })\n }\n })()\n\n if (!response.ok) {\n throw (\n ORPCError.fromJSON(json)\n ?? new ORPCError({\n status: response.status,\n code: 'INTERNAL_SERVER_ERROR',\n message: 'Internal server error',\n })\n )\n }\n\n return json\n }\n\n return client as any\n}\n","/// <reference lib=\"dom\" />\n\nimport type {\n ContractProcedure,\n ContractRouter,\n SchemaOutput,\n} from '@orpc/contract'\nimport type { Procedure, Router } from '@orpc/server'\nimport type { Promisable } from '@orpc/shared'\nimport { createProcedureClient, type ProcedureClient } from './procedure'\n\nexport type RouterClientWithContractRouter<TRouter extends ContractRouter> = {\n [K in keyof TRouter]: TRouter[K] extends ContractProcedure<\n infer UInputSchema,\n infer UOutputSchema\n >\n ? ProcedureClient<UInputSchema, UOutputSchema, SchemaOutput<UOutputSchema>>\n : TRouter[K] extends ContractRouter\n ? RouterClientWithContractRouter<TRouter[K]>\n : never\n}\n\nexport type RouterClientWithRouter<TRouter extends Router<any>> = {\n [K in keyof TRouter]: TRouter[K] extends Procedure<\n any,\n any,\n infer UInputSchema,\n infer UOutputSchema,\n infer UFuncOutput\n >\n ? ProcedureClient<UInputSchema, UOutputSchema, UFuncOutput>\n : TRouter[K] extends Router<any>\n ? RouterClientWithRouter<TRouter[K]>\n : never\n}\n\nexport interface CreateRouterClientOptions {\n /**\n * The base url of the server.\n */\n baseURL: string\n\n /**\n * The fetch function used to make the request.\n * @default global fetch\n */\n fetch?: typeof fetch\n\n /**\n * The headers used to make the request.\n * Invoked before the request is made.\n */\n headers?: (input: unknown) => Promisable<Headers | Record<string, string>>\n\n /**\n * This used for internal purpose only.\n *\n * @internal\n */\n path?: string[]\n}\n\nexport function createRouterClient<\n TRouter extends Router<any> | ContractRouter,\n>(\n options: CreateRouterClientOptions,\n): TRouter extends Router<any>\n ? RouterClientWithRouter<TRouter>\n : TRouter extends ContractRouter\n ? RouterClientWithContractRouter<TRouter>\n : never {\n const path = options?.path ?? []\n\n const client = new Proxy(\n createProcedureClient({\n baseURL: options.baseURL,\n fetch: options.fetch,\n headers: options.headers,\n path,\n }),\n {\n get(target, key) {\n if (typeof key !== 'string') {\n return Reflect.get(target, key)\n }\n\n return createRouterClient({\n ...options,\n path: [...path, key],\n })\n },\n },\n )\n\n return client as any\n}\n","/** unnoq */\n\nimport { createRouterClient } from './router'\n\nexport * from './procedure'\nexport * from './router'\nexport * from '@orpc/shared/error'\n\nexport const createORPCClient = createRouterClient\n"],"mappings":";AAIA;AAAA,EACE;AAAA,EACA;AAAA,OAIK;AACP,SAAS,YAAY;AACrB,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB,sBAAsB;AAoC1C,SAAS,sBAKd,SAC2D;AAC3D,QAAM,aAAa,IAAI,eAAe;AACtC,QAAM,eAAe,IAAI,iBAAiB;AAE1C,QAAM,SAAS,OAAO,UAAqC;AACzD,UAAM,SAAS,QAAQ,SAAS;AAChC,UAAM,MAAM,GAAG,KAAK,QAAQ,SAAS,GAAG,CAAC,IAAI,QAAQ,KAAK,IAAI,kBAAkB,EAAE,KAAK,GAAG,CAAC;AAC3F,QAAI,UAAU,MAAM,QAAQ,UAAU,KAAK;AAC3C,cAAU,mBAAmB,UAAU,UAAU,IAAI,QAAQ,OAAO;AAEpE,UAAM,EAAE,MAAM,S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.d.ts
DELETED
package/dist/src/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY;AAEZ,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAE7C,cAAc,aAAa,CAAA;AAC3B,cAAc,UAAU,CAAA;AACxB,cAAc,oBAAoB,CAAA;AAElC,eAAO,MAAM,gBAAgB,2BAAqB,CAAA"}
|
package/dist/src/procedure.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { Promisable } from '@orpc/shared';
|
|
2
|
-
import { type Schema, type SchemaInput, type SchemaOutput } from '@orpc/contract';
|
|
3
|
-
export interface ProcedureClient<TInputSchema extends Schema, TOutputSchema extends Schema, TFuncOutput extends SchemaOutput<TOutputSchema>> {
|
|
4
|
-
(input: SchemaInput<TInputSchema>): Promise<SchemaOutput<TOutputSchema, TFuncOutput>>;
|
|
5
|
-
}
|
|
6
|
-
export interface CreateProcedureClientOptions {
|
|
7
|
-
/**
|
|
8
|
-
* The base url of the server.
|
|
9
|
-
*/
|
|
10
|
-
baseURL: string;
|
|
11
|
-
/**
|
|
12
|
-
* The fetch function used to make the request.
|
|
13
|
-
* @default global fetch
|
|
14
|
-
*/
|
|
15
|
-
fetch?: typeof fetch;
|
|
16
|
-
/**
|
|
17
|
-
* The headers used to make the request.
|
|
18
|
-
* Invoked before the request is made.
|
|
19
|
-
*/
|
|
20
|
-
headers?: (input: unknown) => Promisable<Headers | Record<string, string>>;
|
|
21
|
-
/**
|
|
22
|
-
* The path of the procedure on server.
|
|
23
|
-
*/
|
|
24
|
-
path: string[];
|
|
25
|
-
}
|
|
26
|
-
export declare function createProcedureClient<TInputSchema extends Schema, TOutputSchema extends Schema, TFuncOutput extends SchemaOutput<TOutputSchema>>(options: CreateProcedureClientOptions): ProcedureClient<TInputSchema, TOutputSchema, TFuncOutput>;
|
|
27
|
-
//# sourceMappingURL=procedure.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"procedure.d.ts","sourceRoot":"","sources":["../../src/procedure.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAGL,KAAK,MAAM,EACX,KAAK,WAAW,EAChB,KAAK,YAAY,EAClB,MAAM,gBAAgB,CAAA;AAKvB,MAAM,WAAW,eAAe,CAC9B,YAAY,SAAS,MAAM,EAC3B,aAAa,SAAS,MAAM,EAC5B,WAAW,SAAS,YAAY,CAAC,aAAa,CAAC;IAE/C,CACE,KAAK,EAAE,WAAW,CAAC,YAAY,CAAC,GAC/B,OAAO,CAAC,YAAY,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC,CAAA;CACrD;AAED,MAAM,WAAW,4BAA4B;IAC3C;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IAEf;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,KAAK,CAAA;IAEpB;;;OAGG;IACH,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,UAAU,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;IAE1E;;OAEG;IACH,IAAI,EAAE,MAAM,EAAE,CAAA;CACf;AAED,wBAAgB,qBAAqB,CACnC,YAAY,SAAS,MAAM,EAC3B,aAAa,SAAS,MAAM,EAC5B,WAAW,SAAS,YAAY,CAAC,aAAa,CAAC,EAE/C,OAAO,EAAE,4BAA4B,GACpC,eAAe,CAAC,YAAY,EAAE,aAAa,EAAE,WAAW,CAAC,CAoD3D"}
|
package/dist/src/router.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { ContractProcedure, ContractRouter, SchemaOutput } from '@orpc/contract';
|
|
2
|
-
import type { Procedure, Router } from '@orpc/server';
|
|
3
|
-
import type { Promisable } from '@orpc/shared';
|
|
4
|
-
import { type ProcedureClient } from './procedure';
|
|
5
|
-
export type RouterClientWithContractRouter<TRouter extends ContractRouter> = {
|
|
6
|
-
[K in keyof TRouter]: TRouter[K] extends ContractProcedure<infer UInputSchema, infer UOutputSchema> ? ProcedureClient<UInputSchema, UOutputSchema, SchemaOutput<UOutputSchema>> : TRouter[K] extends ContractRouter ? RouterClientWithContractRouter<TRouter[K]> : never;
|
|
7
|
-
};
|
|
8
|
-
export type RouterClientWithRouter<TRouter extends Router<any>> = {
|
|
9
|
-
[K in keyof TRouter]: TRouter[K] extends Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput> ? ProcedureClient<UInputSchema, UOutputSchema, UFuncOutput> : TRouter[K] extends Router<any> ? RouterClientWithRouter<TRouter[K]> : never;
|
|
10
|
-
};
|
|
11
|
-
export interface CreateRouterClientOptions {
|
|
12
|
-
/**
|
|
13
|
-
* The base url of the server.
|
|
14
|
-
*/
|
|
15
|
-
baseURL: string;
|
|
16
|
-
/**
|
|
17
|
-
* The fetch function used to make the request.
|
|
18
|
-
* @default global fetch
|
|
19
|
-
*/
|
|
20
|
-
fetch?: typeof fetch;
|
|
21
|
-
/**
|
|
22
|
-
* The headers used to make the request.
|
|
23
|
-
* Invoked before the request is made.
|
|
24
|
-
*/
|
|
25
|
-
headers?: (input: unknown) => Promisable<Headers | Record<string, string>>;
|
|
26
|
-
/**
|
|
27
|
-
* This used for internal purpose only.
|
|
28
|
-
*
|
|
29
|
-
* @internal
|
|
30
|
-
*/
|
|
31
|
-
path?: string[];
|
|
32
|
-
}
|
|
33
|
-
export declare function createRouterClient<TRouter extends Router<any> | ContractRouter>(options: CreateRouterClientOptions): TRouter extends Router<any> ? RouterClientWithRouter<TRouter> : TRouter extends ContractRouter ? RouterClientWithContractRouter<TRouter> : never;
|
|
34
|
-
//# sourceMappingURL=router.d.ts.map
|
package/dist/src/router.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot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