@orpc/server 0.38.0 → 0.40.0
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/dist/chunk-L4ESXQX7.js +32 -0
- package/dist/{chunk-GIXDBJGV.js → chunk-NXEANHUK.js} +48 -16
- package/dist/{chunk-XFBAK67J.js → chunk-XI6WGCB3.js} +2 -5
- package/dist/{chunk-XP6YRLY2.js → chunk-XXBE6CYD.js} +3 -2
- package/dist/fetch.js +6 -12
- package/dist/hono.js +6 -12
- package/dist/index.js +15 -7
- package/dist/next.js +6 -12
- package/dist/node.js +7 -146
- package/dist/plugins.js +1 -1
- package/dist/src/adapters/fetch/index.d.ts +0 -1
- package/dist/src/adapters/node/index.d.ts +0 -1
- package/dist/src/adapters/standard/handler.d.ts +2 -1
- package/dist/src/adapters/standard/rpc-codec.d.ts +2 -1
- package/dist/src/adapters/standard/rpc-serializer.d.ts +7 -1
- package/dist/src/adapters/standard/types.d.ts +1 -25
- package/dist/src/context.d.ts +0 -1
- package/dist/src/index.d.ts +2 -1
- package/dist/src/middleware.d.ts +1 -0
- package/dist/src/procedure-client.d.ts +1 -0
- package/dist/src/procedure.d.ts +3 -2
- package/dist/standard.js +3 -3
- package/package.json +6 -4
- package/dist/chunk-WJ2G7572.js +0 -145
- package/dist/src/adapters/fetch/utils.d.ts +0 -5
- package/dist/src/adapters/node/utils.d.ts +0 -5
@@ -0,0 +1,32 @@
|
|
1
|
+
import {
|
2
|
+
RPCCodec,
|
3
|
+
RPCMatcher,
|
4
|
+
StandardHandler
|
5
|
+
} from "./chunk-NXEANHUK.js";
|
6
|
+
|
7
|
+
// src/adapters/fetch/rpc-handler.ts
|
8
|
+
import { toFetchResponse, toStandardRequest } from "@orpc/server-standard-fetch";
|
9
|
+
var RPCHandler = class {
|
10
|
+
standardHandler;
|
11
|
+
constructor(router, options) {
|
12
|
+
const matcher = options?.matcher ?? new RPCMatcher();
|
13
|
+
const codec = options?.codec ?? new RPCCodec();
|
14
|
+
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
15
|
+
}
|
16
|
+
async handle(request, ...rest) {
|
17
|
+
const standardRequest = toStandardRequest(request);
|
18
|
+
const result = await this.standardHandler.handle(standardRequest, ...rest);
|
19
|
+
if (!result.matched) {
|
20
|
+
return result;
|
21
|
+
}
|
22
|
+
return {
|
23
|
+
matched: true,
|
24
|
+
response: toFetchResponse(result.response)
|
25
|
+
};
|
26
|
+
}
|
27
|
+
};
|
28
|
+
|
29
|
+
export {
|
30
|
+
RPCHandler
|
31
|
+
};
|
32
|
+
//# sourceMappingURL=chunk-L4ESXQX7.js.map
|
@@ -6,13 +6,13 @@ import {
|
|
6
6
|
getRouterChild,
|
7
7
|
isProcedure,
|
8
8
|
unlazy
|
9
|
-
} from "./chunk-
|
9
|
+
} from "./chunk-XXBE6CYD.js";
|
10
10
|
import {
|
11
11
|
CompositePlugin
|
12
|
-
} from "./chunk-
|
12
|
+
} from "./chunk-XI6WGCB3.js";
|
13
13
|
|
14
14
|
// src/adapters/standard/handler.ts
|
15
|
-
import { toORPCError } from "@orpc/contract";
|
15
|
+
import { ORPCError, toORPCError } from "@orpc/contract";
|
16
16
|
import { intercept, trim } from "@orpc/shared";
|
17
17
|
var StandardHandler = class {
|
18
18
|
constructor(router, matcher, codec, options = {}) {
|
@@ -34,6 +34,7 @@ var StandardHandler = class {
|
|
34
34
|
// context is optional only when all fields are optional so we can safely force it to have a context
|
35
35
|
},
|
36
36
|
async (interceptorOptions) => {
|
37
|
+
let isDecoding = false;
|
37
38
|
try {
|
38
39
|
return await intercept(
|
39
40
|
this.options.interceptors ?? [],
|
@@ -52,8 +53,11 @@ var StandardHandler = class {
|
|
52
53
|
};
|
53
54
|
this.plugin.beforeCreateProcedureClient(clientOptions, interceptorOptions2);
|
54
55
|
const client = createProcedureClient(match.procedure, clientOptions);
|
56
|
+
isDecoding = true;
|
55
57
|
const input = await this.codec.decode(request, match.params, match.procedure);
|
56
|
-
|
58
|
+
isDecoding = false;
|
59
|
+
const lastEventId = Array.isArray(request.headers["last-event-id"]) ? request.headers["last-event-id"].at(-1) : request.headers["last-event-id"];
|
60
|
+
const output = await client(input, { signal: request.signal, lastEventId });
|
57
61
|
const response = this.codec.encode(output, match.procedure);
|
58
62
|
return {
|
59
63
|
matched: true,
|
@@ -62,7 +66,10 @@ var StandardHandler = class {
|
|
62
66
|
}
|
63
67
|
);
|
64
68
|
} catch (e) {
|
65
|
-
const error =
|
69
|
+
const error = isDecoding ? new ORPCError("BAD_REQUEST", {
|
70
|
+
message: `Malformed request. Ensure the request body is properly formatted and the 'Content-Type' header is set correctly.`,
|
71
|
+
cause: e
|
72
|
+
}) : toORPCError(e);
|
66
73
|
const response = this.codec.encodeError(error);
|
67
74
|
return {
|
68
75
|
matched: true,
|
@@ -75,14 +82,27 @@ var StandardHandler = class {
|
|
75
82
|
};
|
76
83
|
|
77
84
|
// src/adapters/standard/rpc-serializer.ts
|
85
|
+
import { mapEventIterator, ORPCError as ORPCError2, toORPCError as toORPCError2 } from "@orpc/contract";
|
86
|
+
import { ErrorEvent, isAsyncIteratorObject } from "@orpc/server-standard";
|
78
87
|
import { findDeepMatches, isObject, set } from "@orpc/shared";
|
79
88
|
var RPCSerializer = class {
|
80
89
|
serialize(data) {
|
81
|
-
if (data
|
82
|
-
return
|
83
|
-
|
84
|
-
|
85
|
-
|
90
|
+
if (isAsyncIteratorObject(data)) {
|
91
|
+
return mapEventIterator(data, {
|
92
|
+
value: async (value) => serializeRPCJson(value),
|
93
|
+
error: async (e) => {
|
94
|
+
if (e instanceof ErrorEvent) {
|
95
|
+
return new ErrorEvent({
|
96
|
+
data: serializeRPCJson(e.data),
|
97
|
+
cause: e
|
98
|
+
});
|
99
|
+
}
|
100
|
+
return new ErrorEvent({
|
101
|
+
data: serializeRPCJson(toORPCError2(e).toJSON()),
|
102
|
+
cause: e
|
103
|
+
});
|
104
|
+
}
|
105
|
+
});
|
86
106
|
}
|
87
107
|
const serializedJSON = serializeRPCJson(data);
|
88
108
|
const { maps, values: blobs } = findDeepMatches((v) => v instanceof Blob, serializedJSON.json);
|
@@ -98,11 +118,23 @@ var RPCSerializer = class {
|
|
98
118
|
return form;
|
99
119
|
}
|
100
120
|
deserialize(serialized) {
|
101
|
-
if (serialized
|
102
|
-
return
|
103
|
-
|
104
|
-
|
105
|
-
|
121
|
+
if (isAsyncIteratorObject(serialized)) {
|
122
|
+
return mapEventIterator(serialized, {
|
123
|
+
value: async (value) => deserializeRPCJson(value),
|
124
|
+
error: async (e) => {
|
125
|
+
if (!(e instanceof ErrorEvent)) {
|
126
|
+
return e;
|
127
|
+
}
|
128
|
+
const deserialized = deserializeRPCJson(e.data);
|
129
|
+
if (ORPCError2.isValidJSON(deserialized)) {
|
130
|
+
return ORPCError2.fromJSON(deserialized, { cause: e });
|
131
|
+
}
|
132
|
+
return new ErrorEvent({
|
133
|
+
data: deserialized,
|
134
|
+
cause: e
|
135
|
+
});
|
136
|
+
}
|
137
|
+
});
|
106
138
|
}
|
107
139
|
if (!(serialized instanceof FormData)) {
|
108
140
|
return deserializeRPCJson(serialized);
|
@@ -316,4 +348,4 @@ export {
|
|
316
348
|
RPCCodec,
|
317
349
|
RPCMatcher
|
318
350
|
};
|
319
|
-
//# sourceMappingURL=chunk-
|
351
|
+
//# sourceMappingURL=chunk-NXEANHUK.js.map
|
@@ -21,12 +21,9 @@ var CORSPlugin = class {
|
|
21
21
|
options;
|
22
22
|
constructor(options) {
|
23
23
|
const defaults = {
|
24
|
-
origin:
|
24
|
+
origin: (origin) => origin,
|
25
25
|
allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"]
|
26
26
|
};
|
27
|
-
if (options?.credentials) {
|
28
|
-
defaults.origin = (origin) => origin;
|
29
|
-
}
|
30
27
|
this.options = {
|
31
28
|
...defaults,
|
32
29
|
...options
|
@@ -125,4 +122,4 @@ export {
|
|
125
122
|
CORSPlugin,
|
126
123
|
ResponseHeadersPlugin
|
127
124
|
};
|
128
|
-
//# sourceMappingURL=chunk-
|
125
|
+
//# sourceMappingURL=chunk-XI6WGCB3.js.map
|
@@ -81,7 +81,8 @@ function createProcedureClient(lazyableProcedure, ...[options]) {
|
|
81
81
|
errors,
|
82
82
|
path,
|
83
83
|
procedure,
|
84
|
-
signal: callerOptions?.signal
|
84
|
+
signal: callerOptions?.signal,
|
85
|
+
lastEventId: callerOptions?.lastEventId
|
85
86
|
},
|
86
87
|
(interceptorOptions) => executeProcedureInternal(interceptorOptions.procedure, interceptorOptions)
|
87
88
|
);
|
@@ -375,4 +376,4 @@ export {
|
|
375
376
|
convertPathToHttpPath,
|
376
377
|
createContractedProcedure
|
377
378
|
};
|
378
|
-
//# sourceMappingURL=chunk-
|
379
|
+
//# sourceMappingURL=chunk-XXBE6CYD.js.map
|
package/dist/fetch.js
CHANGED
@@ -1,16 +1,10 @@
|
|
1
1
|
import {
|
2
|
-
RPCHandler
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
import "./chunk-GIXDBJGV.js";
|
8
|
-
import "./chunk-XP6YRLY2.js";
|
9
|
-
import "./chunk-XFBAK67J.js";
|
2
|
+
RPCHandler
|
3
|
+
} from "./chunk-L4ESXQX7.js";
|
4
|
+
import "./chunk-NXEANHUK.js";
|
5
|
+
import "./chunk-XXBE6CYD.js";
|
6
|
+
import "./chunk-XI6WGCB3.js";
|
10
7
|
export {
|
11
|
-
RPCHandler
|
12
|
-
fetchReToStandardBody,
|
13
|
-
fetchRequestToStandardRequest,
|
14
|
-
standardResponseToFetchResponse
|
8
|
+
RPCHandler
|
15
9
|
};
|
16
10
|
//# sourceMappingURL=fetch.js.map
|
package/dist/hono.js
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
import {
|
2
|
-
RPCHandler
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
import "./chunk-GIXDBJGV.js";
|
8
|
-
import "./chunk-XP6YRLY2.js";
|
9
|
-
import "./chunk-XFBAK67J.js";
|
2
|
+
RPCHandler
|
3
|
+
} from "./chunk-L4ESXQX7.js";
|
4
|
+
import "./chunk-NXEANHUK.js";
|
5
|
+
import "./chunk-XXBE6CYD.js";
|
6
|
+
import "./chunk-XI6WGCB3.js";
|
10
7
|
|
11
8
|
// src/adapters/hono/middleware.ts
|
12
9
|
import { value } from "@orpc/shared";
|
@@ -32,9 +29,6 @@ function createMiddleware(handler, ...[options]) {
|
|
32
29
|
}
|
33
30
|
export {
|
34
31
|
RPCHandler,
|
35
|
-
createMiddleware
|
36
|
-
fetchReToStandardBody,
|
37
|
-
fetchRequestToStandardRequest,
|
38
|
-
standardResponseToFetchResponse
|
32
|
+
createMiddleware
|
39
33
|
};
|
40
34
|
//# sourceMappingURL=hono.js.map
|
package/dist/index.js
CHANGED
@@ -21,7 +21,7 @@ import {
|
|
21
21
|
middlewareOutputFn,
|
22
22
|
setRouterContract,
|
23
23
|
unlazy
|
24
|
-
} from "./chunk-
|
24
|
+
} from "./chunk-XXBE6CYD.js";
|
25
25
|
|
26
26
|
// src/builder.ts
|
27
27
|
import { mergeErrorMap as mergeErrorMap2, mergeMeta as mergeMeta2, mergePrefix, mergeRoute as mergeRoute2, mergeTags } from "@orpc/contract";
|
@@ -50,10 +50,14 @@ function decorateMiddleware(middleware) {
|
|
50
50
|
decorated.concat = (concatMiddleware, mapInput) => {
|
51
51
|
const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
|
52
52
|
const concatted = decorateMiddleware((options, input, output, ...rest) => {
|
53
|
-
const
|
54
|
-
|
55
|
-
|
56
|
-
|
53
|
+
const merged = middleware({
|
54
|
+
...options,
|
55
|
+
next: (...[nextOptions1]) => mapped({
|
56
|
+
...options,
|
57
|
+
context: { ...options.context, ...nextOptions1?.context },
|
58
|
+
next: (...[nextOptions2]) => options.next({ context: { ...nextOptions1?.context, ...nextOptions2?.context } })
|
59
|
+
}, input, output, ...rest)
|
60
|
+
}, input, output, ...rest);
|
57
61
|
return merged;
|
58
62
|
});
|
59
63
|
return concatted;
|
@@ -357,7 +361,8 @@ function createRouterClient(router, ...rest) {
|
|
357
361
|
}
|
358
362
|
|
359
363
|
// src/index.ts
|
360
|
-
import { isDefinedError, ORPCError, safe, type, ValidationError } from "@orpc/contract";
|
364
|
+
import { eventIterator, isDefinedError, ORPCError, safe, type, ValidationError } from "@orpc/contract";
|
365
|
+
import { getEventMeta, withEventMeta } from "@orpc/server-standard";
|
361
366
|
import { onError, onFinish, onStart, onSuccess } from "@orpc/shared";
|
362
367
|
export {
|
363
368
|
Builder,
|
@@ -378,8 +383,10 @@ export {
|
|
378
383
|
deepSetLazyRouterPrefix,
|
379
384
|
eachAllContractProcedure,
|
380
385
|
eachContractProcedure,
|
386
|
+
eventIterator,
|
381
387
|
fallbackConfig,
|
382
388
|
flatLazy,
|
389
|
+
getEventMeta,
|
383
390
|
getLazyRouterPrefix,
|
384
391
|
getRouterChild,
|
385
392
|
getRouterContract,
|
@@ -399,6 +406,7 @@ export {
|
|
399
406
|
safe,
|
400
407
|
setRouterContract,
|
401
408
|
type,
|
402
|
-
unlazy
|
409
|
+
unlazy,
|
410
|
+
withEventMeta
|
403
411
|
};
|
404
412
|
//# sourceMappingURL=index.js.map
|
package/dist/next.js
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
import {
|
2
|
-
RPCHandler
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
import "./chunk-GIXDBJGV.js";
|
8
|
-
import "./chunk-XP6YRLY2.js";
|
9
|
-
import "./chunk-XFBAK67J.js";
|
2
|
+
RPCHandler
|
3
|
+
} from "./chunk-L4ESXQX7.js";
|
4
|
+
import "./chunk-NXEANHUK.js";
|
5
|
+
import "./chunk-XXBE6CYD.js";
|
6
|
+
import "./chunk-XI6WGCB3.js";
|
10
7
|
|
11
8
|
// src/adapters/next/serve.ts
|
12
9
|
import { value } from "@orpc/shared";
|
@@ -29,9 +26,6 @@ function serve(handler, ...[options]) {
|
|
29
26
|
}
|
30
27
|
export {
|
31
28
|
RPCHandler,
|
32
|
-
|
33
|
-
fetchRequestToStandardRequest,
|
34
|
-
serve,
|
35
|
-
standardResponseToFetchResponse
|
29
|
+
serve
|
36
30
|
};
|
37
31
|
//# sourceMappingURL=next.js.map
|
package/dist/node.js
CHANGED
@@ -2,149 +2,12 @@ import {
|
|
2
2
|
RPCCodec,
|
3
3
|
RPCMatcher,
|
4
4
|
StandardHandler
|
5
|
-
} from "./chunk-
|
6
|
-
import "./chunk-
|
7
|
-
import "./chunk-
|
8
|
-
|
9
|
-
// src/adapters/node/utils.ts
|
10
|
-
import { Buffer, File } from "node:buffer";
|
11
|
-
import { Readable } from "node:stream";
|
12
|
-
import { once } from "@orpc/shared";
|
13
|
-
import { contentDisposition, parse as parseContentDisposition } from "@tinyhttp/content-disposition";
|
14
|
-
function nodeHttpToStandardRequest(req, res) {
|
15
|
-
const method = req.method ?? "GET";
|
16
|
-
const protocol = "encrypted" in req.socket && req.socket.encrypted ? "https:" : "http:";
|
17
|
-
const host = req.headers.host ?? "localhost";
|
18
|
-
const url = new URL(req.originalUrl ?? req.url ?? "/", `${protocol}//${host}`);
|
19
|
-
return {
|
20
|
-
raw: { request: req, response: res },
|
21
|
-
method,
|
22
|
-
url,
|
23
|
-
headers: req.headers,
|
24
|
-
body: once(() => {
|
25
|
-
return nodeHttpRequestToStandardBody(req);
|
26
|
-
}),
|
27
|
-
get signal() {
|
28
|
-
const signal = nodeHttpResponseToAbortSignal(res);
|
29
|
-
Object.defineProperty(this, "signal", { value: signal, writable: true });
|
30
|
-
return signal;
|
31
|
-
},
|
32
|
-
set signal(value) {
|
33
|
-
Object.defineProperty(this, "signal", { value, writable: true });
|
34
|
-
}
|
35
|
-
};
|
36
|
-
}
|
37
|
-
function nodeHttpResponseSendStandardResponse(res, standardResponse) {
|
38
|
-
return new Promise((resolve, reject) => {
|
39
|
-
res.on("error", reject);
|
40
|
-
res.on("finish", resolve);
|
41
|
-
const resHeaders = standardResponse.headers;
|
42
|
-
delete resHeaders["content-type"];
|
43
|
-
delete resHeaders["content-disposition"];
|
44
|
-
if (standardResponse.body === void 0) {
|
45
|
-
res.writeHead(standardResponse.status, standardResponse.headers);
|
46
|
-
res.end();
|
47
|
-
return;
|
48
|
-
}
|
49
|
-
if (standardResponse.body instanceof Blob) {
|
50
|
-
resHeaders["content-type"] = standardResponse.body.type;
|
51
|
-
resHeaders["content-length"] = standardResponse.body.size.toString();
|
52
|
-
resHeaders["content-disposition"] = contentDisposition(
|
53
|
-
standardResponse.body instanceof File ? standardResponse.body.name : "blob",
|
54
|
-
{ type: "inline" }
|
55
|
-
);
|
56
|
-
res.writeHead(standardResponse.status, resHeaders);
|
57
|
-
Readable.fromWeb(
|
58
|
-
standardResponse.body.stream()
|
59
|
-
// Conflict between types=node and lib=dom so we need to cast it
|
60
|
-
).pipe(res);
|
61
|
-
return;
|
62
|
-
}
|
63
|
-
if (standardResponse.body instanceof FormData) {
|
64
|
-
const response = new Response(standardResponse.body);
|
65
|
-
resHeaders["content-type"] = response.headers.get("content-type");
|
66
|
-
res.writeHead(standardResponse.status, resHeaders);
|
67
|
-
Readable.fromWeb(
|
68
|
-
response.body
|
69
|
-
// Conflict between types=node and lib=dom so we need to cast it
|
70
|
-
).pipe(res);
|
71
|
-
return;
|
72
|
-
}
|
73
|
-
if (standardResponse.body instanceof URLSearchParams) {
|
74
|
-
resHeaders["content-type"] = "application/x-www-form-urlencoded";
|
75
|
-
res.writeHead(standardResponse.status, resHeaders);
|
76
|
-
res.end(standardResponse.body.toString());
|
77
|
-
return;
|
78
|
-
}
|
79
|
-
resHeaders["content-type"] = "application/json";
|
80
|
-
res.writeHead(standardResponse.status, resHeaders);
|
81
|
-
res.end(JSON.stringify(standardResponse.body));
|
82
|
-
});
|
83
|
-
}
|
84
|
-
async function nodeHttpRequestToStandardBody(req) {
|
85
|
-
const method = req.method ?? "GET";
|
86
|
-
if (method === "GET" || method === "HEAD") {
|
87
|
-
return void 0;
|
88
|
-
}
|
89
|
-
const contentDisposition2 = req.headers["content-disposition"];
|
90
|
-
const contentType = req.headers["content-type"];
|
91
|
-
if (contentDisposition2) {
|
92
|
-
const fileName = parseContentDisposition(contentDisposition2).parameters.filename;
|
93
|
-
if (typeof fileName === "string") {
|
94
|
-
return await streamToFile(req, fileName, contentType || "application/octet-stream");
|
95
|
-
}
|
96
|
-
}
|
97
|
-
if (!contentType || contentType.startsWith("application/json")) {
|
98
|
-
const text = await streamToString(req);
|
99
|
-
if (!text) {
|
100
|
-
return void 0;
|
101
|
-
}
|
102
|
-
return JSON.parse(text);
|
103
|
-
}
|
104
|
-
if (contentType.startsWith("multipart/form-data")) {
|
105
|
-
return await streamToFormData(req, contentType);
|
106
|
-
}
|
107
|
-
if (contentType.startsWith("application/x-www-form-urlencoded")) {
|
108
|
-
const text = await streamToString(req);
|
109
|
-
return new URLSearchParams(text);
|
110
|
-
}
|
111
|
-
if (contentType.startsWith("text/")) {
|
112
|
-
return await streamToString(req);
|
113
|
-
}
|
114
|
-
return streamToFile(req, "blob", contentType);
|
115
|
-
}
|
116
|
-
function streamToFormData(stream, contentType) {
|
117
|
-
const response = new Response(stream, {
|
118
|
-
// Conflict between types=node and lib=dom so we need to cast it
|
119
|
-
headers: {
|
120
|
-
"content-type": contentType
|
121
|
-
}
|
122
|
-
});
|
123
|
-
return response.formData();
|
124
|
-
}
|
125
|
-
async function streamToString(stream) {
|
126
|
-
let string = "";
|
127
|
-
for await (const chunk of stream) {
|
128
|
-
string += chunk.toString();
|
129
|
-
}
|
130
|
-
return string;
|
131
|
-
}
|
132
|
-
async function streamToFile(stream, fileName, contentType) {
|
133
|
-
const chunks = [];
|
134
|
-
for await (const chunk of stream) {
|
135
|
-
chunks.push(chunk);
|
136
|
-
}
|
137
|
-
return new File([Buffer.concat(chunks)], fileName, { type: contentType });
|
138
|
-
}
|
139
|
-
function nodeHttpResponseToAbortSignal(res) {
|
140
|
-
const controller = new AbortController();
|
141
|
-
res.on("close", () => {
|
142
|
-
controller.abort();
|
143
|
-
});
|
144
|
-
return controller.signal;
|
145
|
-
}
|
5
|
+
} from "./chunk-NXEANHUK.js";
|
6
|
+
import "./chunk-XXBE6CYD.js";
|
7
|
+
import "./chunk-XI6WGCB3.js";
|
146
8
|
|
147
9
|
// src/adapters/node/rpc-handler.ts
|
10
|
+
import { sendStandardResponse, toStandardRequest } from "@orpc/server-standard-node";
|
148
11
|
var RPCHandler = class {
|
149
12
|
standardHandler;
|
150
13
|
constructor(router, options) {
|
@@ -153,18 +16,16 @@ var RPCHandler = class {
|
|
153
16
|
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
154
17
|
}
|
155
18
|
async handle(req, res, ...rest) {
|
156
|
-
const standardRequest =
|
19
|
+
const standardRequest = toStandardRequest(req, res);
|
157
20
|
const result = await this.standardHandler.handle(standardRequest, ...rest);
|
158
21
|
if (!result.matched) {
|
159
22
|
return { matched: false };
|
160
23
|
}
|
161
|
-
await
|
24
|
+
await sendStandardResponse(res, result.response);
|
162
25
|
return { matched: true };
|
163
26
|
}
|
164
27
|
};
|
165
28
|
export {
|
166
|
-
RPCHandler
|
167
|
-
nodeHttpResponseSendStandardResponse,
|
168
|
-
nodeHttpToStandardRequest
|
29
|
+
RPCHandler
|
169
30
|
};
|
170
31
|
//# sourceMappingURL=node.js.map
|
package/dist/plugins.js
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
import type { ErrorMap, HTTPPath, Meta, Schema } from '@orpc/contract';
|
2
|
+
import type { StandardRequest, StandardResponse } from '@orpc/server-standard';
|
2
3
|
import type { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
3
4
|
import type { Context } from '../../context';
|
4
5
|
import type { Plugin } from '../../plugins';
|
5
6
|
import type { CreateProcedureClientOptions } from '../../procedure-client';
|
6
7
|
import type { Router } from '../../router';
|
7
|
-
import type { StandardCodec, StandardMatcher
|
8
|
+
import type { StandardCodec, StandardMatcher } from './types';
|
8
9
|
export type StandardHandleOptions<T extends Context> = {
|
9
10
|
prefix?: HTTPPath;
|
10
11
|
} & (Record<never, never> extends T ? {
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import type { ORPCError } from '@orpc/contract';
|
2
|
+
import type { StandardRequest, StandardResponse } from '@orpc/server-standard';
|
2
3
|
import type { AnyProcedure } from '../../procedure';
|
3
|
-
import type { StandardCodec, StandardParams
|
4
|
+
import type { StandardCodec, StandardParams } from './types';
|
4
5
|
import { RPCSerializer } from './rpc-serializer';
|
5
6
|
export interface StandardCodecOptions {
|
6
7
|
serializer?: RPCSerializer;
|
@@ -3,7 +3,13 @@ export type RPCSerializedJsonMeta = ['bigint' | 'date' | 'nan' | 'undefined' | '
|
|
3
3
|
export type RPCSerialized = {
|
4
4
|
json: unknown;
|
5
5
|
meta: RPCSerializedJsonMeta;
|
6
|
-
} | FormData |
|
6
|
+
} | FormData | AsyncIteratorObject<{
|
7
|
+
json: unknown;
|
8
|
+
meta: RPCSerializedJsonMeta;
|
9
|
+
}, {
|
10
|
+
json: unknown;
|
11
|
+
meta: RPCSerializedJsonMeta;
|
12
|
+
}, void>;
|
7
13
|
export type RPCSerializedFormDataMaps = Segment[][];
|
8
14
|
export declare class RPCSerializer {
|
9
15
|
serialize(data: unknown): RPCSerialized;
|
@@ -1,31 +1,7 @@
|
|
1
1
|
import type { HTTPPath, ORPCError } from '@orpc/contract';
|
2
|
-
import type {
|
2
|
+
import type { StandardRequest, StandardResponse } from '@orpc/server-standard';
|
3
3
|
import type { AnyProcedure } from '../../procedure';
|
4
4
|
import type { AnyRouter } from '../../router';
|
5
|
-
export interface StandardHeaders {
|
6
|
-
[key: string]: string | string[] | undefined;
|
7
|
-
}
|
8
|
-
export type StandardBody = undefined | JsonValue | Blob | URLSearchParams | FormData;
|
9
|
-
export interface StandardRequest {
|
10
|
-
/**
|
11
|
-
* Can be { request: Request } or { request: IncomingMessage, response: ServerResponse } based on the adapter.
|
12
|
-
*/
|
13
|
-
raw: Record<string, unknown>;
|
14
|
-
method: string;
|
15
|
-
url: URL;
|
16
|
-
headers: StandardHeaders;
|
17
|
-
/**
|
18
|
-
* The body has been parsed base on the content-type header.
|
19
|
-
* This method can safely call multiple times (cached).
|
20
|
-
*/
|
21
|
-
body(): Promise<StandardBody>;
|
22
|
-
signal?: AbortSignal;
|
23
|
-
}
|
24
|
-
export interface StandardResponse {
|
25
|
-
status: number;
|
26
|
-
headers: StandardHeaders;
|
27
|
-
body: StandardBody;
|
28
|
-
}
|
29
5
|
export type StandardParams = Record<string, string>;
|
30
6
|
export type StandardMatchResult = {
|
31
7
|
path: string[];
|
package/dist/src/context.d.ts
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
import type { IsNever } from '@orpc/shared';
|
2
2
|
export type Context = Record<string, any>;
|
3
|
-
export type TypeInitialContext<T extends Context> = (type: T) => unknown;
|
4
3
|
export type MergedContext<T extends Context, U extends Context> = T & U;
|
5
4
|
export declare function mergeContext<T extends Context, U extends Context>(context: T, other: U): MergedContext<T, U>;
|
6
5
|
export type ConflictContextGuard<T extends Context> = true extends IsNever<T> | {
|
package/dist/src/index.d.ts
CHANGED
@@ -18,6 +18,7 @@ export * from './router';
|
|
18
18
|
export * from './router-accessible-lazy';
|
19
19
|
export * from './router-client';
|
20
20
|
export * from './utils';
|
21
|
-
export { isDefinedError, ORPCError, safe, type, ValidationError } from '@orpc/contract';
|
21
|
+
export { eventIterator, isDefinedError, ORPCError, safe, type, ValidationError } from '@orpc/contract';
|
22
|
+
export { getEventMeta, withEventMeta } from '@orpc/server-standard';
|
22
23
|
export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
23
24
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/middleware.d.ts
CHANGED
@@ -22,6 +22,7 @@ export interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorCo
|
|
22
22
|
path: string[];
|
23
23
|
procedure: Procedure<Context, Context, Schema, Schema, unknown, ErrorMap, TMeta>;
|
24
24
|
signal?: AbortSignal;
|
25
|
+
lastEventId: string | undefined;
|
25
26
|
next: MiddlewareNextFn<TInContext, TOutput>;
|
26
27
|
errors: TErrorConstructorMap;
|
27
28
|
}
|
@@ -11,6 +11,7 @@ export interface ProcedureClientInterceptorOptions<TInitialContext extends Conte
|
|
11
11
|
path: string[];
|
12
12
|
procedure: Procedure<Context, Context, Schema, Schema, unknown, ErrorMap, TMeta>;
|
13
13
|
signal?: AbortSignal;
|
14
|
+
lastEventId: string | undefined;
|
14
15
|
}
|
15
16
|
/**
|
16
17
|
* Options for creating a procedure caller with comprehensive type safety
|
package/dist/src/procedure.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { ContractProcedureDef, ErrorMap, Meta, ORPCErrorConstructorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
2
|
import type { Promisable } from '@orpc/shared';
|
3
|
-
import type { Context
|
3
|
+
import type { Context } from './context';
|
4
4
|
import type { AnyMiddleware } from './middleware';
|
5
5
|
export interface ProcedureHandlerOptions<TCurrentContext extends Context, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
6
6
|
context: TCurrentContext;
|
@@ -8,13 +8,14 @@ export interface ProcedureHandlerOptions<TCurrentContext extends Context, TInput
|
|
8
8
|
path: string[];
|
9
9
|
procedure: Procedure<Context, Context, Schema, Schema, unknown, ErrorMap, TMeta>;
|
10
10
|
signal?: AbortSignal;
|
11
|
+
lastEventId: string | undefined;
|
11
12
|
errors: TErrorConstructorMap;
|
12
13
|
}
|
13
14
|
export interface ProcedureHandler<TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
14
15
|
(opt: ProcedureHandlerOptions<TCurrentContext, SchemaOutput<TInputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): Promisable<SchemaInput<TOutputSchema, THandlerOutput>>;
|
15
16
|
}
|
16
17
|
export interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
17
|
-
__initialContext?:
|
18
|
+
__initialContext?: (type: TInitialContext) => unknown;
|
18
19
|
middlewares: AnyMiddleware[];
|
19
20
|
inputValidationIndex: number;
|
20
21
|
outputValidationIndex: number;
|
package/dist/standard.js
CHANGED
@@ -4,9 +4,9 @@ import {
|
|
4
4
|
RPCSerializer,
|
5
5
|
StandardHandler,
|
6
6
|
serializeRPCJson
|
7
|
-
} from "./chunk-
|
8
|
-
import "./chunk-
|
9
|
-
import "./chunk-
|
7
|
+
} from "./chunk-NXEANHUK.js";
|
8
|
+
import "./chunk-XXBE6CYD.js";
|
9
|
+
import "./chunk-XI6WGCB3.js";
|
10
10
|
export {
|
11
11
|
RPCCodec,
|
12
12
|
RPCMatcher,
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/server",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.
|
4
|
+
"version": "0.40.0",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -63,9 +63,11 @@
|
|
63
63
|
"next": ">=14.0.0"
|
64
64
|
},
|
65
65
|
"dependencies": {
|
66
|
-
"@
|
67
|
-
"@orpc/
|
68
|
-
"@orpc/
|
66
|
+
"@orpc/server-standard": "^0.4.0",
|
67
|
+
"@orpc/server-standard-fetch": "^0.4.0",
|
68
|
+
"@orpc/server-standard-node": "^0.4.0",
|
69
|
+
"@orpc/contract": "0.40.0",
|
70
|
+
"@orpc/shared": "0.40.0"
|
69
71
|
},
|
70
72
|
"devDependencies": {
|
71
73
|
"light-my-request": "^6.5.1"
|
package/dist/chunk-WJ2G7572.js
DELETED
@@ -1,145 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
RPCCodec,
|
3
|
-
RPCMatcher,
|
4
|
-
StandardHandler
|
5
|
-
} from "./chunk-GIXDBJGV.js";
|
6
|
-
|
7
|
-
// src/adapters/fetch/utils.ts
|
8
|
-
import { once } from "@orpc/shared";
|
9
|
-
import { contentDisposition, parse as parseContentDisposition } from "@tinyhttp/content-disposition";
|
10
|
-
function fetchHeadersToStandardHeaders(headers) {
|
11
|
-
const standardHeaders = {};
|
12
|
-
for (const [key, value] of headers) {
|
13
|
-
if (Array.isArray(standardHeaders[key])) {
|
14
|
-
standardHeaders[key].push(value);
|
15
|
-
} else if (standardHeaders[key] !== void 0) {
|
16
|
-
standardHeaders[key] = [standardHeaders[key], value];
|
17
|
-
} else {
|
18
|
-
standardHeaders[key] = value;
|
19
|
-
}
|
20
|
-
}
|
21
|
-
return standardHeaders;
|
22
|
-
}
|
23
|
-
async function fetchReToStandardBody(re) {
|
24
|
-
if (!re.body) {
|
25
|
-
return void 0;
|
26
|
-
}
|
27
|
-
const contentDisposition2 = re.headers.get("content-disposition");
|
28
|
-
if (contentDisposition2) {
|
29
|
-
const fileName = parseContentDisposition(contentDisposition2).parameters.filename;
|
30
|
-
if (typeof fileName === "string") {
|
31
|
-
const blob2 = await re.blob();
|
32
|
-
return new File([blob2], fileName, {
|
33
|
-
type: blob2.type
|
34
|
-
});
|
35
|
-
}
|
36
|
-
}
|
37
|
-
const contentType = re.headers.get("content-type");
|
38
|
-
if (!contentType || contentType.startsWith("application/json")) {
|
39
|
-
const text = await re.text();
|
40
|
-
if (!text) {
|
41
|
-
return void 0;
|
42
|
-
}
|
43
|
-
return JSON.parse(text);
|
44
|
-
}
|
45
|
-
if (contentType.startsWith("multipart/form-data")) {
|
46
|
-
return await re.formData();
|
47
|
-
}
|
48
|
-
if (contentType.startsWith("application/x-www-form-urlencoded")) {
|
49
|
-
return new URLSearchParams(await re.text());
|
50
|
-
}
|
51
|
-
if (contentType.startsWith("text/")) {
|
52
|
-
return await re.text();
|
53
|
-
}
|
54
|
-
const blob = await re.blob();
|
55
|
-
return new File([blob], "blob", {
|
56
|
-
type: blob.type
|
57
|
-
});
|
58
|
-
}
|
59
|
-
function fetchRequestToStandardRequest(request) {
|
60
|
-
const url = new URL(request.url);
|
61
|
-
return {
|
62
|
-
raw: { request },
|
63
|
-
url,
|
64
|
-
signal: request.signal,
|
65
|
-
method: request.method,
|
66
|
-
body: once(() => {
|
67
|
-
return fetchReToStandardBody(request);
|
68
|
-
}),
|
69
|
-
get headers() {
|
70
|
-
const headers = fetchHeadersToStandardHeaders(request.headers);
|
71
|
-
Object.defineProperty(this, "headers", { value: headers, writable: true });
|
72
|
-
return headers;
|
73
|
-
},
|
74
|
-
set headers(value) {
|
75
|
-
Object.defineProperty(this, "headers", { value, writable: true });
|
76
|
-
}
|
77
|
-
};
|
78
|
-
}
|
79
|
-
function standardResponseToFetchHeaders(response) {
|
80
|
-
const fetchHeaders = new Headers();
|
81
|
-
for (const [key, value] of Object.entries(response.headers)) {
|
82
|
-
if (Array.isArray(value)) {
|
83
|
-
for (const v of value) {
|
84
|
-
fetchHeaders.append(key, v);
|
85
|
-
}
|
86
|
-
} else if (value !== void 0) {
|
87
|
-
fetchHeaders.append(key, value);
|
88
|
-
}
|
89
|
-
}
|
90
|
-
return fetchHeaders;
|
91
|
-
}
|
92
|
-
function standardResponseToFetchResponse(response) {
|
93
|
-
const resHeaders = standardResponseToFetchHeaders(response);
|
94
|
-
resHeaders.delete("content-type");
|
95
|
-
resHeaders.delete("content-disposition");
|
96
|
-
if (response.body === void 0) {
|
97
|
-
return new Response(void 0, { headers: resHeaders, status: response.status });
|
98
|
-
}
|
99
|
-
if (response.body instanceof Blob) {
|
100
|
-
resHeaders.set("content-type", response.body.type);
|
101
|
-
resHeaders.set("content-length", response.body.size.toString());
|
102
|
-
resHeaders.set(
|
103
|
-
"content-disposition",
|
104
|
-
contentDisposition(response.body instanceof File ? response.body.name : "blob", { type: "inline" })
|
105
|
-
);
|
106
|
-
return new Response(response.body, { headers: resHeaders, status: response.status });
|
107
|
-
}
|
108
|
-
if (response.body instanceof FormData) {
|
109
|
-
return new Response(response.body, { headers: resHeaders, status: response.status });
|
110
|
-
}
|
111
|
-
if (response.body instanceof URLSearchParams) {
|
112
|
-
return new Response(response.body, { headers: resHeaders, status: response.status });
|
113
|
-
}
|
114
|
-
resHeaders.set("content-type", "application/json");
|
115
|
-
return new Response(JSON.stringify(response.body), { headers: resHeaders, status: response.status });
|
116
|
-
}
|
117
|
-
|
118
|
-
// src/adapters/fetch/rpc-handler.ts
|
119
|
-
var RPCHandler = class {
|
120
|
-
standardHandler;
|
121
|
-
constructor(router, options) {
|
122
|
-
const matcher = options?.matcher ?? new RPCMatcher();
|
123
|
-
const codec = options?.codec ?? new RPCCodec();
|
124
|
-
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
125
|
-
}
|
126
|
-
async handle(request, ...rest) {
|
127
|
-
const standardRequest = fetchRequestToStandardRequest(request);
|
128
|
-
const result = await this.standardHandler.handle(standardRequest, ...rest);
|
129
|
-
if (!result.matched) {
|
130
|
-
return result;
|
131
|
-
}
|
132
|
-
return {
|
133
|
-
matched: true,
|
134
|
-
response: standardResponseToFetchResponse(result.response)
|
135
|
-
};
|
136
|
-
}
|
137
|
-
};
|
138
|
-
|
139
|
-
export {
|
140
|
-
fetchReToStandardBody,
|
141
|
-
fetchRequestToStandardRequest,
|
142
|
-
standardResponseToFetchResponse,
|
143
|
-
RPCHandler
|
144
|
-
};
|
145
|
-
//# sourceMappingURL=chunk-WJ2G7572.js.map
|
@@ -1,5 +0,0 @@
|
|
1
|
-
import type { StandardBody, StandardRequest, StandardResponse } from '../standard';
|
2
|
-
export declare function fetchReToStandardBody(re: Request | Response): Promise<StandardBody>;
|
3
|
-
export declare function fetchRequestToStandardRequest(request: Request): StandardRequest;
|
4
|
-
export declare function standardResponseToFetchResponse(response: StandardResponse): Response;
|
5
|
-
//# sourceMappingURL=utils.d.ts.map
|
@@ -1,5 +0,0 @@
|
|
1
|
-
import type { StandardRequest, StandardResponse } from '../standard';
|
2
|
-
import type { NodeHttpRequest, NodeHttpResponse } from './types';
|
3
|
-
export declare function nodeHttpToStandardRequest(req: NodeHttpRequest, res: NodeHttpResponse): StandardRequest;
|
4
|
-
export declare function nodeHttpResponseSendStandardResponse(res: NodeHttpResponse, standardResponse: StandardResponse): Promise<void>;
|
5
|
-
//# sourceMappingURL=utils.d.ts.map
|