@temporary-name/standard-server-node 1.9.3-alpha.cf2fe368e72e6a6ab0ce041b812dbf8134f70b0b → 1.9.3-alpha.d0c8ba895f81e5ee5f2f893da0804bd96a5aa41c
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/index.d.mts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.mjs +31 -15
- package/package.json +5 -4
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { StandardBody,
|
|
1
|
+
import { StandardBody, StandardLazyRequest, StandardResponse } from '@temporary-name/shared';
|
|
2
2
|
import Stream, { Readable } from 'node:stream';
|
|
3
3
|
import { ToEventIteratorOptions as ToEventIteratorOptions$1, ToEventStreamOptions as ToEventStreamOptions$1 } from '@temporary-name/standard-server-fetch';
|
|
4
4
|
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
5
5
|
import { Http2ServerRequest, Http2ServerResponse } from 'node:http2';
|
|
6
|
+
import { IncomingHttpHeaders } from 'http';
|
|
6
7
|
|
|
7
8
|
interface ToEventIteratorOptions extends ToEventIteratorOptions$1 {
|
|
8
9
|
}
|
|
@@ -34,10 +35,11 @@ interface ToNodeHttpBodyOptions extends ToEventStreamOptions {
|
|
|
34
35
|
* @param headers - WARNING: The headers can be changed by the function and effects on the original headers.
|
|
35
36
|
* @param options
|
|
36
37
|
*/
|
|
37
|
-
declare function toNodeHttpBody(body: StandardBody, headers:
|
|
38
|
+
declare function toNodeHttpBody(body: StandardBody, headers: Headers, options?: ToNodeHttpBodyOptions): Readable | undefined | string;
|
|
38
39
|
|
|
39
40
|
declare function toStandardMethod(method: string | undefined): string;
|
|
40
41
|
|
|
42
|
+
declare function toStandardHeaders(headers: IncomingHttpHeaders): Headers;
|
|
41
43
|
declare function toStandardLazyRequest(req: NodeHttpRequest, res: NodeHttpResponse): StandardLazyRequest;
|
|
42
44
|
|
|
43
45
|
interface SendStandardResponseOptions extends ToNodeHttpBodyOptions {
|
|
@@ -48,5 +50,5 @@ declare function toAbortSignal(stream: Stream.Writable): AbortSignal;
|
|
|
48
50
|
|
|
49
51
|
declare function toStandardUrl(req: NodeHttpRequest): URL;
|
|
50
52
|
|
|
51
|
-
export { sendStandardResponse, toAbortSignal, toEventIterator, toEventStream, toNodeHttpBody, toStandardBody, toStandardLazyRequest, toStandardMethod, toStandardUrl };
|
|
53
|
+
export { sendStandardResponse, toAbortSignal, toEventIterator, toEventStream, toNodeHttpBody, toStandardBody, toStandardHeaders, toStandardLazyRequest, toStandardMethod, toStandardUrl };
|
|
52
54
|
export type { NodeHttpRequest, NodeHttpResponse, SendStandardResponseOptions, ToEventIteratorOptions, ToEventStreamOptions, ToNodeHttpBodyOptions, ToStandardBodyOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { StandardBody,
|
|
1
|
+
import { StandardBody, StandardLazyRequest, StandardResponse } from '@temporary-name/shared';
|
|
2
2
|
import Stream, { Readable } from 'node:stream';
|
|
3
3
|
import { ToEventIteratorOptions as ToEventIteratorOptions$1, ToEventStreamOptions as ToEventStreamOptions$1 } from '@temporary-name/standard-server-fetch';
|
|
4
4
|
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
5
5
|
import { Http2ServerRequest, Http2ServerResponse } from 'node:http2';
|
|
6
|
+
import { IncomingHttpHeaders } from 'http';
|
|
6
7
|
|
|
7
8
|
interface ToEventIteratorOptions extends ToEventIteratorOptions$1 {
|
|
8
9
|
}
|
|
@@ -34,10 +35,11 @@ interface ToNodeHttpBodyOptions extends ToEventStreamOptions {
|
|
|
34
35
|
* @param headers - WARNING: The headers can be changed by the function and effects on the original headers.
|
|
35
36
|
* @param options
|
|
36
37
|
*/
|
|
37
|
-
declare function toNodeHttpBody(body: StandardBody, headers:
|
|
38
|
+
declare function toNodeHttpBody(body: StandardBody, headers: Headers, options?: ToNodeHttpBodyOptions): Readable | undefined | string;
|
|
38
39
|
|
|
39
40
|
declare function toStandardMethod(method: string | undefined): string;
|
|
40
41
|
|
|
42
|
+
declare function toStandardHeaders(headers: IncomingHttpHeaders): Headers;
|
|
41
43
|
declare function toStandardLazyRequest(req: NodeHttpRequest, res: NodeHttpResponse): StandardLazyRequest;
|
|
42
44
|
|
|
43
45
|
interface SendStandardResponseOptions extends ToNodeHttpBodyOptions {
|
|
@@ -48,5 +50,5 @@ declare function toAbortSignal(stream: Stream.Writable): AbortSignal;
|
|
|
48
50
|
|
|
49
51
|
declare function toStandardUrl(req: NodeHttpRequest): URL;
|
|
50
52
|
|
|
51
|
-
export { sendStandardResponse, toAbortSignal, toEventIterator, toEventStream, toNodeHttpBody, toStandardBody, toStandardLazyRequest, toStandardMethod, toStandardUrl };
|
|
53
|
+
export { sendStandardResponse, toAbortSignal, toEventIterator, toEventStream, toNodeHttpBody, toStandardBody, toStandardHeaders, toStandardLazyRequest, toStandardMethod, toStandardUrl };
|
|
52
54
|
export type { NodeHttpRequest, NodeHttpResponse, SendStandardResponseOptions, ToEventIteratorOptions, ToEventStreamOptions, ToNodeHttpBodyOptions, ToStandardBodyOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { runWithSpan, parseEmptyableJSON, isAsyncIteratorObject, stringifyJSON, AbortError, guard, once } from '@temporary-name/shared';
|
|
2
|
-
import { getFilenameFromContentDisposition,
|
|
2
|
+
import { getFilenameFromContentDisposition, generateContentDisposition } from '@temporary-name/standard-server';
|
|
3
3
|
import { Readable } from 'node:stream';
|
|
4
4
|
import { toEventIterator as toEventIterator$1, toEventStream as toEventStream$1 } from '@temporary-name/standard-server-fetch';
|
|
5
5
|
|
|
@@ -42,32 +42,35 @@ function toStandardBody(req, options = {}) {
|
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
44
|
function toNodeHttpBody(body, headers, options = {}) {
|
|
45
|
-
const currentContentDisposition =
|
|
46
|
-
delete
|
|
47
|
-
delete
|
|
45
|
+
const currentContentDisposition = headers.get("content-disposition");
|
|
46
|
+
headers.delete("content-type");
|
|
47
|
+
headers.delete("content-disposition");
|
|
48
48
|
if (body === void 0) {
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
51
|
if (body instanceof Blob) {
|
|
52
|
-
headers
|
|
53
|
-
headers
|
|
54
|
-
headers
|
|
52
|
+
headers.set("content-type", body.type);
|
|
53
|
+
headers.set("content-length", body.size.toString());
|
|
54
|
+
headers.set(
|
|
55
|
+
"content-disposition",
|
|
56
|
+
currentContentDisposition ?? generateContentDisposition(body instanceof File ? body.name : "blob")
|
|
57
|
+
);
|
|
55
58
|
return Readable.fromWeb(body.stream());
|
|
56
59
|
}
|
|
57
60
|
if (body instanceof FormData) {
|
|
58
61
|
const response = new Response(body);
|
|
59
|
-
headers
|
|
62
|
+
headers.set("content-type", response.headers.get("content-type"));
|
|
60
63
|
return Readable.fromWeb(response.body);
|
|
61
64
|
}
|
|
62
65
|
if (body instanceof URLSearchParams) {
|
|
63
|
-
headers
|
|
66
|
+
headers.set("content-type", "application/x-www-form-urlencoded");
|
|
64
67
|
return body.toString();
|
|
65
68
|
}
|
|
66
69
|
if (isAsyncIteratorObject(body)) {
|
|
67
|
-
headers
|
|
70
|
+
headers.set("content-type", "text/event-stream");
|
|
68
71
|
return toEventStream(body, options);
|
|
69
72
|
}
|
|
70
|
-
headers
|
|
73
|
+
headers.set("content-type", "application/json");
|
|
71
74
|
return stringifyJSON(body);
|
|
72
75
|
}
|
|
73
76
|
function _streamToFormData(stream, contentType) {
|
|
@@ -115,12 +118,25 @@ function toStandardUrl(req) {
|
|
|
115
118
|
return new URL(`${origin}${path.startsWith("/") ? "" : "/"}${path}`);
|
|
116
119
|
}
|
|
117
120
|
|
|
121
|
+
function toStandardHeaders(headers) {
|
|
122
|
+
const standard = new Headers();
|
|
123
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
124
|
+
if (Array.isArray(value)) {
|
|
125
|
+
for (const item of value) {
|
|
126
|
+
standard.append(key, item);
|
|
127
|
+
}
|
|
128
|
+
} else if (value !== void 0) {
|
|
129
|
+
standard.set(key, value);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return standard;
|
|
133
|
+
}
|
|
118
134
|
function toStandardLazyRequest(req, res) {
|
|
119
135
|
const signal = toAbortSignal(res);
|
|
120
136
|
return {
|
|
121
137
|
method: toStandardMethod(req.method),
|
|
122
138
|
url: toStandardUrl(req),
|
|
123
|
-
headers: req.headers,
|
|
139
|
+
headers: toStandardHeaders(req.headers),
|
|
124
140
|
body: once(() => toStandardBody(req, { signal })),
|
|
125
141
|
signal
|
|
126
142
|
};
|
|
@@ -130,9 +146,9 @@ function sendStandardResponse(res, standardResponse, options = {}) {
|
|
|
130
146
|
return new Promise((resolve, reject) => {
|
|
131
147
|
res.once("error", reject);
|
|
132
148
|
res.once("close", resolve);
|
|
133
|
-
const resHeaders =
|
|
149
|
+
const resHeaders = new Headers(standardResponse.headers);
|
|
134
150
|
const resBody = toNodeHttpBody(standardResponse.body, resHeaders, options);
|
|
135
|
-
res.writeHead(standardResponse.status, resHeaders);
|
|
151
|
+
res.writeHead(standardResponse.status, Object.fromEntries(resHeaders));
|
|
136
152
|
if (resBody === void 0) {
|
|
137
153
|
res.end();
|
|
138
154
|
} else if (typeof resBody === "string") {
|
|
@@ -149,4 +165,4 @@ function sendStandardResponse(res, standardResponse, options = {}) {
|
|
|
149
165
|
});
|
|
150
166
|
}
|
|
151
167
|
|
|
152
|
-
export { sendStandardResponse, toAbortSignal, toEventIterator, toEventStream, toNodeHttpBody, toStandardBody, toStandardLazyRequest, toStandardMethod, toStandardUrl };
|
|
168
|
+
export { sendStandardResponse, toAbortSignal, toEventIterator, toEventStream, toNodeHttpBody, toStandardBody, toStandardHeaders, toStandardLazyRequest, toStandardMethod, toStandardUrl };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@temporary-name/standard-server-node",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.9.3-alpha.
|
|
4
|
+
"version": "1.9.3-alpha.d0c8ba895f81e5ee5f2f893da0804bd96a5aa41c",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://www.stainless.com/",
|
|
7
7
|
"repository": {
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"dist"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@temporary-name/shared": "1.9.3-alpha.
|
|
27
|
-
"@temporary-name/standard-server": "1.9.3-alpha.
|
|
28
|
-
"@temporary-name/standard-server-fetch": "1.9.3-alpha.
|
|
26
|
+
"@temporary-name/shared": "1.9.3-alpha.d0c8ba895f81e5ee5f2f893da0804bd96a5aa41c",
|
|
27
|
+
"@temporary-name/standard-server": "1.9.3-alpha.d0c8ba895f81e5ee5f2f893da0804bd96a5aa41c",
|
|
28
|
+
"@temporary-name/standard-server-fetch": "1.9.3-alpha.d0c8ba895f81e5ee5f2f893da0804bd96a5aa41c"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/node": "^22.15.30",
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "unbuild",
|
|
37
37
|
"build:watch": "pnpm run build --watch",
|
|
38
|
+
"clean": "tsc -b --clean",
|
|
38
39
|
"type:check": "tsc -b"
|
|
39
40
|
}
|
|
40
41
|
}
|