tuain-form-manager 1.5.4 → 1.5.6
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/lib/form-manager.js +12 -4
- package/lib/form.js +31 -8
- package/package.json +1 -1
package/lib/form-manager.js
CHANGED
|
@@ -6,13 +6,16 @@ const { customizeFormDefinition } = require('./form-utils');
|
|
|
6
6
|
const START_OPERATION = 'startOperation';
|
|
7
7
|
|
|
8
8
|
class FormManager {
|
|
9
|
-
constructor(rootPath, formsDefinitions, cacheManager, appLogger, errMgr, formClasses = null) {
|
|
9
|
+
constructor(rootPath, formsDefinitions, cacheManager, appLogger, errMgr, formClasses = null, debugMode = false) {
|
|
10
10
|
this.rootPath = rootPath ?? '';
|
|
11
11
|
this.formsDefinitions = formsDefinitions;
|
|
12
12
|
this.formClasses = formClasses;
|
|
13
13
|
this._formsSignature = null;
|
|
14
14
|
this.logger = appLogger;
|
|
15
15
|
this.errMgr = errMgr;
|
|
16
|
+
// Controla si el detalle de los errores expone el mensaje/stack de la excepción.
|
|
17
|
+
// Se propaga a cada instancia de formulario. Default seguro: false (no expone).
|
|
18
|
+
this.debugMode = debugMode ?? false;
|
|
16
19
|
this.errMgr.addModuleSet('forms-lib', modErrs);
|
|
17
20
|
this.getFormsSignature = () => this._formsSignature;
|
|
18
21
|
this.calculateFormsSignature();
|
|
@@ -76,14 +79,15 @@ class FormManager {
|
|
|
76
79
|
[errorObj, formDefinition] = await this.executeFormStart(requestContext, formDefinition, formCode);
|
|
77
80
|
}
|
|
78
81
|
} catch (err) {
|
|
79
|
-
const
|
|
82
|
+
const context = `Excepción no controlada en ${formCode}`;
|
|
83
|
+
const errorDetail = `${context}: ${err.message}\n${err.stack}`;
|
|
80
84
|
this.logger.log({
|
|
81
85
|
level: 'error',
|
|
82
86
|
label: 'FormManager',
|
|
83
87
|
action: 'getFormDefinition',
|
|
84
88
|
message: errorDetail,
|
|
85
89
|
});
|
|
86
|
-
errorObj = this.errMgr.get(modErrs.getFormDefinition.formPopulateFail, errorDetail);
|
|
90
|
+
errorObj = this.errMgr.get(modErrs.getFormDefinition.formPopulateFail, this.debugMode ? errorDetail : context);
|
|
87
91
|
}
|
|
88
92
|
return [errorObj, formDefinition];
|
|
89
93
|
}
|
|
@@ -186,6 +190,9 @@ class FormManager {
|
|
|
186
190
|
errorObj = this.errMgr.get(modErrs.formActionExec.formNotFound, message);
|
|
187
191
|
return [errorObj, null];
|
|
188
192
|
}
|
|
193
|
+
// Propaga el modo depuración a la instancia del formulario para que sus
|
|
194
|
+
// manejadores de excepción decidan si exponen el mensaje/stack en el detalle.
|
|
195
|
+
formCustomObject.debugMode = this.debugMode;
|
|
189
196
|
[errorObj, resultForm] = await formCustomObject.executeFormAction(actionCode);
|
|
190
197
|
message = `END FORM ACTION ${formCode} / ${actionCode} / ${errorObj?.errorCode ?? ''}`;
|
|
191
198
|
this.logger.log({
|
|
@@ -196,6 +203,7 @@ class FormManager {
|
|
|
196
203
|
});
|
|
197
204
|
return [errorObj, resultForm];
|
|
198
205
|
} catch (err) {
|
|
206
|
+
const context = `Excepción no controlada. END BY EXCEPTION FORM ACTION ${formCode} / ${actionCode}`;
|
|
199
207
|
message =
|
|
200
208
|
`Excepción no controlada: ${err.message}\n${err.stack}` +
|
|
201
209
|
`------ END BY EXCEPTION FORM ACTION ${formCode} / ${actionCode} ------`;
|
|
@@ -205,7 +213,7 @@ class FormManager {
|
|
|
205
213
|
action: 'executeFormAction',
|
|
206
214
|
message,
|
|
207
215
|
});
|
|
208
|
-
errorObj = this.errMgr.get(modErrs.formActionExec.formNotFound, message);
|
|
216
|
+
errorObj = this.errMgr.get(modErrs.formActionExec.formNotFound, this.debugMode ? message : context);
|
|
209
217
|
return [errorObj, null];
|
|
210
218
|
}
|
|
211
219
|
}
|
package/lib/form.js
CHANGED
|
@@ -73,6 +73,9 @@ class Form {
|
|
|
73
73
|
constructor(logger, errMgr, requestContext, formDefinition, requestData) {
|
|
74
74
|
this.logger = logger;
|
|
75
75
|
this.errMgr = errMgr;
|
|
76
|
+
// Lo inyecta FormManager tras instanciar. Controla si el detalle del error
|
|
77
|
+
// expone el mensaje/stack de la excepción. Default seguro: false (no expone).
|
|
78
|
+
this.debugMode = false;
|
|
76
79
|
this._errorObject = null;
|
|
77
80
|
this._formDefinition = formDefinition;
|
|
78
81
|
|
|
@@ -745,9 +748,10 @@ class Form {
|
|
|
745
748
|
try {
|
|
746
749
|
errorObj = await callback(fieldCode, fieldValue);
|
|
747
750
|
} catch (err) {
|
|
748
|
-
|
|
751
|
+
const context = `Excepción en validación de ${fieldCode}`;
|
|
752
|
+
message = `${context}: ${err.message} / ${err.stack}`;
|
|
749
753
|
this.logger.log({ level: 'error', label: 'fieldValidation', action: fieldCode, message });
|
|
750
|
-
errorObj = this.errMgr.get(modErrs.fieldValidation.exceptionNotHandled, message);
|
|
754
|
+
errorObj = this.errMgr.get(modErrs.fieldValidation.exceptionNotHandled, this.debugMode ? message : context);
|
|
751
755
|
}
|
|
752
756
|
return errorObj;
|
|
753
757
|
}
|
|
@@ -773,9 +777,10 @@ class Form {
|
|
|
773
777
|
try {
|
|
774
778
|
errorObj = await callback(actionCode);
|
|
775
779
|
} catch (err) {
|
|
776
|
-
|
|
780
|
+
const context = `Excepción en acción de ${actionCode}`;
|
|
781
|
+
message = `${context}: ${err.message} / ${err.stack}`;
|
|
777
782
|
this.logger.log({ level: 'error', label: 'executeFormAction', action: actionCode, message });
|
|
778
|
-
errorObj = this.errMgr.get(modErrs.formActionExec.exceptionNotHandled, message);
|
|
783
|
+
errorObj = this.errMgr.get(modErrs.formActionExec.exceptionNotHandled, this.debugMode ? message : context);
|
|
779
784
|
}
|
|
780
785
|
return [errorObj, this.getExportData()];
|
|
781
786
|
}
|
|
@@ -838,6 +843,22 @@ class Form {
|
|
|
838
843
|
return responseTable.fields[fieldCode];
|
|
839
844
|
}
|
|
840
845
|
|
|
846
|
+
setTableRecords(tableCode, records = [], options = {}) {
|
|
847
|
+
const responseTable = this.getResponseTable(tableCode);
|
|
848
|
+
if (!responseTable || !records || !Array.isArray(records)) {
|
|
849
|
+
return;
|
|
850
|
+
}
|
|
851
|
+
const idField = options?.idField ?? Object.keys(records?.[0] ?? {})?.[0];
|
|
852
|
+
const tableDef = this.getTableDefinition(tableCode);
|
|
853
|
+
const columns = tableDef?.fields.map((flds) => flds.fieldCode) ?? [];
|
|
854
|
+
const tableRecords = records.map((record, index) => ({
|
|
855
|
+
tableRecordId: record[idField] ?? index,
|
|
856
|
+
recordData: columns.map((fieldCode) => ({ fieldCode, fieldValue: record[fieldCode] ?? '' })),
|
|
857
|
+
}));
|
|
858
|
+
this.setTableConstraints(tableCode, options);
|
|
859
|
+
Object.assign(responseTable, { tableRecords });
|
|
860
|
+
}
|
|
861
|
+
|
|
841
862
|
fillTable(records, mapping) {
|
|
842
863
|
const { tableCode, recordIdField, recordColumnsNames, recordItemAttributes } = mapping;
|
|
843
864
|
const responseTable = this.getResponseTable(tableCode);
|
|
@@ -1037,9 +1058,10 @@ class Form {
|
|
|
1037
1058
|
});
|
|
1038
1059
|
errorObject = await tableActionCallback(tableCode, actionCode, tableRecordId, tableRecordData ?? {});
|
|
1039
1060
|
} catch (err) {
|
|
1040
|
-
|
|
1061
|
+
const context = `Excepción no soportada en acción ${actionCode} sobre la tabla ${tableCode}`;
|
|
1062
|
+
message = `${context} : ${err.message} / ${err.stack}`;
|
|
1041
1063
|
this.logger.log({ level: 'error', label: 'tableAction', action: actionCode, message });
|
|
1042
|
-
errorObject = this.errMgr.get(modErrs.tableActionExec.noCallback, message);
|
|
1064
|
+
errorObject = this.errMgr.get(modErrs.tableActionExec.noCallback, this.debugMode ? message : context);
|
|
1043
1065
|
}
|
|
1044
1066
|
return errorObject;
|
|
1045
1067
|
}
|
|
@@ -1070,9 +1092,10 @@ class Form {
|
|
|
1070
1092
|
}
|
|
1071
1093
|
errorObject = await tablePopulateCallback(tableCode, this.actionSubject);
|
|
1072
1094
|
} catch (err) {
|
|
1073
|
-
|
|
1095
|
+
const context = `Excepción no soportada en el poblamiento de la tabla ${tableCode} en ${this.formCode}`;
|
|
1096
|
+
message = `${context}: ${err} / ${err.stack}`;
|
|
1074
1097
|
this.logger.log({ level: 'error', label: 'executeTablePopulate', action: tableCode, message });
|
|
1075
|
-
errorObject = this.errMgr.get(modErrs.tablePopulate.exceptionNotHandled, message);
|
|
1098
|
+
errorObject = this.errMgr.get(modErrs.tablePopulate.exceptionNotHandled, this.debugMode ? message : context);
|
|
1076
1099
|
}
|
|
1077
1100
|
return errorObject;
|
|
1078
1101
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tuain-form-manager",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.6",
|
|
4
4
|
"description": "Component library to perform operations on Tuain Development Framework forms to interchange information on web or mobile applications based on the data interchange of abstract forms making trnasformation on the data upon actions required on both sides (front and back)",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|