ismx-nexo-node-app 0.4.161 → 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.
- package/dist/js/api/Service.js +6 -0
- package/dist/js/business/BusinessServer.js +5 -1
- package/dist/js/business/utils/ArrayUtils.js +2 -2
- package/dist/types/api/Service.d.ts +2 -0
- package/package.json +1 -1
- package/src/main/node/api/Service.ts +8 -1
- package/src/main/node/business/BusinessServer.ts +4 -1
- package/src/main/node/business/utils/ArrayUtils.ts +2 -2
package/dist/js/api/Service.js
CHANGED
|
@@ -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
|
-
|
|
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
|
}
|
|
@@ -146,9 +146,9 @@ class ArrayUtils {
|
|
|
146
146
|
static sortedBy(array, key, sortFn = 'desc') {
|
|
147
147
|
let valueFn = typeof key === 'function' ? key : (t) => t[key];
|
|
148
148
|
if (sortFn === 'desc')
|
|
149
|
-
return ArrayUtils.sorted(array, (a, b) => valueFn(a) - valueFn(b));
|
|
150
|
-
if (sortFn === 'asc')
|
|
151
149
|
return ArrayUtils.sorted(array, (a, b) => valueFn(b) - valueFn(a));
|
|
150
|
+
if (sortFn === 'asc')
|
|
151
|
+
return ArrayUtils.sorted(array, (a, b) => valueFn(a) - valueFn(b));
|
|
152
152
|
else
|
|
153
153
|
return array;
|
|
154
154
|
}
|
|
@@ -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
|
@@ -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
|
-
|
|
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
|
}}
|
|
@@ -139,8 +139,8 @@ export default abstract class ArrayUtils {
|
|
|
139
139
|
*/
|
|
140
140
|
static sortedBy<T>(array: T[], key: keyof T | ((t: T) => number), sortFn: 'asc' | 'desc' = 'desc'): T[] {
|
|
141
141
|
let valueFn: (t: T) => number = typeof key === 'function' ? key : (t) => t[key] as number;
|
|
142
|
-
if (sortFn === 'desc') return ArrayUtils.sorted(array, (a, b) => valueFn(
|
|
143
|
-
if (sortFn === 'asc') return ArrayUtils.sorted(array, (a, b) => valueFn(
|
|
142
|
+
if (sortFn === 'desc') return ArrayUtils.sorted(array, (a, b) => valueFn(b) - valueFn(a));
|
|
143
|
+
if (sortFn === 'asc') return ArrayUtils.sorted(array, (a, b) => valueFn(a) - valueFn(b));
|
|
144
144
|
else return array;
|
|
145
145
|
}
|
|
146
146
|
}
|