ismx-nexo-node-app 0.4.133 → 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 +21 -5
- package/dist/types/index.d.ts +3 -0
- package/dist/types/repository/RepositoryDatabasePostgres.d.ts +7 -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 +26 -5
- 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();
|
|
@@ -270,14 +278,22 @@ class RepositoryDatabasePostgres extends RepositoryDatabase_1.default {
|
|
|
270
278
|
continue;
|
|
271
279
|
if (alias !== "")
|
|
272
280
|
alias += ".";
|
|
273
|
-
if (value instanceof Array)
|
|
281
|
+
if (value instanceof Array) {
|
|
274
282
|
where += ` AND ${alias}${column} = ANY(\$${iter++})`;
|
|
275
|
-
|
|
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) {
|
|
276
291
|
where += ` AND ${alias}${column} IS NULL`;
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
where += ` AND ${alias}${column} = \$${iter++}`;
|
|
280
295
|
values.push(value);
|
|
296
|
+
}
|
|
281
297
|
}
|
|
282
298
|
return { where, values };
|
|
283
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;
|
|
@@ -56,10 +61,10 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase {
|
|
|
56
61
|
runTable<T>(name: string, params?: Valuable[], filters?: Partial<T>): Promise<T[]>;
|
|
57
62
|
runValue<T>(name: string, params?: Valuable[], filters?: Partial<T>): Promise<Valuable | undefined>;
|
|
58
63
|
toWhere(tableName: string, filters?: {
|
|
59
|
-
[key: string]: Valuable | Array<Valuable
|
|
64
|
+
[key: string]: Valuable | Array<Valuable> | PgOperator;
|
|
60
65
|
}, alias?: string, index?: number): {
|
|
61
66
|
where: string;
|
|
62
|
-
values: (string | number | symbol | Date | Valuable[])[];
|
|
67
|
+
values: (string | number | symbol | Date | Valuable[] | null | undefined)[];
|
|
63
68
|
};
|
|
64
69
|
anyWhere(filters: any, alias?: string, index?: number): {
|
|
65
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;
|
|
@@ -226,7 +234,7 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
|
|
|
226
234
|
return this.run<T>(name, params, filters).then((result) => Object.values(result[0] ?? {})[0] as Valuable)
|
|
227
235
|
}
|
|
228
236
|
|
|
229
|
-
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)
|
|
230
238
|
{
|
|
231
239
|
let table = this.tables[tableName];
|
|
232
240
|
let columns = PostgresUtils.columns(table);
|
|
@@ -236,10 +244,23 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
|
|
|
236
244
|
let value = filters[PostgresUtils.snakeToCamel(column.replace(/"/g, ''))]
|
|
237
245
|
if (value === undefined) continue;
|
|
238
246
|
if (alias !== "") alias += "."
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
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
|
+
}
|
|
243
264
|
}
|
|
244
265
|
|
|
245
266
|
return { where, values };
|