ismx-nexo-node-app 0.4.162 → 0.4.163

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.
@@ -26,6 +26,12 @@ class HttpResponse {
26
26
  response.httpCode = httpCode;
27
27
  return response;
28
28
  }
29
+ static do(httpCode, content) {
30
+ let response = new HttpResponse();
31
+ response.content = content;
32
+ response.httpCode = httpCode;
33
+ return response;
34
+ }
29
35
  }
30
36
  exports.HttpResponse = HttpResponse;
31
37
  class Service {
@@ -37,6 +37,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
38
  const Service_1 = require("../api/Service");
39
39
  const Business_1 = __importDefault(require("./Business"));
40
+ const node_stream_1 = require("node:stream");
40
41
  class BusinessServer extends Business_1.default {
41
42
  constructor() {
42
43
  super();
@@ -147,7 +148,10 @@ class BusinessServer extends Business_1.default {
147
148
  Object.entries((_h = response.headers) !== null && _h !== void 0 ? _h : {}).forEach(([header, value]) => {
148
149
  socket.set(header, value);
149
150
  });
150
- socket.send(response === null || response === void 0 ? void 0 : response.content);
151
+ if (response.pipe)
152
+ node_stream_1.Readable.fromWeb(response.pipe).pipe(socket);
153
+ else
154
+ socket.send(response === null || response === void 0 ? void 0 : response.content);
151
155
  try {
152
156
  (_j = this.onEnd) === null || _j === void 0 ? void 0 : _j.call(this, request, response);
153
157
  }
@@ -21,8 +21,10 @@ export declare class HttpResponse<T = any> {
21
21
  headers?: {
22
22
  [key: string]: string;
23
23
  };
24
+ pipe?: ReadableStream;
24
25
  static ok<T = any>(content: T): HttpResponse<any>;
25
26
  static ko<T = any>(httpCode: number, content: T): HttpResponse<any>;
27
+ static do<T = any>(httpCode: number, content: T): HttpResponse<any>;
26
28
  }
27
29
  export type ServiceType = "json" | "xml" | 'stream' | 'image' | 'audio' | 'video' | '*';
28
30
  export default abstract class Service<Req, Res> {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ismx-nexo-node-app",
3
- "version": "0.4.162",
3
+ "version": "0.4.163",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build": "rm -rf ./dist && npx tsc",
@@ -14,6 +14,7 @@ export class HttpResponse<T = any> {
14
14
  content: T = null!;
15
15
  httpCode?: number;
16
16
  headers?: { [key: string]: string };
17
+ pipe?: ReadableStream;
17
18
 
18
19
  static ok<T=any>(content: T) {
19
20
  let response = new HttpResponse();
@@ -25,7 +26,13 @@ export class HttpResponse<T = any> {
25
26
  let response = new HttpResponse();
26
27
  response.content = content;
27
28
  response.httpCode = httpCode;
28
- return response
29
+ return response;
30
+ }
31
+ static do<T=any>(httpCode: number, content: T) {
32
+ let response = new HttpResponse();
33
+ response.content = content;
34
+ response.httpCode = httpCode;
35
+ return response;
29
36
  }
30
37
  }
31
38
 
@@ -1,5 +1,6 @@
1
1
  import Service, {HttpRequest, HttpResponse} from "../api/Service";
2
2
  import Business from "./Business";
3
+ import {Readable} from "node:stream";
3
4
 
4
5
  export default class BusinessServer extends Business
5
6
  {
@@ -109,7 +110,9 @@ export default class BusinessServer extends Business
109
110
  Object.entries(response.headers ?? {}).forEach(([header, value]) => {
110
111
  socket.set(header, value);
111
112
  });
112
- socket.send(response?.content);
113
+ if (response.pipe) (Readable as any).fromWeb(response.pipe).pipe(socket);
114
+ else socket.send(response?.content);
115
+
113
116
  try { this.onEnd?.(request, response); } catch(e) { }
114
117
  }
115
118
  }}