@orpc/standard-server-node 0.0.0-next.ee89076 → 0.0.0-next.f01f7b1
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 +5 -2
- package/dist/index.d.mts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.mjs +19 -6
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<image align="center" src="https://orpc.
|
|
2
|
+
<image align="center" src="https://orpc.dev/logo.webp" width=280 alt="oRPC logo" />
|
|
3
3
|
</div>
|
|
4
4
|
|
|
5
5
|
<h1></h1>
|
|
@@ -17,6 +17,9 @@
|
|
|
17
17
|
<a href="https://discord.gg/TXEbwRBvQn">
|
|
18
18
|
<img alt="Discord" src="https://img.shields.io/discord/1308966753044398161?color=7389D8&label&logo=discord&logoColor=ffffff" />
|
|
19
19
|
</a>
|
|
20
|
+
<a href="https://deepwiki.com/unnoq/orpc">
|
|
21
|
+
<img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki">
|
|
22
|
+
</a>
|
|
20
23
|
</div>
|
|
21
24
|
|
|
22
25
|
<h3 align="center">Typesafe APIs Made Simple 🪄</h3>
|
|
@@ -42,7 +45,7 @@
|
|
|
42
45
|
|
|
43
46
|
## Documentation
|
|
44
47
|
|
|
45
|
-
You can find the full documentation [here](https://orpc.
|
|
48
|
+
You can find the full documentation [here](https://orpc.dev).
|
|
46
49
|
|
|
47
50
|
## Packages
|
|
48
51
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { StandardBody, StandardHeaders, StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
|
|
2
2
|
import { ToEventIteratorOptions as ToEventIteratorOptions$1, ToEventStreamOptions as ToEventStreamOptions$1 } from '@orpc/standard-server-fetch';
|
|
3
3
|
import Stream, { Readable } from 'node:stream';
|
|
4
|
-
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
4
|
+
import { IncomingMessage, ServerResponse, OutgoingHttpHeaders } from 'node:http';
|
|
5
5
|
import { Http2ServerRequest, Http2ServerResponse } from 'node:http2';
|
|
6
6
|
|
|
7
7
|
interface ToEventIteratorOptions extends ToEventIteratorOptions$1 {
|
|
@@ -17,6 +17,10 @@ type NodeHttpRequest = (IncomingMessage | Http2ServerRequest) & {
|
|
|
17
17
|
* This is useful for `express.js` middleware.
|
|
18
18
|
*/
|
|
19
19
|
originalUrl?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Prefer parsed body if it is available.
|
|
22
|
+
*/
|
|
23
|
+
body?: unknown;
|
|
20
24
|
};
|
|
21
25
|
type NodeHttpResponse = ServerResponse | Http2ServerResponse;
|
|
22
26
|
|
|
@@ -32,6 +36,8 @@ interface ToNodeHttpBodyOptions extends ToEventStreamOptions {
|
|
|
32
36
|
*/
|
|
33
37
|
declare function toNodeHttpBody(body: StandardBody, headers: StandardHeaders, options?: ToNodeHttpBodyOptions): Readable | undefined | string;
|
|
34
38
|
|
|
39
|
+
declare function toNodeHttpHeaders(headers: StandardHeaders): OutgoingHttpHeaders;
|
|
40
|
+
|
|
35
41
|
declare function toStandardMethod(method: string | undefined): string;
|
|
36
42
|
|
|
37
43
|
declare function toStandardLazyRequest(req: NodeHttpRequest, res: NodeHttpResponse): StandardLazyRequest;
|
|
@@ -44,5 +50,5 @@ declare function toAbortSignal(stream: Stream.Writable): AbortSignal;
|
|
|
44
50
|
|
|
45
51
|
declare function toStandardUrl(req: NodeHttpRequest): URL;
|
|
46
52
|
|
|
47
|
-
export { sendStandardResponse, toAbortSignal, toEventIterator, toEventStream, toNodeHttpBody, toStandardBody, toStandardLazyRequest, toStandardMethod, toStandardUrl };
|
|
53
|
+
export { sendStandardResponse, toAbortSignal, toEventIterator, toEventStream, toNodeHttpBody, toNodeHttpHeaders, toStandardBody, toStandardLazyRequest, toStandardMethod, toStandardUrl };
|
|
48
54
|
export type { NodeHttpRequest, NodeHttpResponse, SendStandardResponseOptions, ToEventIteratorOptions, ToEventStreamOptions, ToNodeHttpBodyOptions, ToStandardBodyOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { StandardBody, StandardHeaders, StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
|
|
2
2
|
import { ToEventIteratorOptions as ToEventIteratorOptions$1, ToEventStreamOptions as ToEventStreamOptions$1 } from '@orpc/standard-server-fetch';
|
|
3
3
|
import Stream, { Readable } from 'node:stream';
|
|
4
|
-
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
4
|
+
import { IncomingMessage, ServerResponse, OutgoingHttpHeaders } from 'node:http';
|
|
5
5
|
import { Http2ServerRequest, Http2ServerResponse } from 'node:http2';
|
|
6
6
|
|
|
7
7
|
interface ToEventIteratorOptions extends ToEventIteratorOptions$1 {
|
|
@@ -17,6 +17,10 @@ type NodeHttpRequest = (IncomingMessage | Http2ServerRequest) & {
|
|
|
17
17
|
* This is useful for `express.js` middleware.
|
|
18
18
|
*/
|
|
19
19
|
originalUrl?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Prefer parsed body if it is available.
|
|
22
|
+
*/
|
|
23
|
+
body?: unknown;
|
|
20
24
|
};
|
|
21
25
|
type NodeHttpResponse = ServerResponse | Http2ServerResponse;
|
|
22
26
|
|
|
@@ -32,6 +36,8 @@ interface ToNodeHttpBodyOptions extends ToEventStreamOptions {
|
|
|
32
36
|
*/
|
|
33
37
|
declare function toNodeHttpBody(body: StandardBody, headers: StandardHeaders, options?: ToNodeHttpBodyOptions): Readable | undefined | string;
|
|
34
38
|
|
|
39
|
+
declare function toNodeHttpHeaders(headers: StandardHeaders): OutgoingHttpHeaders;
|
|
40
|
+
|
|
35
41
|
declare function toStandardMethod(method: string | undefined): string;
|
|
36
42
|
|
|
37
43
|
declare function toStandardLazyRequest(req: NodeHttpRequest, res: NodeHttpResponse): StandardLazyRequest;
|
|
@@ -44,5 +50,5 @@ declare function toAbortSignal(stream: Stream.Writable): AbortSignal;
|
|
|
44
50
|
|
|
45
51
|
declare function toStandardUrl(req: NodeHttpRequest): URL;
|
|
46
52
|
|
|
47
|
-
export { sendStandardResponse, toAbortSignal, toEventIterator, toEventStream, toNodeHttpBody, toStandardBody, toStandardLazyRequest, toStandardMethod, toStandardUrl };
|
|
53
|
+
export { sendStandardResponse, toAbortSignal, toEventIterator, toEventStream, toNodeHttpBody, toNodeHttpHeaders, toStandardBody, toStandardLazyRequest, toStandardMethod, toStandardUrl };
|
|
48
54
|
export type { NodeHttpRequest, NodeHttpResponse, SendStandardResponseOptions, ToEventIteratorOptions, ToEventStreamOptions, ToNodeHttpBodyOptions, ToStandardBodyOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Readable } from 'node:stream';
|
|
2
|
-
import { runWithSpan, parseEmptyableJSON, isAsyncIteratorObject, stringifyJSON, AbortError, once } from '@orpc/shared';
|
|
2
|
+
import { runWithSpan, parseEmptyableJSON, isAsyncIteratorObject, stringifyJSON, AbortError, guard, once } from '@orpc/shared';
|
|
3
3
|
import { getFilenameFromContentDisposition, flattenHeader, generateContentDisposition } from '@orpc/standard-server';
|
|
4
4
|
import { toEventIterator as toEventIterator$1, toEventStream as toEventStream$1 } from '@orpc/standard-server-fetch';
|
|
5
5
|
|
|
@@ -11,6 +11,9 @@ function toEventStream(iterator, options = {}) {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
function toStandardBody(req, options = {}) {
|
|
14
|
+
if (req.body !== void 0) {
|
|
15
|
+
return Promise.resolve(req.body);
|
|
16
|
+
}
|
|
14
17
|
return runWithSpan({ name: "parse_standard_body", signal: options.signal }, async () => {
|
|
15
18
|
const contentDisposition = req.headers["content-disposition"];
|
|
16
19
|
const contentType = req.headers["content-type"];
|
|
@@ -90,6 +93,16 @@ async function _streamToFile(stream, fileName, contentType) {
|
|
|
90
93
|
return new File(chunks, fileName, { type: contentType });
|
|
91
94
|
}
|
|
92
95
|
|
|
96
|
+
function toNodeHttpHeaders(headers) {
|
|
97
|
+
const nodeHttpHeaders = {};
|
|
98
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
99
|
+
if (value !== void 0) {
|
|
100
|
+
nodeHttpHeaders[key] = value;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return nodeHttpHeaders;
|
|
104
|
+
}
|
|
105
|
+
|
|
93
106
|
function toStandardMethod(method) {
|
|
94
107
|
return method ?? "GET";
|
|
95
108
|
}
|
|
@@ -107,9 +120,9 @@ function toAbortSignal(stream) {
|
|
|
107
120
|
|
|
108
121
|
function toStandardUrl(req) {
|
|
109
122
|
const protocol = "encrypted" in req.socket && req.socket.encrypted ? "https:" : "http:";
|
|
110
|
-
const
|
|
111
|
-
const
|
|
112
|
-
return
|
|
123
|
+
const origin = guard(() => new URL(`${protocol}//${req.headers.host ?? "localhost"}`).origin) ?? `${protocol}//localhost`;
|
|
124
|
+
const path = req.originalUrl ?? req.url ?? "/";
|
|
125
|
+
return new URL(`${origin}${path.startsWith("/") ? "" : "/"}${path}`);
|
|
113
126
|
}
|
|
114
127
|
|
|
115
128
|
function toStandardLazyRequest(req, res) {
|
|
@@ -129,7 +142,7 @@ function sendStandardResponse(res, standardResponse, options = {}) {
|
|
|
129
142
|
res.once("close", resolve);
|
|
130
143
|
const resHeaders = { ...standardResponse.headers };
|
|
131
144
|
const resBody = toNodeHttpBody(standardResponse.body, resHeaders, options);
|
|
132
|
-
res.writeHead(standardResponse.status, resHeaders);
|
|
145
|
+
res.writeHead(standardResponse.status, toNodeHttpHeaders(resHeaders));
|
|
133
146
|
if (resBody === void 0) {
|
|
134
147
|
res.end();
|
|
135
148
|
} else if (typeof resBody === "string") {
|
|
@@ -146,4 +159,4 @@ function sendStandardResponse(res, standardResponse, options = {}) {
|
|
|
146
159
|
});
|
|
147
160
|
}
|
|
148
161
|
|
|
149
|
-
export { sendStandardResponse, toAbortSignal, toEventIterator, toEventStream, toNodeHttpBody, toStandardBody, toStandardLazyRequest, toStandardMethod, toStandardUrl };
|
|
162
|
+
export { sendStandardResponse, toAbortSignal, toEventIterator, toEventStream, toNodeHttpBody, toNodeHttpHeaders, toStandardBody, toStandardLazyRequest, toStandardMethod, toStandardUrl };
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/standard-server-node",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.f01f7b1",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"homepage": "https://orpc.
|
|
6
|
+
"homepage": "https://orpc.dev",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "git+https://github.com/unnoq/orpc.git",
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"dist"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@orpc/shared": "0.0.0-next.
|
|
27
|
-
"@orpc/standard-server-fetch": "0.0.0-next.
|
|
28
|
-
"@orpc/standard-server": "0.0.0-next.
|
|
26
|
+
"@orpc/shared": "0.0.0-next.f01f7b1",
|
|
27
|
+
"@orpc/standard-server-fetch": "0.0.0-next.f01f7b1",
|
|
28
|
+
"@orpc/standard-server": "0.0.0-next.f01f7b1"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/node": "^22.15.30",
|