ismx-nexo-node-app 0.4.132 → 0.4.134
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/BusinessErrors.js +2 -0
- package/dist/js/index.js +5 -1
- package/dist/js/repository/RepositoryDatabasePostgres.js +30 -5
- package/dist/types/index.d.ts +3 -0
- package/dist/types/repository/RepositoryDatabasePostgres.d.ts +8 -2
- package/package.json +1 -1
- package/src/main/node/business/BusinessErrors.ts +2 -0
- package/src/main/node/index.ts +3 -0
- package/src/main/node/repository/RepositoryDatabasePostgres.ts +35 -6
- package/src/main/node/repository/utils/PostgresUtils.ts +1 -1
|
@@ -81,6 +81,8 @@ class BusinessErrors {
|
|
|
81
81
|
getBodyParam(param, body) {
|
|
82
82
|
let path = param.split(".");
|
|
83
83
|
let value = body;
|
|
84
|
+
if (value === undefined || value === null)
|
|
85
|
+
this.except("0014", param);
|
|
84
86
|
for (let key of path) {
|
|
85
87
|
value = value[key];
|
|
86
88
|
if (value === undefined || value === null)
|
package/dist/js/index.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.RestUtils = exports.QueryUtils = exports.RepositoryRestFormalTemplate = exports.RepositoryRestFormal = exports.RepositoryRest = exports.RepositoryDatabasePostgres = exports.RepositoryDatabase = exports.Repository = exports.PromiseUtils = exports.ArrayUtils = exports.StringUtils = exports.NumberUtils = exports.CryptoUtils = exports.DateUtils = exports.BusinessLogger = exports.FormalError = exports.BusinessErrors = exports.BusinessThreadState = exports.BusinessThread = exports.BusinessServer = exports.FormalLoopbackBusiness = exports.FormalProxyBusiness = exports.ProxyBusiness = exports.BusinessState = exports.Business = exports.ColorUtils = exports.ServiceRestFormalTemplate = exports.ServiceRestFormal = exports.ServiceRest = exports.HttpResponse = exports.Service = void 0;
|
|
29
|
+
exports.PostgresUtils = exports.RestUtils = exports.QueryUtils = exports.RepositoryRestFormalTemplate = exports.RepositoryRestFormal = exports.RepositoryRest = exports.RepositoryDatabasePostgres = exports.RepositoryDatabase = exports.Repository = exports.PromiseUtils = exports.ArrayUtils = exports.StringUtils = exports.NumberUtils = exports.CryptoUtils = exports.DateUtils = exports.BusinessLogger = exports.FormalError = exports.BusinessErrors = exports.BusinessThreadState = exports.BusinessThread = exports.BusinessServer = exports.FormalLoopbackBusiness = exports.FormalProxyBusiness = exports.ProxyBusiness = exports.BusinessState = exports.Business = exports.ColorUtils = exports.ServiceRestFormalTemplate = exports.ServiceRestFormal = exports.ServiceRest = exports.HttpResponse = exports.Service = void 0;
|
|
30
30
|
const Service_1 = __importStar(require("./api/Service"));
|
|
31
31
|
class Service extends Service_1.default {
|
|
32
32
|
}
|
|
@@ -151,3 +151,7 @@ const RestUtils_1 = __importDefault(require("./repository/utils/RestUtils"));
|
|
|
151
151
|
class RestUtils extends RestUtils_1.default {
|
|
152
152
|
}
|
|
153
153
|
exports.RestUtils = RestUtils;
|
|
154
|
+
const PostgresUtils_1 = __importDefault(require("./repository/utils/PostgresUtils"));
|
|
155
|
+
class PostgresUtils extends PostgresUtils_1.default {
|
|
156
|
+
}
|
|
157
|
+
exports.PostgresUtils = PostgresUtils;
|
|
@@ -35,9 +35,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
35
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.PgOperator = void 0;
|
|
38
39
|
const PostgresUtils_1 = __importDefault(require("./utils/PostgresUtils"));
|
|
39
40
|
const RepositoryDatabase_1 = __importDefault(require("./RepositoryDatabase"));
|
|
40
41
|
const Repository_1 = require("./Repository");
|
|
42
|
+
class PgOperator {
|
|
43
|
+
constructor(vals, toWhere) {
|
|
44
|
+
this.toWhere = toWhere;
|
|
45
|
+
this.vals = vals;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.PgOperator = PgOperator;
|
|
41
49
|
class RepositoryDatabasePostgres extends RepositoryDatabase_1.default {
|
|
42
50
|
constructor() {
|
|
43
51
|
super();
|
|
@@ -244,6 +252,15 @@ class RepositoryDatabasePostgres extends RepositoryDatabase_1.default {
|
|
|
244
252
|
return this.query(query, [...values, ...params]);
|
|
245
253
|
});
|
|
246
254
|
}
|
|
255
|
+
runTable(name_1) {
|
|
256
|
+
return __awaiter(this, arguments, void 0, function* (name, params = [], filters = {}) {
|
|
257
|
+
var _a;
|
|
258
|
+
let { where, values } = this.anyWhere(filters);
|
|
259
|
+
let placeholders = (_a = params === null || params === void 0 ? void 0 : params.map((_, index) => "$" + (index + 1 + values.length))) !== null && _a !== void 0 ? _a : [];
|
|
260
|
+
let query = `SELECT * FROM ${name}(${placeholders.join(',')}) WHERE ${where}`;
|
|
261
|
+
return this.query(query, [...values, ...params]);
|
|
262
|
+
});
|
|
263
|
+
}
|
|
247
264
|
runValue(name_1) {
|
|
248
265
|
return __awaiter(this, arguments, void 0, function* (name, params = [], filters = {}) {
|
|
249
266
|
return this.run(name, params, filters).then((result) => { var _a; return Object.values((_a = result[0]) !== null && _a !== void 0 ? _a : {})[0]; });
|
|
@@ -261,14 +278,22 @@ class RepositoryDatabasePostgres extends RepositoryDatabase_1.default {
|
|
|
261
278
|
continue;
|
|
262
279
|
if (alias !== "")
|
|
263
280
|
alias += ".";
|
|
264
|
-
if (value instanceof Array)
|
|
281
|
+
if (value instanceof Array) {
|
|
265
282
|
where += ` AND ${alias}${column} = ANY(\$${iter++})`;
|
|
266
|
-
|
|
283
|
+
values.push(value);
|
|
284
|
+
}
|
|
285
|
+
else if (value instanceof PgOperator) {
|
|
286
|
+
let idxs = value.vals.map((v) => `\$${iter++}`);
|
|
287
|
+
where += ` AND ${value.toWhere(`${alias}${column}`, idxs)}`;
|
|
288
|
+
values.push(...value.vals);
|
|
289
|
+
}
|
|
290
|
+
else if (value === null) {
|
|
267
291
|
where += ` AND ${alias}${column} IS NULL`;
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
where += ` AND ${alias}${column} = \$${iter++}`;
|
|
271
295
|
values.push(value);
|
|
296
|
+
}
|
|
272
297
|
}
|
|
273
298
|
return { where, values };
|
|
274
299
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -103,3 +103,6 @@ export declare abstract class QueryUtils extends _QueryUtils {
|
|
|
103
103
|
import _RestUtils from "./repository/utils/RestUtils";
|
|
104
104
|
export declare abstract class RestUtils extends _RestUtils {
|
|
105
105
|
}
|
|
106
|
+
import _PostgresUtils from "./repository/utils/PostgresUtils";
|
|
107
|
+
export declare abstract class PostgresUtils extends _PostgresUtils {
|
|
108
|
+
}
|
|
@@ -5,6 +5,11 @@ export interface Column {
|
|
|
5
5
|
schema: string;
|
|
6
6
|
default?: string;
|
|
7
7
|
}
|
|
8
|
+
export declare class PgOperator {
|
|
9
|
+
readonly toWhere: (column: string, params: string[]) => string;
|
|
10
|
+
readonly vals: Valuable[];
|
|
11
|
+
constructor(vals: Valuable[], toWhere: (column: string, params: string[]) => string);
|
|
12
|
+
}
|
|
8
13
|
export default class RepositoryDatabasePostgres extends RepositoryDatabase {
|
|
9
14
|
private readonly introspectIntervalTime;
|
|
10
15
|
protected client: any;
|
|
@@ -53,12 +58,13 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase {
|
|
|
53
58
|
}): Promise<string[]>;
|
|
54
59
|
selectHash<T>(tableName: string, select: string, filters?: Partial<T>): Promise<Hash<Primitive>>;
|
|
55
60
|
run<T>(name: string, params?: Valuable[], filters?: Partial<T>): Promise<T[]>;
|
|
61
|
+
runTable<T>(name: string, params?: Valuable[], filters?: Partial<T>): Promise<T[]>;
|
|
56
62
|
runValue<T>(name: string, params?: Valuable[], filters?: Partial<T>): Promise<Valuable | undefined>;
|
|
57
63
|
toWhere(tableName: string, filters?: {
|
|
58
|
-
[key: string]: Valuable | Array<Valuable
|
|
64
|
+
[key: string]: Valuable | Array<Valuable> | PgOperator;
|
|
59
65
|
}, alias?: string, index?: number): {
|
|
60
66
|
where: string;
|
|
61
|
-
values: (string | number | symbol | Date | Valuable[])[];
|
|
67
|
+
values: (string | number | symbol | Date | Valuable[] | null | undefined)[];
|
|
62
68
|
};
|
|
63
69
|
anyWhere(filters: any, alias?: string, index?: number): {
|
|
64
70
|
where: string;
|
package/package.json
CHANGED
|
@@ -79,6 +79,8 @@ export default class BusinessErrors {
|
|
|
79
79
|
getBodyParam(param: string, body: any): any {
|
|
80
80
|
let path = param.split(".");
|
|
81
81
|
let value = body;
|
|
82
|
+
if (value === undefined || value === null)
|
|
83
|
+
this.except("0014", param);
|
|
82
84
|
for (let key of path) {
|
|
83
85
|
value = value[key];
|
|
84
86
|
if (value === undefined || value === null) this.except("0014", param);
|
package/src/main/node/index.ts
CHANGED
|
@@ -97,3 +97,6 @@ export abstract class QueryUtils extends _QueryUtils {}
|
|
|
97
97
|
|
|
98
98
|
import _RestUtils from "./repository/utils/RestUtils";
|
|
99
99
|
export abstract class RestUtils extends _RestUtils {}
|
|
100
|
+
|
|
101
|
+
import _PostgresUtils from "./repository/utils/PostgresUtils";
|
|
102
|
+
export abstract class PostgresUtils extends _PostgresUtils {}
|
|
@@ -8,6 +8,14 @@ export interface Column {
|
|
|
8
8
|
default?: string
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
export class PgOperator {
|
|
12
|
+
readonly toWhere: (column: string, params: string[]) => string;
|
|
13
|
+
readonly vals: Valuable[];
|
|
14
|
+
constructor(vals: Valuable[], toWhere: (column: string, params: string[]) => string) {
|
|
15
|
+
this.toWhere = toWhere; this.vals = vals;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
11
19
|
export default class RepositoryDatabasePostgres extends RepositoryDatabase
|
|
12
20
|
{
|
|
13
21
|
private readonly introspectIntervalTime: number = 60 * 60 * 1000;
|
|
@@ -211,14 +219,22 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
|
|
|
211
219
|
let { where, values } = this.anyWhere(filters as any);
|
|
212
220
|
let placeholders = params?.map((_, index) => "$"+(index+1+values.length)) ?? [];
|
|
213
221
|
let query = `SELECT ${name}(${placeholders.join(',')}) WHERE ${where}`;
|
|
214
|
-
return this.query<any>(query, [ ...values, ...params ])
|
|
222
|
+
return this.query<any>(query, [ ...values, ...params ]);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
async runTable<T>(name: string, params: Valuable[] = [], filters: Partial<T> = {}): Promise<T[]>
|
|
226
|
+
{
|
|
227
|
+
let { where, values } = this.anyWhere(filters as any);
|
|
228
|
+
let placeholders = params?.map((_, index) => "$"+(index+1+values.length)) ?? [];
|
|
229
|
+
let query = `SELECT * FROM ${name}(${placeholders.join(',')}) WHERE ${where}`;
|
|
230
|
+
return this.query<any>(query, [ ...values, ...params ]);
|
|
215
231
|
}
|
|
216
232
|
|
|
217
233
|
async runValue<T>(name: string, params: Valuable[] = [], filters: Partial<T> = {}): Promise<Valuable | undefined> {
|
|
218
234
|
return this.run<T>(name, params, filters).then((result) => Object.values(result[0] ?? {})[0] as Valuable)
|
|
219
235
|
}
|
|
220
236
|
|
|
221
|
-
toWhere(tableName: string, filters: { [key: string]: Valuable | Array<Valuable> }={}, alias:string = "", index=1)
|
|
237
|
+
toWhere(tableName: string, filters: { [key: string]: Valuable | Array<Valuable> | PgOperator }={}, alias:string = "", index=1)
|
|
222
238
|
{
|
|
223
239
|
let table = this.tables[tableName];
|
|
224
240
|
let columns = PostgresUtils.columns(table);
|
|
@@ -228,10 +244,23 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
|
|
|
228
244
|
let value = filters[PostgresUtils.snakeToCamel(column.replace(/"/g, ''))]
|
|
229
245
|
if (value === undefined) continue;
|
|
230
246
|
if (alias !== "") alias += "."
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
247
|
+
|
|
248
|
+
if (value instanceof Array) {
|
|
249
|
+
where += ` AND ${alias}${column} = ANY(\$${iter++})`;
|
|
250
|
+
values.push(value);
|
|
251
|
+
|
|
252
|
+
} else if (value instanceof PgOperator) {
|
|
253
|
+
let idxs = value.vals.map((v) => `\$${iter++}`)
|
|
254
|
+
where += ` AND ${value.toWhere(`${alias}${column}`, idxs)}`
|
|
255
|
+
values.push(...value.vals);
|
|
256
|
+
|
|
257
|
+
} else if (value === null) {
|
|
258
|
+
where += ` AND ${alias}${column} IS NULL`
|
|
259
|
+
|
|
260
|
+
} else {
|
|
261
|
+
where += ` AND ${alias}${column} = \$${iter++}`;
|
|
262
|
+
values.push(value);
|
|
263
|
+
}
|
|
235
264
|
}
|
|
236
265
|
|
|
237
266
|
return { where, values };
|