@objectstack/runtime 6.0.0 → 6.2.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/index.cjs +40 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -1
- package/package.json +18 -18
package/dist/index.js
CHANGED
|
@@ -5819,6 +5819,46 @@ function sendResultBase(result, res, securityHeaders) {
|
|
|
5819
5819
|
return;
|
|
5820
5820
|
}
|
|
5821
5821
|
if (result.result) {
|
|
5822
|
+
const r = result.result;
|
|
5823
|
+
const isStream = r && typeof r === "object" && (r.type === "stream" || r.stream === true) && r.events;
|
|
5824
|
+
if (isStream && typeof res.write === "function" && typeof res.end === "function") {
|
|
5825
|
+
res.status(typeof r.status === "number" ? r.status : 200);
|
|
5826
|
+
applySecurityHeaders();
|
|
5827
|
+
if (r.headers && typeof r.headers === "object") {
|
|
5828
|
+
for (const [k, v] of Object.entries(r.headers)) {
|
|
5829
|
+
res.header(k, String(v));
|
|
5830
|
+
}
|
|
5831
|
+
} else {
|
|
5832
|
+
res.header("Content-Type", r.contentType || "text/event-stream");
|
|
5833
|
+
res.header("Cache-Control", "no-cache");
|
|
5834
|
+
res.header("Connection", "keep-alive");
|
|
5835
|
+
}
|
|
5836
|
+
res.write("");
|
|
5837
|
+
(async () => {
|
|
5838
|
+
try {
|
|
5839
|
+
for await (const event of r.events) {
|
|
5840
|
+
if (event == null) continue;
|
|
5841
|
+
res.write(typeof event === "string" ? event : `data: ${JSON.stringify(event)}
|
|
5842
|
+
|
|
5843
|
+
`);
|
|
5844
|
+
}
|
|
5845
|
+
} catch (streamErr) {
|
|
5846
|
+
try {
|
|
5847
|
+
res.write(`event: error
|
|
5848
|
+
data: ${JSON.stringify({ message: streamErr instanceof Error ? streamErr.message : String(streamErr) })}
|
|
5849
|
+
|
|
5850
|
+
`);
|
|
5851
|
+
} catch {
|
|
5852
|
+
}
|
|
5853
|
+
} finally {
|
|
5854
|
+
try {
|
|
5855
|
+
res.end();
|
|
5856
|
+
} catch {
|
|
5857
|
+
}
|
|
5858
|
+
}
|
|
5859
|
+
})();
|
|
5860
|
+
return;
|
|
5861
|
+
}
|
|
5822
5862
|
res.status(200);
|
|
5823
5863
|
applySecurityHeaders();
|
|
5824
5864
|
res.json(result.result);
|