@orpc/standard-server-node 1.14.10 → 1.14.12
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 +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.mjs +31 -7
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -46,9 +46,11 @@ interface SendStandardResponseOptions extends ToNodeHttpBodyOptions {
|
|
|
46
46
|
}
|
|
47
47
|
declare function sendStandardResponse(res: NodeHttpResponse, standardResponse: StandardResponse, options?: SendStandardResponseOptions): Promise<void>;
|
|
48
48
|
|
|
49
|
-
declare function toAbortSignal(stream: Stream.Writable): AbortSignal;
|
|
49
|
+
declare function toAbortSignal(stream: Stream.Writable | NodeHttpResponse): AbortSignal;
|
|
50
50
|
|
|
51
51
|
declare function toStandardUrl(req: NodeHttpRequest): URL;
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
declare function isNodeResponseStreamEnded(res: Stream.Writable | NodeHttpResponse): boolean;
|
|
54
|
+
|
|
55
|
+
export { isNodeResponseStreamEnded, sendStandardResponse, toAbortSignal, toEventIterator, toEventStream, toNodeHttpBody, toNodeHttpHeaders, toStandardBody, toStandardLazyRequest, toStandardMethod, toStandardUrl };
|
|
54
56
|
export type { NodeHttpRequest, NodeHttpResponse, SendStandardResponseOptions, ToEventIteratorOptions, ToEventStreamOptions, ToNodeHttpBodyOptions, ToStandardBodyOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -46,9 +46,11 @@ interface SendStandardResponseOptions extends ToNodeHttpBodyOptions {
|
|
|
46
46
|
}
|
|
47
47
|
declare function sendStandardResponse(res: NodeHttpResponse, standardResponse: StandardResponse, options?: SendStandardResponseOptions): Promise<void>;
|
|
48
48
|
|
|
49
|
-
declare function toAbortSignal(stream: Stream.Writable): AbortSignal;
|
|
49
|
+
declare function toAbortSignal(stream: Stream.Writable | NodeHttpResponse): AbortSignal;
|
|
50
50
|
|
|
51
51
|
declare function toStandardUrl(req: NodeHttpRequest): URL;
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
declare function isNodeResponseStreamEnded(res: Stream.Writable | NodeHttpResponse): boolean;
|
|
54
|
+
|
|
55
|
+
export { isNodeResponseStreamEnded, sendStandardResponse, toAbortSignal, toEventIterator, toEventStream, toNodeHttpBody, toNodeHttpHeaders, toStandardBody, toStandardLazyRequest, toStandardMethod, toStandardUrl };
|
|
54
56
|
export type { NodeHttpRequest, NodeHttpResponse, SendStandardResponseOptions, ToEventIteratorOptions, ToEventStreamOptions, ToNodeHttpBodyOptions, ToStandardBodyOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -113,14 +113,27 @@ function toStandardMethod(method) {
|
|
|
113
113
|
return method ?? "GET";
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
+
function isNodeResponseStreamEnded(res) {
|
|
117
|
+
const stream = "stream" in res ? res.stream : res;
|
|
118
|
+
return stream.closed || stream.destroyed || stream.writableFinished;
|
|
119
|
+
}
|
|
120
|
+
|
|
116
121
|
function toAbortSignal(stream) {
|
|
117
122
|
const controller = new AbortController();
|
|
118
|
-
stream.
|
|
119
|
-
|
|
120
|
-
|
|
123
|
+
if (stream.errored) {
|
|
124
|
+
controller.abort(stream.errored);
|
|
125
|
+
} else if (isNodeResponseStreamEnded(stream)) {
|
|
126
|
+
if (!stream.writableFinished || !stream.writableEnded) {
|
|
121
127
|
controller.abort(new AbortError("Writable stream closed before it finished writing"));
|
|
122
128
|
}
|
|
123
|
-
}
|
|
129
|
+
} else {
|
|
130
|
+
stream.once("error", (error) => controller.abort(error));
|
|
131
|
+
stream.once("close", () => {
|
|
132
|
+
if (!stream.writableFinished || !stream.writableEnded) {
|
|
133
|
+
controller.abort(new AbortError("Writable stream closed before it finished writing"));
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
124
137
|
return controller.signal;
|
|
125
138
|
}
|
|
126
139
|
|
|
@@ -144,10 +157,21 @@ function toStandardLazyRequest(req, res) {
|
|
|
144
157
|
|
|
145
158
|
function sendStandardResponse(res, standardResponse, options = {}) {
|
|
146
159
|
return new Promise((resolve, reject) => {
|
|
147
|
-
res.once("error", reject);
|
|
148
|
-
res.once("close", resolve);
|
|
149
160
|
const resHeaders = { ...standardResponse.headers };
|
|
150
161
|
const resBody = toNodeHttpBody(standardResponse.body, resHeaders, options);
|
|
162
|
+
if (isNodeResponseStreamEnded(res)) {
|
|
163
|
+
if (typeof resBody === "object" && !resBody.closed) {
|
|
164
|
+
resBody.destroy();
|
|
165
|
+
}
|
|
166
|
+
if (res.errored) {
|
|
167
|
+
reject(res.errored);
|
|
168
|
+
} else {
|
|
169
|
+
resolve();
|
|
170
|
+
}
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
res.once("error", reject);
|
|
174
|
+
res.once("close", resolve);
|
|
151
175
|
res.writeHead(standardResponse.status, toNodeHttpHeaders(resHeaders));
|
|
152
176
|
if (resBody === void 0) {
|
|
153
177
|
res.end();
|
|
@@ -165,4 +189,4 @@ function sendStandardResponse(res, standardResponse, options = {}) {
|
|
|
165
189
|
});
|
|
166
190
|
}
|
|
167
191
|
|
|
168
|
-
export { sendStandardResponse, toAbortSignal, toEventIterator, toEventStream, toNodeHttpBody, toNodeHttpHeaders, toStandardBody, toStandardLazyRequest, toStandardMethod, toStandardUrl };
|
|
192
|
+
export { isNodeResponseStreamEnded, sendStandardResponse, toAbortSignal, toEventIterator, toEventStream, toNodeHttpBody, toNodeHttpHeaders, toStandardBody, toStandardLazyRequest, toStandardMethod, toStandardUrl };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/standard-server-node",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.14.
|
|
4
|
+
"version": "1.14.12",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.dev",
|
|
7
7
|
"repository": {
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"dist"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@orpc/standard-server": "1.14.
|
|
28
|
-
"@orpc/
|
|
29
|
-
"@orpc/
|
|
27
|
+
"@orpc/standard-server-fetch": "1.14.12",
|
|
28
|
+
"@orpc/standard-server": "1.14.12",
|
|
29
|
+
"@orpc/shared": "1.14.12"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/node": "^22.19.3",
|