ismx-nexo-node-app 0.4.183 → 0.4.186
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/business/BusinessServer.js +2 -22
- package/dist/js/repository/RepositoryDatabasePostgres.js +23 -0
- package/dist/types/api/Service.d.ts +10 -1
- package/dist/types/business/BusinessServer.d.ts +1 -1
- package/dist/types/repository/RepositoryDatabasePostgres.d.ts +3 -0
- package/package.json +3 -1
- package/src/main/node/api/Service.ts +11 -1
- package/src/main/node/business/BusinessServer.ts +4 -23
- package/src/main/node/repository/RepositoryDatabasePostgres.ts +24 -0
|
@@ -44,6 +44,7 @@ class BusinessServer extends Business_1.default {
|
|
|
44
44
|
this.publish = this.publish.bind(this);
|
|
45
45
|
Promise.resolve().then(() => __importStar(require("express"))).then((e) => this.express = e.default);
|
|
46
46
|
Promise.resolve().then(() => __importStar(require("cors"))).then((e) => this.cors = e.default);
|
|
47
|
+
Promise.resolve().then(() => __importStar(require("multer"))).then((multer) => this.multer = multer);
|
|
47
48
|
Promise.resolve().then(() => __importStar(require("node:stream"))).then((e) => this.readable = e.default.Readable);
|
|
48
49
|
}
|
|
49
50
|
init() {
|
|
@@ -95,6 +96,7 @@ class BusinessServer extends Business_1.default {
|
|
|
95
96
|
case 'stream': return this.express.raw({ type: 'application/octet-stream', limit: '50mb' });
|
|
96
97
|
case 'image': return this.express.raw({ type: 'image/*', limit: '50mb' });
|
|
97
98
|
case 'audio': return this.express.raw({ type: 'audio/*', limit: '50mb' });
|
|
99
|
+
case 'multipart': return this.multer({ storage: this.multer.memoryStorage() }).array('bundle');
|
|
98
100
|
case '*': return this.express.raw({ type: () => true, limit: '50mb' });
|
|
99
101
|
default: return this.express.json();
|
|
100
102
|
}
|
|
@@ -169,27 +171,5 @@ class BusinessServer extends Business_1.default {
|
|
|
169
171
|
}
|
|
170
172
|
});
|
|
171
173
|
}
|
|
172
|
-
load(parent, path) {
|
|
173
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
174
|
-
/*
|
|
175
|
-
const { readdir } = await import('fs/promises');
|
|
176
|
-
const pathModule = await import('path');
|
|
177
|
-
const { fileURLToPath } = await import('url');
|
|
178
|
-
|
|
179
|
-
// @ts-ignore
|
|
180
|
-
const __dirname = pathModule.dirname(fileURLToPath(parent));
|
|
181
|
-
const servicesPath = pathModule.join(__dirname, path);
|
|
182
|
-
|
|
183
|
-
const files = await readdir(servicesPath);
|
|
184
|
-
for (const file of files) {
|
|
185
|
-
if (!file.endsWith('.ts') && !file.endsWith('.js')) continue;
|
|
186
|
-
const modulePath = pathModule.join(servicesPath, file);
|
|
187
|
-
const mod = await import(modulePath);
|
|
188
|
-
const ServiceClass = Object.values(mod)[0];
|
|
189
|
-
// @ts-ignore
|
|
190
|
-
const instance = new ServiceClass();
|
|
191
|
-
}*/
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
174
|
}
|
|
195
175
|
exports.default = BusinessServer;
|
|
@@ -175,6 +175,29 @@ class RepositoryDatabasePostgres extends RepositoryDatabase_1.default {
|
|
|
175
175
|
return this.query(query, values).then((result) => result[0]);
|
|
176
176
|
});
|
|
177
177
|
}
|
|
178
|
+
updateAll(tableName, filters, object) {
|
|
179
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
180
|
+
if (!this.tables[tableName])
|
|
181
|
+
throw new Error(`table ${tableName} does not exist`);
|
|
182
|
+
let table = this.tables[tableName];
|
|
183
|
+
let schema = table[0].schema;
|
|
184
|
+
const columns = PostgresUtils_1.default.columns(table).filter(column => {
|
|
185
|
+
const camelKey = PostgresUtils_1.default.snakeToCamel(column);
|
|
186
|
+
return Object.prototype.hasOwnProperty.call(object, camelKey);
|
|
187
|
+
});
|
|
188
|
+
if (columns.length === 0)
|
|
189
|
+
return this.find(tableName, filters);
|
|
190
|
+
let { where, values } = this.toWhere(tableName, filters);
|
|
191
|
+
const params = columns.map((_, index) => `\$${index + values.length + 1}`).join(",");
|
|
192
|
+
const query = `
|
|
193
|
+
UPDATE ${schema}.${tableName}
|
|
194
|
+
SET (${columns.join(",")}) = ROW(${params})
|
|
195
|
+
WHERE ${where} RETURNING *
|
|
196
|
+
`;
|
|
197
|
+
let allValues = [...values, ...columns.map((column) => object[PostgresUtils_1.default.snakeToCamel(column)])];
|
|
198
|
+
return this.query(query, allValues).then((result) => result);
|
|
199
|
+
});
|
|
200
|
+
}
|
|
178
201
|
delete(tableName, id) {
|
|
179
202
|
return __awaiter(this, void 0, void 0, function* () {
|
|
180
203
|
return (yield this.deleteAll(tableName, { id }))[0];
|
|
@@ -10,11 +10,20 @@ export interface HttpRequest<T = any> {
|
|
|
10
10
|
query?: {
|
|
11
11
|
[key: string]: string;
|
|
12
12
|
};
|
|
13
|
+
multipart?: HttpMultipart[];
|
|
13
14
|
body?: T;
|
|
14
15
|
headers?: {
|
|
15
16
|
[key: string]: string;
|
|
16
17
|
};
|
|
17
18
|
}
|
|
19
|
+
export interface HttpMultipart {
|
|
20
|
+
fieldname: string;
|
|
21
|
+
originalname: string;
|
|
22
|
+
encoding?: string;
|
|
23
|
+
mimetype: string;
|
|
24
|
+
buffer: Buffer;
|
|
25
|
+
size: number;
|
|
26
|
+
}
|
|
18
27
|
export declare class HttpResponse<T = any> {
|
|
19
28
|
content: T;
|
|
20
29
|
httpCode?: number;
|
|
@@ -26,7 +35,7 @@ export declare class HttpResponse<T = any> {
|
|
|
26
35
|
static ko<T = any>(httpCode: number, content: T): HttpResponse<any>;
|
|
27
36
|
static do<T = any>(httpCode: number, content: T): HttpResponse<any>;
|
|
28
37
|
}
|
|
29
|
-
export type ServiceType = "json" | "xml" | 'stream' | 'image' | 'audio' | 'video' | '*';
|
|
38
|
+
export type ServiceType = "json" | "xml" | 'stream' | 'image' | 'audio' | 'video' | 'multipart' | '*';
|
|
30
39
|
export default abstract class Service<Req, Res> {
|
|
31
40
|
static readonly services: Service<any, any>[];
|
|
32
41
|
readonly method: string;
|
|
@@ -4,6 +4,7 @@ export default class BusinessServer extends Business {
|
|
|
4
4
|
private services;
|
|
5
5
|
private express;
|
|
6
6
|
private app;
|
|
7
|
+
private multer;
|
|
7
8
|
private cors;
|
|
8
9
|
private readable;
|
|
9
10
|
constructor();
|
|
@@ -22,5 +23,4 @@ export default class BusinessServer extends Business {
|
|
|
22
23
|
setOnEnd(listener: (request: HttpRequest, response: HttpResponse) => any): void;
|
|
23
24
|
private publish;
|
|
24
25
|
private run;
|
|
25
|
-
load(parent: string, path: string): Promise<void>;
|
|
26
26
|
}
|
|
@@ -42,6 +42,9 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase {
|
|
|
42
42
|
[key: string]: Valuable;
|
|
43
43
|
} | any)[]): Promise<T[]>;
|
|
44
44
|
update<T>(tableName: string, id: string, object: Partial<T>): Promise<T>;
|
|
45
|
+
updateAll<T>(tableName: string, filters: {
|
|
46
|
+
[p: string]: Valuable | Array<any>;
|
|
47
|
+
}, object: Partial<T>): Promise<T[]>;
|
|
45
48
|
delete<T>(tableName: string, id: string): Promise<T>;
|
|
46
49
|
deleteAll<T>(tableName: string, filters: Partial<T>): Promise<T[]>;
|
|
47
50
|
page<T>(tableName: string, sortKey: string, maxResults?: number, pageNumber?: number, filters?: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ismx-nexo-node-app",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.186",
|
|
4
4
|
"description": "",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "rm -rf ./dist && npx tsc",
|
|
@@ -14,10 +14,12 @@
|
|
|
14
14
|
"author": "",
|
|
15
15
|
"license": "ISC",
|
|
16
16
|
"dependencies": {
|
|
17
|
+
"@types/multer": "^2.0.0",
|
|
17
18
|
"esbuild": "^0.23.1"
|
|
18
19
|
},
|
|
19
20
|
"reqDependencies": {
|
|
20
21
|
"cors": "^2.8.5",
|
|
22
|
+
"multer": "^2.8.5",
|
|
21
23
|
"node-fetch": "^2.6.11",
|
|
22
24
|
"pg": "^8.11.0",
|
|
23
25
|
"ts-node": "8.10.1",
|
|
@@ -6,10 +6,20 @@ export interface HttpRequest<T = any> {
|
|
|
6
6
|
timestamp?: Date,
|
|
7
7
|
params?: { [key: string]: string },
|
|
8
8
|
query?: { [key: string]: string },
|
|
9
|
+
multipart?: HttpMultipart[] ,
|
|
9
10
|
body?: T,
|
|
10
11
|
headers?: { [key: string]: string },
|
|
11
12
|
}
|
|
12
13
|
|
|
14
|
+
export interface HttpMultipart {
|
|
15
|
+
fieldname: string,
|
|
16
|
+
originalname: string,
|
|
17
|
+
encoding?: string,
|
|
18
|
+
mimetype: string,
|
|
19
|
+
buffer: Buffer,
|
|
20
|
+
size: number,
|
|
21
|
+
}
|
|
22
|
+
|
|
13
23
|
export class HttpResponse<T = any> {
|
|
14
24
|
content: T = null!;
|
|
15
25
|
httpCode?: number;
|
|
@@ -36,7 +46,7 @@ export class HttpResponse<T = any> {
|
|
|
36
46
|
}
|
|
37
47
|
}
|
|
38
48
|
|
|
39
|
-
export type ServiceType = "json" | "xml" | 'stream' | 'image' | 'audio' | 'video' | '*';
|
|
49
|
+
export type ServiceType = "json" | "xml" | 'stream' | 'image' | 'audio' | 'video' | 'multipart' | '*';
|
|
40
50
|
export default abstract class Service<Req, Res>
|
|
41
51
|
{
|
|
42
52
|
public static readonly services: Service<any, any>[] = []
|
|
@@ -8,6 +8,7 @@ export default class BusinessServer extends Business
|
|
|
8
8
|
private express: any;
|
|
9
9
|
|
|
10
10
|
private app: any;
|
|
11
|
+
private multer: any;
|
|
11
12
|
private cors: any;
|
|
12
13
|
private readable: any;
|
|
13
14
|
|
|
@@ -16,7 +17,8 @@ export default class BusinessServer extends Business
|
|
|
16
17
|
this.publish = this.publish.bind(this);
|
|
17
18
|
|
|
18
19
|
import("express").then((e) => this.express = e.default);
|
|
19
|
-
import("cors").then((e) => this.cors = e.default)
|
|
20
|
+
import("cors").then((e) => this.cors = e.default);
|
|
21
|
+
import("multer").then((multer) => this.multer = multer);
|
|
20
22
|
import("node:stream").then((e) => this.readable = e.default.Readable)
|
|
21
23
|
}
|
|
22
24
|
|
|
@@ -83,6 +85,7 @@ export default class BusinessServer extends Business
|
|
|
83
85
|
case 'stream': return this.express.raw({ type: 'application/octet-stream', limit: '50mb' });
|
|
84
86
|
case 'image': return this.express.raw({ type: 'image/*', limit: '50mb' });
|
|
85
87
|
case 'audio': return this.express.raw({ type: 'audio/*', limit: '50mb' });
|
|
88
|
+
case 'multipart': return this.multer({ storage: this.multer.memoryStorage() }).array('bundle');
|
|
86
89
|
case '*': return this.express.raw({ type: () => true, limit: '50mb' });
|
|
87
90
|
default: return this.express.json();
|
|
88
91
|
}})();
|
|
@@ -132,26 +135,4 @@ export default class BusinessServer extends Business
|
|
|
132
135
|
try { this.onEnd?.(request, response); } catch(e) { }
|
|
133
136
|
}
|
|
134
137
|
}}
|
|
135
|
-
|
|
136
|
-
public async load(parent: string, path: string): Promise<void>
|
|
137
|
-
{
|
|
138
|
-
/*
|
|
139
|
-
const { readdir } = await import('fs/promises');
|
|
140
|
-
const pathModule = await import('path');
|
|
141
|
-
const { fileURLToPath } = await import('url');
|
|
142
|
-
|
|
143
|
-
// @ts-ignore
|
|
144
|
-
const __dirname = pathModule.dirname(fileURLToPath(parent));
|
|
145
|
-
const servicesPath = pathModule.join(__dirname, path);
|
|
146
|
-
|
|
147
|
-
const files = await readdir(servicesPath);
|
|
148
|
-
for (const file of files) {
|
|
149
|
-
if (!file.endsWith('.ts') && !file.endsWith('.js')) continue;
|
|
150
|
-
const modulePath = pathModule.join(servicesPath, file);
|
|
151
|
-
const mod = await import(modulePath);
|
|
152
|
-
const ServiceClass = Object.values(mod)[0];
|
|
153
|
-
// @ts-ignore
|
|
154
|
-
const instance = new ServiceClass();
|
|
155
|
-
}*/
|
|
156
|
-
}
|
|
157
138
|
}
|
|
@@ -150,6 +150,30 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
|
|
|
150
150
|
return this.query<T>(query, values).then((result) => result[0]);
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
+
async updateAll<T>(tableName: string, filters: { [p: string]: Valuable | Array<any> }, object: Partial<T>): Promise<T[]> {
|
|
154
|
+
|
|
155
|
+
if (!this.tables[tableName]) throw new Error(`table ${tableName} does not exist`);
|
|
156
|
+
let table = this.tables[tableName];
|
|
157
|
+
let schema = table[0].schema;
|
|
158
|
+
const columns = PostgresUtils.columns(table).filter(column => {
|
|
159
|
+
const camelKey = PostgresUtils.snakeToCamel(column);
|
|
160
|
+
return Object.prototype.hasOwnProperty.call(object, camelKey);
|
|
161
|
+
});
|
|
162
|
+
if (columns.length === 0) return this.find(tableName, filters);
|
|
163
|
+
|
|
164
|
+
let { where, values } = this.toWhere(tableName, filters);
|
|
165
|
+
const params = columns.map((_, index) => `\$${index + values.length + 1}`).join(",");
|
|
166
|
+
|
|
167
|
+
const query = `
|
|
168
|
+
UPDATE ${schema}.${tableName}
|
|
169
|
+
SET (${columns.join(",")}) = ROW(${params})
|
|
170
|
+
WHERE ${where} RETURNING *
|
|
171
|
+
`;
|
|
172
|
+
|
|
173
|
+
let allValues = [ ...values, ...columns.map((column) => object[PostgresUtils.snakeToCamel(column) as keyof T]) ]
|
|
174
|
+
return this.query<T>(query, allValues).then((result) => result);
|
|
175
|
+
}
|
|
176
|
+
|
|
153
177
|
async delete<T>(tableName: string, id: string): Promise<T> {
|
|
154
178
|
return (await this.deleteAll(tableName, { id } as any))[0] as T;
|
|
155
179
|
}
|