@puca/puca-core 8.1.3 → 8.2.0
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/core/services/index.d.ts +2 -0
- package/dist/core/services/index.js +5 -3
- package/dist/core/services/index.js.map +1 -1
- package/dist/core/services/install.service.js +39 -27
- package/dist/core/services/install.service.js.map +1 -1
- package/dist/core/services/job-executor/job-executor.service.d.ts +42 -0
- package/dist/core/services/job-executor/job-executor.service.js +87 -0
- package/dist/core/services/job-executor/job-executor.service.js.map +1 -0
- package/dist/core/services/life-cycle.service.d.ts +3 -3
- package/dist/core/services/life-cycle.service.js +5 -3
- package/dist/core/services/life-cycle.service.js.map +1 -1
- package/dist/core/services/single-instance-ensure.service.d.ts +5 -10
- package/dist/core/services/single-instance-ensure.service.js +12 -67
- package/dist/core/services/single-instance-ensure.service.js.map +1 -1
- package/dist/core/services/user-config.service.js +46 -4
- package/dist/core/services/user-config.service.js.map +1 -1
- package/dist/models/crud-controller-especification-environment.d.ts +3 -0
- package/dist/models/table-dictionary.d.ts +7 -6
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -1
|
@@ -1,80 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SingleInstanceEnsureService = void 0;
|
|
4
|
-
const logger_1 = require("./logger");
|
|
5
4
|
class SingleInstanceEnsureService {
|
|
6
|
-
constructor(
|
|
7
|
-
this.
|
|
8
|
-
this.logger = new logger_1.Logger('SingleInstanceEnsureService');
|
|
9
|
-
this.running = [];
|
|
10
|
-
this.healthCheck = setInterval(() => {
|
|
11
|
-
if (this.running.length) {
|
|
12
|
-
this.logger.log("Running: " + this.running.reduce((a, b) => `${a},${b}`));
|
|
13
|
-
}
|
|
14
|
-
}, 5000);
|
|
5
|
+
constructor(jobExecutorFactory) {
|
|
6
|
+
this.jobExecutorFactory = jobExecutorFactory;
|
|
15
7
|
}
|
|
16
|
-
ensure(key, func, opt) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return resolve(false);
|
|
27
|
-
}
|
|
28
|
-
r.setex(completeKey, opt.timeoutInSeconds, 'locked', () => {
|
|
29
|
-
this.logger.log(`processo '${key}' iniciado`);
|
|
30
|
-
resolve(true);
|
|
31
|
-
this.running.push(key);
|
|
32
|
-
func()
|
|
33
|
-
.catch((error) => {
|
|
34
|
-
this.logger.error(error);
|
|
35
|
-
})
|
|
36
|
-
.finally(() => {
|
|
37
|
-
this.shutdownByKey(key)
|
|
38
|
-
.catch(error => {
|
|
39
|
-
this.logger.error(error);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
});
|
|
8
|
+
async ensure(key, data, func, opt) {
|
|
9
|
+
const jobExecutor = this.jobExecutorFactory.get(this.toCompleteKey(key));
|
|
10
|
+
jobExecutor.process(1, (job) => {
|
|
11
|
+
func(job.data);
|
|
12
|
+
});
|
|
13
|
+
jobExecutor.add(data, {
|
|
14
|
+
key,
|
|
15
|
+
timeout: opt.timeoutInSeconds * 1000,
|
|
16
|
+
removeOnComplete: true,
|
|
17
|
+
removeOnFail: true
|
|
44
18
|
});
|
|
45
19
|
}
|
|
46
20
|
toCompleteKey(key) {
|
|
47
21
|
return `SingleInstanceEnsureService-${key}`;
|
|
48
22
|
}
|
|
49
|
-
async shutdownByKey(key) {
|
|
50
|
-
const completeKey = this.toCompleteKey(key);
|
|
51
|
-
const r = this.redisManagerService.get();
|
|
52
|
-
return new Promise((resolve, reject) => {
|
|
53
|
-
r.del(completeKey, error => {
|
|
54
|
-
this.logger.log(`processo '${key}' finalizado`);
|
|
55
|
-
this.running.splice(this.running.findIndex(r => r === key), 1);
|
|
56
|
-
if (error) {
|
|
57
|
-
return reject(error);
|
|
58
|
-
}
|
|
59
|
-
return resolve();
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
async shutdown() {
|
|
64
|
-
clearInterval(this.healthCheck);
|
|
65
|
-
await Promise.all(this.running.map(key => () => {
|
|
66
|
-
return new Promise(async (r) => {
|
|
67
|
-
try {
|
|
68
|
-
await this.shutdownByKey(key);
|
|
69
|
-
r();
|
|
70
|
-
}
|
|
71
|
-
catch (e) {
|
|
72
|
-
this.logger.error(e);
|
|
73
|
-
r();
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}));
|
|
77
|
-
}
|
|
78
23
|
}
|
|
79
24
|
exports.SingleInstanceEnsureService = SingleInstanceEnsureService;
|
|
80
25
|
//# sourceMappingURL=single-instance-ensure.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"single-instance-ensure.service.js","sourceRoot":"","sources":["../../../src/core/services/single-instance-ensure.service.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"single-instance-ensure.service.js","sourceRoot":"","sources":["../../../src/core/services/single-instance-ensure.service.ts"],"names":[],"mappings":";;;AAEA,MAAa,2BAA2B;IACtC,YAA6B,kBAAsC;QAAtC,uBAAkB,GAAlB,kBAAkB,CAAoB;IAAI,CAAC;IAExE,KAAK,CAAC,MAAM,CAAI,GAAW,EAAE,IAAO,EAAE,IAAgC,EAAE,GAEvE;QACC,MAAM,WAAW,GAAG,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAI,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAA;QAC3E,WAAW,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE;YAC7B,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QAChB,CAAC,CAAC,CAAA;QACF,WAAW,CAAC,GAAG,CAAC,IAAI,EAAC;YACnB,GAAG;YACH,OAAO,EAAE,GAAG,CAAC,gBAAgB,GAAG,IAAI;YACpC,gBAAgB,EAAE,IAAI;YACtB,YAAY,EAAE,IAAI;SACnB,CAAC,CAAA;IACJ,CAAC;IAEO,aAAa,CAAC,GAAW;QAC/B,OAAO,+BAA+B,GAAG,EAAE,CAAA;IAC7C,CAAC;CACF;AArBD,kEAqBC"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.UserConfigService = void 0;
|
|
4
4
|
const _ = require("lodash");
|
|
5
5
|
const interfaces_1 = require("../../orm/cases/bo/interfaces");
|
|
6
|
+
const user_access_control_mode_1 = require("../../models/user-access-control-mode");
|
|
6
7
|
class UserConfigService {
|
|
7
8
|
constructor(moduleConfigService, repositoryFactory, configService) {
|
|
8
9
|
this.moduleConfigService = moduleConfigService;
|
|
@@ -18,16 +19,38 @@ class UserConfigService {
|
|
|
18
19
|
if (user.username === 'puca-user') {
|
|
19
20
|
return true;
|
|
20
21
|
}
|
|
22
|
+
const isTable = !!['-list', '-edit', '-new', '-delete'].find(sufix => accessCondition.endsWith(sufix));
|
|
23
|
+
const tableName = isTable ? accessCondition.replace(/(-list|-edit|-new|-delete)$/, '') : null;
|
|
21
24
|
const userConfig = await this.repositoryFactory.getInstance({
|
|
22
25
|
tableName: 'puca_base_api_system_user_config_definition',
|
|
23
26
|
transaction: null
|
|
24
|
-
}).findOneWhere(await this.computeArgs(accessCondition, user, moduleName));
|
|
27
|
+
}).findOneWhere(await this.computeArgs(accessCondition, user, moduleName, tableName));
|
|
25
28
|
if (!userConfig) {
|
|
26
29
|
return true;
|
|
27
30
|
}
|
|
28
|
-
|
|
31
|
+
if (!isTable) {
|
|
32
|
+
return userConfig.r_boolean_value || userConfig.u_boolean_value || false;
|
|
33
|
+
}
|
|
34
|
+
if (!userConfig.use_access_control) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
const accessTypeName = accessCondition.replace(`${tableName}-`, '');
|
|
38
|
+
const accessType = {
|
|
39
|
+
'list': 'select',
|
|
40
|
+
'edit': 'update',
|
|
41
|
+
'new': 'insert',
|
|
42
|
+
'delete': 'delete'
|
|
43
|
+
}[accessTypeName];
|
|
44
|
+
if (!accessType) {
|
|
45
|
+
return userConfig.r_boolean_value || userConfig.u_boolean_value || false;
|
|
46
|
+
}
|
|
47
|
+
const useAccessControl = userConfig.use_access_control[accessType];
|
|
48
|
+
if ((useAccessControl || user_access_control_mode_1.UserAccessControlMode.Disabled) === user_access_control_mode_1.UserAccessControlMode.Disabled) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
return (userConfig.r_boolean_value && useAccessControl === user_access_control_mode_1.UserAccessControlMode.Rule) || (userConfig.u_boolean_value && useAccessControl === user_access_control_mode_1.UserAccessControlMode.User) || false;
|
|
29
52
|
}
|
|
30
|
-
async computeArgs(accessCondition, user, moduleName) {
|
|
53
|
+
async computeArgs(accessCondition, user, moduleName, tableName) {
|
|
31
54
|
if (!moduleName) {
|
|
32
55
|
moduleName = (await this.moduleConfigService.getModuleConfig()).name;
|
|
33
56
|
}
|
|
@@ -35,7 +58,7 @@ class UserConfigService {
|
|
|
35
58
|
moduleName,
|
|
36
59
|
await this.findBackEnd(moduleName),
|
|
37
60
|
].filter(f => f);
|
|
38
|
-
|
|
61
|
+
const r = {
|
|
39
62
|
user,
|
|
40
63
|
alias: 'd',
|
|
41
64
|
fields: [
|
|
@@ -111,6 +134,25 @@ class UserConfigService {
|
|
|
111
134
|
]
|
|
112
135
|
}
|
|
113
136
|
};
|
|
137
|
+
if (tableName) {
|
|
138
|
+
r.fields.push({
|
|
139
|
+
alias: 'use_access_control',
|
|
140
|
+
field: 'use_access_control',
|
|
141
|
+
table: 'td'
|
|
142
|
+
});
|
|
143
|
+
r.args['table_name'] = tableName;
|
|
144
|
+
r.join.push({
|
|
145
|
+
tableName: 'table_dictionary',
|
|
146
|
+
mode: interfaces_1.JoinMode.Inner,
|
|
147
|
+
alias: 'td',
|
|
148
|
+
on: {
|
|
149
|
+
v1: 'td.name',
|
|
150
|
+
operator: interfaces_1.ConditionalOpertator.equals,
|
|
151
|
+
v2: '$table_name'
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
return r;
|
|
114
156
|
}
|
|
115
157
|
}
|
|
116
158
|
exports.UserConfigService = UserConfigService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user-config.service.js","sourceRoot":"","sources":["../../../src/core/services/user-config.service.ts"],"names":[],"mappings":";;;AAAA,4BAA4B;AAM5B,8DAA+E;
|
|
1
|
+
{"version":3,"file":"user-config.service.js","sourceRoot":"","sources":["../../../src/core/services/user-config.service.ts"],"names":[],"mappings":";;;AAAA,4BAA4B;AAM5B,8DAA+E;AAC/E,oFAA8E;AAG9E,MAAa,iBAAiB;IAC5B,YACmB,mBAAwC,EACxC,iBAAoC,EACpC,aAA6B;QAF7B,wBAAmB,GAAnB,mBAAmB,CAAqB;QACxC,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,kBAAa,GAAb,aAAa,CAAgB;IAC5C,CAAC;IAEG,KAAK,CAAC,WAAW,CAAC,UAAkB;QAC1C,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,uBAAuB,EAAE,CAAA;QAC/D,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,UAAU,CAAC,CAAA;QACrD,OAAO,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,SAAS,CAAC,CAAA;IAC9B,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,EACT,eAAe,EACf,IAAI,EACJ,UAAU,GAKX;QACC,IAAI,IAAI,CAAC,QAAQ,KAAK,WAAW,EAAE;YACjC,OAAO,IAAI,CAAC;SACb;QAED,MAAM,OAAO,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,eAAe,CAAC,QAAQ,CAAC,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{
|
|
|
16
16
|
field: string;
|
|
17
17
|
} | string)[];
|
|
18
18
|
};
|
|
19
|
+
export interface UseAccessControl {
|
|
20
|
+
insert?: UserAccessControlMode;
|
|
21
|
+
update?: UserAccessControlMode;
|
|
22
|
+
delete?: UserAccessControlMode;
|
|
23
|
+
select?: UserAccessControlMode;
|
|
24
|
+
}
|
|
19
25
|
export interface TableDictionary {
|
|
20
26
|
puca_pid?: string;
|
|
21
27
|
name?: string;
|
|
@@ -28,10 +34,5 @@ export interface TableDictionary {
|
|
|
28
34
|
parent_access_control?: {
|
|
29
35
|
[field: string]: string;
|
|
30
36
|
};
|
|
31
|
-
use_access_control?:
|
|
32
|
-
insert?: UserAccessControlMode;
|
|
33
|
-
update?: UserAccessControlMode;
|
|
34
|
-
delete?: UserAccessControlMode;
|
|
35
|
-
select?: UserAccessControlMode;
|
|
36
|
-
};
|
|
37
|
+
use_access_control?: UseAccessControl;
|
|
37
38
|
}
|