@objectstack/runtime 6.1.1 → 6.3.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 CHANGED
@@ -5898,6 +5898,46 @@ function sendResultBase(result, res, securityHeaders) {
5898
5898
  return;
5899
5899
  }
5900
5900
  if (result.result) {
5901
+ const r = result.result;
5902
+ const isStream = r && typeof r === "object" && (r.type === "stream" || r.stream === true) && r.events;
5903
+ if (isStream && typeof res.write === "function" && typeof res.end === "function") {
5904
+ res.status(typeof r.status === "number" ? r.status : 200);
5905
+ applySecurityHeaders();
5906
+ if (r.headers && typeof r.headers === "object") {
5907
+ for (const [k, v] of Object.entries(r.headers)) {
5908
+ res.header(k, String(v));
5909
+ }
5910
+ } else {
5911
+ res.header("Content-Type", r.contentType || "text/event-stream");
5912
+ res.header("Cache-Control", "no-cache");
5913
+ res.header("Connection", "keep-alive");
5914
+ }
5915
+ res.write("");
5916
+ (async () => {
5917
+ try {
5918
+ for await (const event of r.events) {
5919
+ if (event == null) continue;
5920
+ res.write(typeof event === "string" ? event : `data: ${JSON.stringify(event)}
5921
+
5922
+ `);
5923
+ }
5924
+ } catch (streamErr) {
5925
+ try {
5926
+ res.write(`event: error
5927
+ data: ${JSON.stringify({ message: streamErr instanceof Error ? streamErr.message : String(streamErr) })}
5928
+
5929
+ `);
5930
+ } catch {
5931
+ }
5932
+ } finally {
5933
+ try {
5934
+ res.end();
5935
+ } catch {
5936
+ }
5937
+ }
5938
+ })();
5939
+ return;
5940
+ }
5901
5941
  res.status(200);
5902
5942
  applySecurityHeaders();
5903
5943
  res.json(result.result);