@orpc/server 0.0.0-next.316c163 → 0.0.0-next.331b26b
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/chunk-3BAPJGK6.js +302 -0
- package/dist/{chunk-FN62GL22.js → chunk-E7GUWVR4.js} +20 -16
- package/dist/chunk-WUOGVGWG.js +1 -0
- package/dist/fetch.js +11 -108
- package/dist/hono.js +30 -0
- package/dist/index.js +15 -12
- package/dist/next.js +36 -0
- package/dist/node.js +87 -0
- package/dist/src/adapters/fetch/index.d.ts +6 -0
- package/dist/src/adapters/fetch/orpc-handler.d.ts +20 -0
- package/dist/src/adapters/fetch/orpc-payload-codec.d.ts +16 -0
- package/dist/src/adapters/fetch/orpc-procedure-matcher.d.ts +12 -0
- package/dist/src/adapters/fetch/super-json.d.ts +12 -0
- package/dist/src/adapters/fetch/types.d.ts +21 -0
- package/dist/src/adapters/hono/index.d.ts +3 -0
- package/dist/src/adapters/hono/middleware.d.ts +12 -0
- package/dist/src/adapters/next/index.d.ts +3 -0
- package/dist/src/adapters/next/serve.d.ts +19 -0
- package/dist/src/adapters/node/index.d.ts +5 -0
- package/dist/src/adapters/node/orpc-handler.d.ts +12 -0
- package/dist/src/adapters/node/request-listener.d.ts +28 -0
- package/dist/src/adapters/node/types.d.ts +22 -0
- package/dist/src/builder.d.ts +2 -2
- package/dist/src/index.d.ts +1 -0
- package/dist/src/lazy-decorated.d.ts +1 -1
- package/dist/src/middleware.d.ts +16 -6
- package/dist/src/procedure-builder.d.ts +2 -2
- package/dist/src/procedure-client.d.ts +11 -6
- package/dist/src/procedure-decorated.d.ts +8 -8
- package/dist/src/procedure-implementer.d.ts +2 -2
- package/dist/src/procedure.d.ts +15 -8
- package/dist/src/router-client.d.ts +3 -3
- package/dist/src/types.d.ts +2 -0
- package/package.json +22 -10
- package/dist/src/fetch/handle-request.d.ts +0 -7
- package/dist/src/fetch/index.d.ts +0 -4
- package/dist/src/fetch/orpc-handler.d.ts +0 -3
- package/dist/src/fetch/types.d.ts +0 -28
@@ -0,0 +1,302 @@
|
|
1
|
+
import {
|
2
|
+
__export,
|
3
|
+
createProcedureClient,
|
4
|
+
getRouterChild,
|
5
|
+
isProcedure,
|
6
|
+
unlazy
|
7
|
+
} from "./chunk-E7GUWVR4.js";
|
8
|
+
|
9
|
+
// src/adapters/fetch/super-json.ts
|
10
|
+
var super_json_exports = {};
|
11
|
+
__export(super_json_exports, {
|
12
|
+
deserialize: () => deserialize,
|
13
|
+
serialize: () => serialize
|
14
|
+
});
|
15
|
+
|
16
|
+
// ../../node_modules/.pnpm/is-what@5.0.2/node_modules/is-what/dist/getType.js
|
17
|
+
function getType(payload) {
|
18
|
+
return Object.prototype.toString.call(payload).slice(8, -1);
|
19
|
+
}
|
20
|
+
|
21
|
+
// ../../node_modules/.pnpm/is-what@5.0.2/node_modules/is-what/dist/isPlainObject.js
|
22
|
+
function isPlainObject(payload) {
|
23
|
+
if (getType(payload) !== "Object")
|
24
|
+
return false;
|
25
|
+
const prototype = Object.getPrototypeOf(payload);
|
26
|
+
return !!prototype && prototype.constructor === Object && prototype === Object.prototype;
|
27
|
+
}
|
28
|
+
|
29
|
+
// src/adapters/fetch/super-json.ts
|
30
|
+
function serialize(value, segments = [], meta = []) {
|
31
|
+
if (typeof value === "bigint") {
|
32
|
+
meta.push(["bigint", segments]);
|
33
|
+
return { data: value.toString(), meta };
|
34
|
+
}
|
35
|
+
if (value instanceof Date) {
|
36
|
+
meta.push(["date", segments]);
|
37
|
+
const data = Number.isNaN(value.getTime()) ? "Invalid Date" : value.toISOString();
|
38
|
+
return { data, meta };
|
39
|
+
}
|
40
|
+
if (Number.isNaN(value)) {
|
41
|
+
meta.push(["nan", segments]);
|
42
|
+
return { data: "NaN", meta };
|
43
|
+
}
|
44
|
+
if (value instanceof RegExp) {
|
45
|
+
meta.push(["regexp", segments]);
|
46
|
+
return { data: value.toString(), meta };
|
47
|
+
}
|
48
|
+
if (value instanceof URL) {
|
49
|
+
meta.push(["url", segments]);
|
50
|
+
return { data: value.toString(), meta };
|
51
|
+
}
|
52
|
+
if (isPlainObject(value)) {
|
53
|
+
const data = {};
|
54
|
+
for (const k in value) {
|
55
|
+
data[k] = serialize(value[k], [...segments, k], meta).data;
|
56
|
+
}
|
57
|
+
return { data, meta };
|
58
|
+
}
|
59
|
+
if (Array.isArray(value)) {
|
60
|
+
const data = value.map((v, i) => {
|
61
|
+
if (v === void 0) {
|
62
|
+
meta.push(["undefined", [...segments, i]]);
|
63
|
+
return null;
|
64
|
+
}
|
65
|
+
return serialize(v, [...segments, i], meta).data;
|
66
|
+
});
|
67
|
+
return { data, meta };
|
68
|
+
}
|
69
|
+
if (value instanceof Set) {
|
70
|
+
const result = serialize(Array.from(value), segments, meta);
|
71
|
+
meta.push(["set", segments]);
|
72
|
+
return result;
|
73
|
+
}
|
74
|
+
if (value instanceof Map) {
|
75
|
+
const result = serialize(Array.from(value.entries()), segments, meta);
|
76
|
+
meta.push(["map", segments]);
|
77
|
+
return result;
|
78
|
+
}
|
79
|
+
return { data: value, meta };
|
80
|
+
}
|
81
|
+
function deserialize({
|
82
|
+
data,
|
83
|
+
meta
|
84
|
+
}) {
|
85
|
+
if (meta.length === 0) {
|
86
|
+
return data;
|
87
|
+
}
|
88
|
+
const ref = { data };
|
89
|
+
for (const [type, segments] of meta) {
|
90
|
+
let currentRef = ref;
|
91
|
+
let preSegment = "data";
|
92
|
+
for (let i = 0; i < segments.length; i++) {
|
93
|
+
currentRef = currentRef[preSegment];
|
94
|
+
preSegment = segments[i];
|
95
|
+
}
|
96
|
+
switch (type) {
|
97
|
+
case "nan":
|
98
|
+
currentRef[preSegment] = Number.NaN;
|
99
|
+
break;
|
100
|
+
case "bigint":
|
101
|
+
currentRef[preSegment] = BigInt(currentRef[preSegment]);
|
102
|
+
break;
|
103
|
+
case "date":
|
104
|
+
currentRef[preSegment] = new Date(currentRef[preSegment]);
|
105
|
+
break;
|
106
|
+
case "regexp": {
|
107
|
+
const [, pattern, flags] = currentRef[preSegment].match(/^\/(.*)\/([a-z]*)$/);
|
108
|
+
currentRef[preSegment] = new RegExp(pattern, flags);
|
109
|
+
break;
|
110
|
+
}
|
111
|
+
case "url":
|
112
|
+
currentRef[preSegment] = new URL(currentRef[preSegment]);
|
113
|
+
break;
|
114
|
+
case "undefined":
|
115
|
+
currentRef[preSegment] = void 0;
|
116
|
+
break;
|
117
|
+
case "map":
|
118
|
+
currentRef[preSegment] = new Map(currentRef[preSegment]);
|
119
|
+
break;
|
120
|
+
case "set":
|
121
|
+
currentRef[preSegment] = new Set(currentRef[preSegment]);
|
122
|
+
break;
|
123
|
+
/* v8 ignore next 3 */
|
124
|
+
default: {
|
125
|
+
const _expected = type;
|
126
|
+
}
|
127
|
+
}
|
128
|
+
}
|
129
|
+
return ref.data;
|
130
|
+
}
|
131
|
+
|
132
|
+
// src/adapters/fetch/orpc-payload-codec.ts
|
133
|
+
import { findDeepMatches, set } from "@orpc/shared";
|
134
|
+
import { ORPCError } from "@orpc/shared/error";
|
135
|
+
var ORPCPayloadCodec = class {
|
136
|
+
/**
|
137
|
+
* If method is GET, the payload will be encoded as query string.
|
138
|
+
* If method is GET and payload contain file, the method will be fallback to fallbackMethod. (fallbackMethod = GET will force to use GET method)
|
139
|
+
*/
|
140
|
+
encode(payload, method = "POST", fallbackMethod = "POST") {
|
141
|
+
const { data, meta } = serialize(payload);
|
142
|
+
const { maps, values } = findDeepMatches((v) => v instanceof Blob, data);
|
143
|
+
if (method === "GET" && (values.length === 0 || fallbackMethod === "GET")) {
|
144
|
+
const query = new URLSearchParams({
|
145
|
+
data: JSON.stringify(data),
|
146
|
+
meta: JSON.stringify(meta)
|
147
|
+
});
|
148
|
+
return {
|
149
|
+
query,
|
150
|
+
method: "GET"
|
151
|
+
};
|
152
|
+
}
|
153
|
+
const nonGETMethod = method === "GET" ? fallbackMethod : method;
|
154
|
+
if (values.length > 0) {
|
155
|
+
const form = new FormData();
|
156
|
+
if (data !== void 0) {
|
157
|
+
form.append("data", JSON.stringify(data));
|
158
|
+
}
|
159
|
+
form.append("meta", JSON.stringify(meta));
|
160
|
+
form.append("maps", JSON.stringify(maps));
|
161
|
+
for (const i in values) {
|
162
|
+
const value = values[i];
|
163
|
+
form.append(i, value);
|
164
|
+
}
|
165
|
+
return {
|
166
|
+
body: form,
|
167
|
+
method: nonGETMethod
|
168
|
+
};
|
169
|
+
}
|
170
|
+
return {
|
171
|
+
body: JSON.stringify({ data, meta }),
|
172
|
+
headers: new Headers({
|
173
|
+
"content-type": "application/json"
|
174
|
+
}),
|
175
|
+
method: nonGETMethod
|
176
|
+
};
|
177
|
+
}
|
178
|
+
async decode(re) {
|
179
|
+
try {
|
180
|
+
if ("method" in re && re.method === "GET") {
|
181
|
+
const url = new URL(re.url);
|
182
|
+
const query = url.searchParams;
|
183
|
+
const data = JSON.parse(query.getAll("data").at(-1));
|
184
|
+
const meta = JSON.parse(query.getAll("meta").at(-1));
|
185
|
+
return deserialize({
|
186
|
+
data,
|
187
|
+
meta
|
188
|
+
});
|
189
|
+
}
|
190
|
+
if (re.headers.get("content-type")?.startsWith("multipart/form-data")) {
|
191
|
+
const form = await re.formData();
|
192
|
+
const rawData = form.get("data");
|
193
|
+
const rawMeta = form.get("meta");
|
194
|
+
const rawMaps = form.get("maps");
|
195
|
+
let data = JSON.parse(rawData);
|
196
|
+
const meta = JSON.parse(rawMeta);
|
197
|
+
const maps = JSON.parse(rawMaps);
|
198
|
+
for (const i in maps) {
|
199
|
+
data = set(data, maps[i], form.get(i));
|
200
|
+
}
|
201
|
+
return deserialize({
|
202
|
+
data,
|
203
|
+
meta
|
204
|
+
});
|
205
|
+
}
|
206
|
+
const json = await re.json();
|
207
|
+
return deserialize(json);
|
208
|
+
} catch (e) {
|
209
|
+
throw new ORPCError({
|
210
|
+
code: "BAD_REQUEST",
|
211
|
+
message: "Cannot parse request/response. Please check the request/response body and Content-Type header.",
|
212
|
+
cause: e
|
213
|
+
});
|
214
|
+
}
|
215
|
+
}
|
216
|
+
};
|
217
|
+
|
218
|
+
// src/adapters/fetch/orpc-procedure-matcher.ts
|
219
|
+
import { trim } from "@orpc/shared";
|
220
|
+
var ORPCProcedureMatcher = class {
|
221
|
+
constructor(router) {
|
222
|
+
this.router = router;
|
223
|
+
}
|
224
|
+
async match(pathname) {
|
225
|
+
const path = trim(pathname, "/").split("/").map(decodeURIComponent);
|
226
|
+
const match = getRouterChild(this.router, ...path);
|
227
|
+
const { default: maybeProcedure } = await unlazy(match);
|
228
|
+
if (!isProcedure(maybeProcedure)) {
|
229
|
+
return void 0;
|
230
|
+
}
|
231
|
+
return {
|
232
|
+
procedure: maybeProcedure,
|
233
|
+
path
|
234
|
+
};
|
235
|
+
}
|
236
|
+
};
|
237
|
+
|
238
|
+
// src/adapters/fetch/orpc-handler.ts
|
239
|
+
import { executeWithHooks, trim as trim2 } from "@orpc/shared";
|
240
|
+
import { ORPCError as ORPCError2 } from "@orpc/shared/error";
|
241
|
+
var ORPCHandler = class {
|
242
|
+
constructor(router, options) {
|
243
|
+
this.options = options;
|
244
|
+
this.procedureMatcher = options?.procedureMatcher ?? new ORPCProcedureMatcher(router);
|
245
|
+
this.payloadCodec = options?.payloadCodec ?? new ORPCPayloadCodec();
|
246
|
+
}
|
247
|
+
procedureMatcher;
|
248
|
+
payloadCodec;
|
249
|
+
async handle(request, ...[options]) {
|
250
|
+
const context = options?.context;
|
251
|
+
const execute = async () => {
|
252
|
+
const url = new URL(request.url);
|
253
|
+
const pathname = `/${trim2(url.pathname.replace(options?.prefix ?? "", ""), "/")}`;
|
254
|
+
const match = await this.procedureMatcher.match(pathname);
|
255
|
+
if (!match) {
|
256
|
+
return { matched: false, response: void 0 };
|
257
|
+
}
|
258
|
+
const input = await this.payloadCodec.decode(request);
|
259
|
+
const client = createProcedureClient({
|
260
|
+
context,
|
261
|
+
procedure: match.procedure,
|
262
|
+
path: match.path
|
263
|
+
});
|
264
|
+
const output = await client(input, { signal: request.signal });
|
265
|
+
const { body, headers } = this.payloadCodec.encode(output);
|
266
|
+
const response = new Response(body, { headers });
|
267
|
+
return { matched: true, response };
|
268
|
+
};
|
269
|
+
try {
|
270
|
+
const result = await executeWithHooks({
|
271
|
+
context,
|
272
|
+
execute,
|
273
|
+
input: request,
|
274
|
+
hooks: this.options,
|
275
|
+
meta: {
|
276
|
+
signal: request.signal
|
277
|
+
}
|
278
|
+
});
|
279
|
+
return result;
|
280
|
+
} catch (e) {
|
281
|
+
const error = e instanceof ORPCError2 ? e : new ORPCError2({
|
282
|
+
code: "INTERNAL_SERVER_ERROR",
|
283
|
+
message: "Internal server error",
|
284
|
+
cause: e
|
285
|
+
});
|
286
|
+
const { body, headers } = this.payloadCodec.encode(error.toJSON());
|
287
|
+
const response = new Response(body, {
|
288
|
+
headers,
|
289
|
+
status: error.status
|
290
|
+
});
|
291
|
+
return { matched: true, response };
|
292
|
+
}
|
293
|
+
}
|
294
|
+
};
|
295
|
+
|
296
|
+
export {
|
297
|
+
super_json_exports,
|
298
|
+
ORPCPayloadCodec,
|
299
|
+
ORPCProcedureMatcher,
|
300
|
+
ORPCHandler
|
301
|
+
};
|
302
|
+
//# sourceMappingURL=chunk-3BAPJGK6.js.map
|
@@ -1,3 +1,9 @@
|
|
1
|
+
var __defProp = Object.defineProperty;
|
2
|
+
var __export = (target, all) => {
|
3
|
+
for (var name in all)
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
5
|
+
};
|
6
|
+
|
1
7
|
// src/utils.ts
|
2
8
|
function mergeContext(a, b) {
|
3
9
|
if (!a)
|
@@ -23,7 +29,7 @@ function isProcedure(item) {
|
|
23
29
|
if (item instanceof Procedure) {
|
24
30
|
return true;
|
25
31
|
}
|
26
|
-
return (typeof item === "object" || typeof item === "function") && item !== null && "~type" in item && item["~type"] === "Procedure" && "~orpc" in item && typeof item["~orpc"] === "object" && item["~orpc"] !== null && "contract" in item["~orpc"] && isContractProcedure(item["~orpc"].contract) && "
|
32
|
+
return (typeof item === "object" || typeof item === "function") && item !== null && "~type" in item && item["~type"] === "Procedure" && "~orpc" in item && typeof item["~orpc"] === "object" && item["~orpc"] !== null && "contract" in item["~orpc"] && isContractProcedure(item["~orpc"].contract) && "handler" in item["~orpc"] && typeof item["~orpc"].handler === "function";
|
27
33
|
}
|
28
34
|
|
29
35
|
// src/lazy.ts
|
@@ -68,12 +74,13 @@ function createProcedureClient(options) {
|
|
68
74
|
};
|
69
75
|
const executeWithValidation = async () => {
|
70
76
|
const validInput = await validateInput(procedure, input);
|
71
|
-
const output = await executeMiddlewareChain(
|
72
|
-
procedure,
|
73
|
-
validInput,
|
77
|
+
const output = await executeMiddlewareChain({
|
74
78
|
context,
|
75
|
-
|
76
|
-
|
79
|
+
input: validInput,
|
80
|
+
path,
|
81
|
+
procedure,
|
82
|
+
signal: callerOptions?.signal
|
83
|
+
});
|
77
84
|
return validateOutput(procedure, output);
|
78
85
|
};
|
79
86
|
return executeWithHooks({
|
@@ -113,23 +120,19 @@ async function validateOutput(procedure, output) {
|
|
113
120
|
}
|
114
121
|
return result.value;
|
115
122
|
}
|
116
|
-
async function executeMiddlewareChain(
|
117
|
-
const middlewares = procedure["~orpc"].middlewares ?? [];
|
123
|
+
async function executeMiddlewareChain(opt) {
|
124
|
+
const middlewares = opt.procedure["~orpc"].middlewares ?? [];
|
118
125
|
let currentMidIndex = 0;
|
119
|
-
let currentContext = context;
|
126
|
+
let currentContext = opt.context;
|
120
127
|
const next = async (nextOptions) => {
|
121
128
|
const mid = middlewares[currentMidIndex];
|
122
129
|
currentMidIndex += 1;
|
123
130
|
currentContext = mergeContext(currentContext, nextOptions.context);
|
124
131
|
if (mid) {
|
125
|
-
return await mid(
|
126
|
-
...meta,
|
127
|
-
next,
|
128
|
-
output: (output) => ({ output, context: void 0 })
|
129
|
-
});
|
132
|
+
return await mid({ ...opt, context: currentContext, next }, opt.input, (output) => ({ output, context: void 0 }));
|
130
133
|
}
|
131
134
|
const result = {
|
132
|
-
output: await procedure["~orpc"].
|
135
|
+
output: await opt.procedure["~orpc"].handler({ ...opt, context: currentContext }),
|
133
136
|
context: currentContext
|
134
137
|
};
|
135
138
|
return result;
|
@@ -168,6 +171,7 @@ function getRouterChild(router, ...path) {
|
|
168
171
|
}
|
169
172
|
|
170
173
|
export {
|
174
|
+
__export,
|
171
175
|
mergeContext,
|
172
176
|
Procedure,
|
173
177
|
isProcedure,
|
@@ -179,4 +183,4 @@ export {
|
|
179
183
|
createProcedureClient,
|
180
184
|
getRouterChild
|
181
185
|
};
|
182
|
-
//# sourceMappingURL=chunk-
|
186
|
+
//# sourceMappingURL=chunk-E7GUWVR4.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
//# sourceMappingURL=chunk-WUOGVGWG.js.map
|
package/dist/fetch.js
CHANGED
@@ -1,112 +1,15 @@
|
|
1
|
+
import "./chunk-WUOGVGWG.js";
|
1
2
|
import {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
} from "./chunk-
|
7
|
-
|
8
|
-
// src/fetch/handle-request.ts
|
9
|
-
import { ORPCError } from "@orpc/shared/error";
|
10
|
-
async function handleFetchRequest(options) {
|
11
|
-
for (const handler of options.handlers) {
|
12
|
-
const response = await handler(options);
|
13
|
-
if (response) {
|
14
|
-
return response;
|
15
|
-
}
|
16
|
-
}
|
17
|
-
const error = new ORPCError({ code: "NOT_FOUND", message: "Not found" });
|
18
|
-
return new Response(JSON.stringify(error.toJSON()), {
|
19
|
-
status: error.status,
|
20
|
-
headers: {
|
21
|
-
"Content-Type": "application/json"
|
22
|
-
}
|
23
|
-
});
|
24
|
-
}
|
25
|
-
|
26
|
-
// src/fetch/orpc-handler.ts
|
27
|
-
import { executeWithHooks, ORPC_PROTOCOL_HEADER, ORPC_PROTOCOL_VALUE, trim, value } from "@orpc/shared";
|
28
|
-
import { ORPCError as ORPCError2 } from "@orpc/shared/error";
|
29
|
-
import { ORPCDeserializer, ORPCSerializer } from "@orpc/transformer";
|
30
|
-
var serializer = new ORPCSerializer();
|
31
|
-
var deserializer = new ORPCDeserializer();
|
32
|
-
function createORPCHandler() {
|
33
|
-
return async (options) => {
|
34
|
-
if (!options.request.headers.get(ORPC_PROTOCOL_HEADER)?.includes(ORPC_PROTOCOL_VALUE)) {
|
35
|
-
return void 0;
|
36
|
-
}
|
37
|
-
const context = await value(options.context);
|
38
|
-
const handler = async () => {
|
39
|
-
const url = new URL(options.request.url);
|
40
|
-
const pathname = `/${trim(url.pathname.replace(options.prefix ?? "", ""), "/")}`;
|
41
|
-
const match = await resolveRouterMatch(options.router, pathname);
|
42
|
-
if (!match) {
|
43
|
-
throw new ORPCError2({ code: "NOT_FOUND", message: "Not found" });
|
44
|
-
}
|
45
|
-
const input = await parseRequestInput(options.request);
|
46
|
-
const caller = createProcedureClient({
|
47
|
-
context,
|
48
|
-
procedure: match.procedure,
|
49
|
-
path: match.path
|
50
|
-
});
|
51
|
-
const output = await caller(input, { signal: options.signal });
|
52
|
-
const { body, headers } = serializer.serialize(output);
|
53
|
-
return new Response(body, {
|
54
|
-
status: 200,
|
55
|
-
headers
|
56
|
-
});
|
57
|
-
};
|
58
|
-
try {
|
59
|
-
return await executeWithHooks({
|
60
|
-
hooks: options,
|
61
|
-
context,
|
62
|
-
execute: handler,
|
63
|
-
input: options.request,
|
64
|
-
meta: {
|
65
|
-
signal: options.signal
|
66
|
-
}
|
67
|
-
});
|
68
|
-
} catch (error) {
|
69
|
-
return handleErrorResponse(error);
|
70
|
-
}
|
71
|
-
};
|
72
|
-
}
|
73
|
-
async function resolveRouterMatch(router, pathname) {
|
74
|
-
const pathSegments = trim(pathname, "/").split("/").map(decodeURIComponent);
|
75
|
-
const match = getRouterChild(router, ...pathSegments);
|
76
|
-
const { default: maybeProcedure } = await unlazy(match);
|
77
|
-
if (!isProcedure(maybeProcedure)) {
|
78
|
-
return void 0;
|
79
|
-
}
|
80
|
-
return {
|
81
|
-
procedure: maybeProcedure,
|
82
|
-
path: pathSegments
|
83
|
-
};
|
84
|
-
}
|
85
|
-
async function parseRequestInput(request) {
|
86
|
-
try {
|
87
|
-
return await deserializer.deserialize(request);
|
88
|
-
} catch (error) {
|
89
|
-
throw new ORPCError2({
|
90
|
-
code: "BAD_REQUEST",
|
91
|
-
message: "Cannot parse request. Please check the request body and Content-Type header.",
|
92
|
-
cause: error
|
93
|
-
});
|
94
|
-
}
|
95
|
-
}
|
96
|
-
function handleErrorResponse(error) {
|
97
|
-
const orpcError = error instanceof ORPCError2 ? error : new ORPCError2({
|
98
|
-
code: "INTERNAL_SERVER_ERROR",
|
99
|
-
message: "Internal server error",
|
100
|
-
cause: error
|
101
|
-
});
|
102
|
-
const { body, headers } = serializer.serialize(orpcError.toJSON());
|
103
|
-
return new Response(body, {
|
104
|
-
status: orpcError.status,
|
105
|
-
headers
|
106
|
-
});
|
107
|
-
}
|
3
|
+
ORPCHandler,
|
4
|
+
ORPCPayloadCodec,
|
5
|
+
ORPCProcedureMatcher,
|
6
|
+
super_json_exports
|
7
|
+
} from "./chunk-3BAPJGK6.js";
|
8
|
+
import "./chunk-E7GUWVR4.js";
|
108
9
|
export {
|
109
|
-
|
110
|
-
|
10
|
+
ORPCHandler,
|
11
|
+
ORPCPayloadCodec,
|
12
|
+
ORPCProcedureMatcher,
|
13
|
+
super_json_exports as SuperJSON
|
111
14
|
};
|
112
15
|
//# sourceMappingURL=fetch.js.map
|
package/dist/hono.js
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
import "./chunk-WUOGVGWG.js";
|
2
|
+
import {
|
3
|
+
ORPCHandler,
|
4
|
+
ORPCPayloadCodec,
|
5
|
+
ORPCProcedureMatcher,
|
6
|
+
super_json_exports
|
7
|
+
} from "./chunk-3BAPJGK6.js";
|
8
|
+
import "./chunk-E7GUWVR4.js";
|
9
|
+
|
10
|
+
// src/adapters/hono/middleware.ts
|
11
|
+
import { value } from "@orpc/shared";
|
12
|
+
function createMiddleware(handler, ...[options]) {
|
13
|
+
return async (c, next) => {
|
14
|
+
const context = await value(options?.context, c);
|
15
|
+
const { matched, response } = await handler.handle(c.req.raw, { ...options, context });
|
16
|
+
if (matched) {
|
17
|
+
c.res = response;
|
18
|
+
return;
|
19
|
+
}
|
20
|
+
await next();
|
21
|
+
};
|
22
|
+
}
|
23
|
+
export {
|
24
|
+
ORPCHandler,
|
25
|
+
ORPCPayloadCodec,
|
26
|
+
ORPCProcedureMatcher,
|
27
|
+
super_json_exports as SuperJSON,
|
28
|
+
createMiddleware
|
29
|
+
};
|
30
|
+
//# sourceMappingURL=hono.js.map
|
package/dist/index.js
CHANGED
@@ -9,7 +9,7 @@ import {
|
|
9
9
|
lazy,
|
10
10
|
mergeContext,
|
11
11
|
unlazy
|
12
|
-
} from "./chunk-
|
12
|
+
} from "./chunk-E7GUWVR4.js";
|
13
13
|
|
14
14
|
// src/builder.ts
|
15
15
|
import { ContractProcedure } from "@orpc/contract";
|
@@ -23,17 +23,17 @@ function decorateMiddleware(middleware) {
|
|
23
23
|
const decorated = middleware;
|
24
24
|
decorated.mapInput = (mapInput) => {
|
25
25
|
const mapped = decorateMiddleware(
|
26
|
-
(input, ...rest) => middleware(mapInput(input), ...rest)
|
26
|
+
(options, input, ...rest) => middleware(options, mapInput(input), ...rest)
|
27
27
|
);
|
28
28
|
return mapped;
|
29
29
|
};
|
30
30
|
decorated.concat = (concatMiddleware, mapInput) => {
|
31
31
|
const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
|
32
|
-
const concatted = decorateMiddleware((
|
33
|
-
const next = async (
|
34
|
-
return mapped(
|
32
|
+
const concatted = decorateMiddleware((options, input, output, ...rest) => {
|
33
|
+
const next = async (nextOptions) => {
|
34
|
+
return mapped({ ...options, context: mergeContext(nextOptions.context, options.context) }, input, output, ...rest);
|
35
35
|
};
|
36
|
-
const merged = middleware(
|
36
|
+
const merged = middleware({ ...options, next }, input, output, ...rest);
|
37
37
|
return merged;
|
38
38
|
});
|
39
39
|
return concatted;
|
@@ -110,11 +110,11 @@ var ProcedureImplementer = class _ProcedureImplementer {
|
|
110
110
|
middlewares: [...this["~orpc"].middlewares ?? [], mappedMiddleware]
|
111
111
|
});
|
112
112
|
}
|
113
|
-
|
113
|
+
handler(handler) {
|
114
114
|
return decorateProcedure(new Procedure({
|
115
115
|
middlewares: this["~orpc"].middlewares,
|
116
116
|
contract: this["~orpc"].contract,
|
117
|
-
|
117
|
+
handler
|
118
118
|
}));
|
119
119
|
}
|
120
120
|
};
|
@@ -358,11 +358,11 @@ var ProcedureBuilder = class _ProcedureBuilder {
|
|
358
358
|
middlewares: this["~orpc"].middlewares
|
359
359
|
}).use(middleware, mapInput);
|
360
360
|
}
|
361
|
-
|
361
|
+
handler(handler) {
|
362
362
|
return decorateProcedure(new Procedure({
|
363
363
|
middlewares: this["~orpc"].middlewares,
|
364
364
|
contract: this["~orpc"].contract,
|
365
|
-
|
365
|
+
handler
|
366
366
|
}));
|
367
367
|
}
|
368
368
|
};
|
@@ -416,14 +416,14 @@ var Builder = class _Builder {
|
|
416
416
|
})
|
417
417
|
});
|
418
418
|
}
|
419
|
-
|
419
|
+
handler(handler) {
|
420
420
|
return decorateProcedure(new Procedure({
|
421
421
|
middlewares: this["~orpc"].middlewares,
|
422
422
|
contract: new ContractProcedure({
|
423
423
|
InputSchema: void 0,
|
424
424
|
OutputSchema: void 0
|
425
425
|
}),
|
426
|
-
|
426
|
+
handler
|
427
427
|
}));
|
428
428
|
}
|
429
429
|
prefix(prefix) {
|
@@ -486,6 +486,7 @@ function createRouterClient(options) {
|
|
486
486
|
}
|
487
487
|
|
488
488
|
// src/index.ts
|
489
|
+
import { configGlobal, fallbackToGlobalConfig } from "@orpc/contract";
|
489
490
|
export * from "@orpc/shared/error";
|
490
491
|
var os = new Builder({});
|
491
492
|
export {
|
@@ -496,6 +497,7 @@ export {
|
|
496
497
|
ProcedureImplementer,
|
497
498
|
RouterBuilder,
|
498
499
|
RouterImplementer,
|
500
|
+
configGlobal,
|
499
501
|
createChainableImplementer,
|
500
502
|
createProcedureClient,
|
501
503
|
createRouterClient,
|
@@ -503,6 +505,7 @@ export {
|
|
503
505
|
decorateMiddleware,
|
504
506
|
decorateProcedure,
|
505
507
|
deepSetLazyRouterPrefix,
|
508
|
+
fallbackToGlobalConfig,
|
506
509
|
flatLazy,
|
507
510
|
getLazyRouterPrefix,
|
508
511
|
getRouterChild,
|
package/dist/next.js
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
import "./chunk-WUOGVGWG.js";
|
2
|
+
import {
|
3
|
+
ORPCHandler,
|
4
|
+
ORPCPayloadCodec,
|
5
|
+
ORPCProcedureMatcher,
|
6
|
+
super_json_exports
|
7
|
+
} from "./chunk-3BAPJGK6.js";
|
8
|
+
import "./chunk-E7GUWVR4.js";
|
9
|
+
|
10
|
+
// src/adapters/next/serve.ts
|
11
|
+
import { value } from "@orpc/shared";
|
12
|
+
function serve(handler, ...[options]) {
|
13
|
+
const main = async (req) => {
|
14
|
+
const context = await value(options?.context, req);
|
15
|
+
const { matched, response } = await handler.handle(req, { ...options, context });
|
16
|
+
if (matched) {
|
17
|
+
return response;
|
18
|
+
}
|
19
|
+
return new Response(`Cannot find a matching procedure for ${req.url}`, { status: 404 });
|
20
|
+
};
|
21
|
+
return {
|
22
|
+
GET: main,
|
23
|
+
POST: main,
|
24
|
+
PUT: main,
|
25
|
+
PATCH: main,
|
26
|
+
DELETE: main
|
27
|
+
};
|
28
|
+
}
|
29
|
+
export {
|
30
|
+
ORPCHandler,
|
31
|
+
ORPCPayloadCodec,
|
32
|
+
ORPCProcedureMatcher,
|
33
|
+
super_json_exports as SuperJSON,
|
34
|
+
serve
|
35
|
+
};
|
36
|
+
//# sourceMappingURL=next.js.map
|