@ejfdelgado/ejflab-common 1.8.2 → 1.8.4
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/package.json
CHANGED
package/src/MyTemplate.js
CHANGED
|
@@ -194,7 +194,7 @@ class MyTemplate extends CsvWithFilters {
|
|
|
194
194
|
};
|
|
195
195
|
}
|
|
196
196
|
}
|
|
197
|
-
render(template, data) {
|
|
197
|
+
render(template, data, skipUndefined = false) {
|
|
198
198
|
|
|
199
199
|
let iteration = {};
|
|
200
200
|
do {
|
|
@@ -209,19 +209,32 @@ class MyTemplate extends CsvWithFilters {
|
|
|
209
209
|
} while (iteration.times > 0);
|
|
210
210
|
|
|
211
211
|
// Replace values
|
|
212
|
-
return this.replaceBareValues(template, data);
|
|
212
|
+
return this.replaceBareValues(template, data, undefined, undefined, undefined, false, skipUndefined);
|
|
213
213
|
}
|
|
214
|
-
replaceBareValues(template, data, open = "\\{", close = "\\}", closeNoScape = "}", useStringify = false) {
|
|
214
|
+
replaceBareValues(template, data, open = "\\{", close = "\\}", closeNoScape = "}", useStringify = false, skipUndefined = false) {
|
|
215
215
|
const myPattern = new RegExp("\\$\\s*" + open + "([^" + closeNoScape + "]+)\\s*" + close, "g");
|
|
216
216
|
template = template.replace(myPattern, (match, g1) => {
|
|
217
217
|
const response = this.getColumnDescription(g1)[0];
|
|
218
218
|
const valor = SimpleObj.getValue(data, response.id);
|
|
219
219
|
if (!useStringify) {
|
|
220
220
|
const temp = this.filterValue(valor, response, undefined, response.id);
|
|
221
|
-
if (
|
|
222
|
-
|
|
221
|
+
if (!skipUndefined) {
|
|
222
|
+
// Duplicated code...
|
|
223
|
+
if (typeof temp == "object") {
|
|
224
|
+
return JSON.stringify(temp);
|
|
225
|
+
}
|
|
226
|
+
return temp;
|
|
227
|
+
} else {
|
|
228
|
+
if (temp === undefined) {
|
|
229
|
+
return match;
|
|
230
|
+
} else {
|
|
231
|
+
// Duplicated code...
|
|
232
|
+
if (typeof temp == "object") {
|
|
233
|
+
return JSON.stringify(temp);
|
|
234
|
+
}
|
|
235
|
+
return temp;
|
|
236
|
+
}
|
|
223
237
|
}
|
|
224
|
-
return temp;
|
|
225
238
|
} else {
|
|
226
239
|
const temp = this.filterValue(valor, response, undefined, response.id);
|
|
227
240
|
return JSON.stringify(temp);
|
package/src/MyTemplate.test.js
CHANGED
|
@@ -63,7 +63,19 @@ function myTest() {
|
|
|
63
63
|
]
|
|
64
64
|
},
|
|
65
65
|
exp: "Filtrado 3 sí debe salir",
|
|
66
|
-
}
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
txt: "my name is ${name} ${lastname} and I like ${colors.0.id} ${colors.0.id}",
|
|
69
|
+
data: { lastname: "Delgado" },
|
|
70
|
+
exp: "my name is ${name} Delgado and I like ${colors.0.id} ${colors.0.id}",
|
|
71
|
+
skipUndefined: true,
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
txt: "my name is ${name} ${lastname} and I like ${colors.0.id} ${colors.0.id}",
|
|
75
|
+
data: { lastname: "Delgado" },
|
|
76
|
+
exp: "my name is undefined Delgado and I like undefined undefined",
|
|
77
|
+
skipUndefined: false,
|
|
78
|
+
},
|
|
67
79
|
];
|
|
68
80
|
|
|
69
81
|
renderer.registerFunction("json", CsvFormatterFilters.json);
|
|
@@ -75,7 +87,7 @@ function myTest() {
|
|
|
75
87
|
|
|
76
88
|
for (let i = 0; i < cases.length; i++) {
|
|
77
89
|
const myCase = cases[i];
|
|
78
|
-
const actual = renderer.render(myCase.txt, myCase.data);
|
|
90
|
+
const actual = renderer.render(myCase.txt, myCase.data, myCase.skipUndefined === true);
|
|
79
91
|
//console.log(actual);
|
|
80
92
|
if (actual !== myCase.exp) {
|
|
81
93
|
throw Error(`expected:\n${myCase.exp}\nactual:\n${actual}`);
|
|
@@ -28,6 +28,7 @@ const { CommandMongo } = require('./steps/CommandMongo');
|
|
|
28
28
|
const { CommandMinio } = require('./steps/CommandMinio');
|
|
29
29
|
const { CommandPostgres } = require('./steps/CommandPostgres.js');
|
|
30
30
|
const { StepMultiple } = require('./steps/StepMultiple.js');
|
|
31
|
+
const { StepMultipleDone } = require('./steps/StepMultipleDone.js');
|
|
31
32
|
|
|
32
33
|
class FlowChartExec {
|
|
33
34
|
executionPromise = null;
|
|
@@ -61,6 +62,7 @@ class FlowChartExec {
|
|
|
61
62
|
this.registry["process"] = StepProcess;
|
|
62
63
|
this.registry["require"] = StepCheckProcessor;
|
|
63
64
|
this.registry["multiple"] = StepMultiple;
|
|
65
|
+
this.registry["multipleDone"] = StepMultipleDone;
|
|
64
66
|
|
|
65
67
|
// Nodes
|
|
66
68
|
this.registry["inc"] = CommandInc;
|
|
@@ -276,11 +278,12 @@ class FlowChartExec {
|
|
|
276
278
|
return this.loadFlowChartInternal(paths, true);
|
|
277
279
|
}
|
|
278
280
|
|
|
279
|
-
complementFlowChart(paths) {
|
|
280
|
-
|
|
281
|
+
complementFlowChart(paths, indexPath) {
|
|
282
|
+
console.log("complementFlowChart...");
|
|
283
|
+
return this.loadFlowChartInternal(paths, false, indexPath);
|
|
281
284
|
}
|
|
282
285
|
|
|
283
|
-
loadFlowChartInternal(paths, initialize) {
|
|
286
|
+
loadFlowChartInternal(paths, initialize, indexPath) {
|
|
284
287
|
if (initialize) {
|
|
285
288
|
this.flowchart = {
|
|
286
289
|
shapes: [],
|
|
@@ -295,6 +298,12 @@ class FlowChartExec {
|
|
|
295
298
|
};
|
|
296
299
|
const llaves = Object.keys(paths);
|
|
297
300
|
llaves.forEach((prefix) => {
|
|
301
|
+
// Get index Number from prefix if matches the pattern
|
|
302
|
+
const prefixGroupsNumber = /_([\d]+)$/.exec(prefix);
|
|
303
|
+
let index = null;
|
|
304
|
+
if (prefixGroupsNumber) {
|
|
305
|
+
index = parseInt(prefixGroupsNumber[1]);
|
|
306
|
+
}
|
|
298
307
|
const path = paths[prefix];
|
|
299
308
|
const xmlFlowText = fs.readFileSync(path, 'utf8');
|
|
300
309
|
const parser = new XMLParser(options);
|
|
@@ -303,6 +312,19 @@ class FlowChartExec {
|
|
|
303
312
|
this.interpretColor(localFlowChart.shapes);
|
|
304
313
|
//
|
|
305
314
|
const check = this.checkTypeOfChart(localFlowChart);
|
|
315
|
+
if (typeof indexPath == "string" && !isNaN(index)) {
|
|
316
|
+
// Write metadata of node
|
|
317
|
+
const placeMetadata = (node) => {
|
|
318
|
+
node.indexPath = indexPath;
|
|
319
|
+
SimpleObj.recreate(node, `meta.${indexPath}`, index);
|
|
320
|
+
}
|
|
321
|
+
localFlowChart.shapes.forEach(placeMetadata);
|
|
322
|
+
localFlowChart.arrows.forEach(placeMetadata);
|
|
323
|
+
const startingPoints = this.getNodesWithText("start", undefined, localFlowChart);
|
|
324
|
+
if (this.actualNodes instanceof Array && startingPoints instanceof Array) {
|
|
325
|
+
this.actualNodes.push(...startingPoints);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
306
328
|
this.flowchart.shapes.push(...localFlowChart.shapes);
|
|
307
329
|
this.flowchart.arrows.push(...localFlowChart.arrows);
|
|
308
330
|
this.flowchart.prefixes.push(prefix);
|
|
@@ -313,8 +335,6 @@ class FlowChartExec {
|
|
|
313
335
|
}
|
|
314
336
|
});
|
|
315
337
|
|
|
316
|
-
//console.log(JSON.stringify(this.flowchart.flux, null, 4));
|
|
317
|
-
|
|
318
338
|
// Se indexan los nodos por id
|
|
319
339
|
const BLACK_LIST = ["flux"];
|
|
320
340
|
this.flowchart.shapes.forEach((node) => {
|
|
@@ -359,7 +379,7 @@ class FlowChartExec {
|
|
|
359
379
|
return instance;
|
|
360
380
|
}
|
|
361
381
|
|
|
362
|
-
interpretArguments(argTxt) {
|
|
382
|
+
interpretArguments(argTxt, node) {
|
|
363
383
|
//console.log(`Interpret ${argTxt}`);
|
|
364
384
|
const tokens = argTxt.split(";");
|
|
365
385
|
const args = [];
|
|
@@ -367,7 +387,13 @@ class FlowChartExec {
|
|
|
367
387
|
const token = tokens[i];
|
|
368
388
|
// Interpret with template
|
|
369
389
|
if (token.trim().length > 0) {
|
|
370
|
-
|
|
390
|
+
let rendered = token;
|
|
391
|
+
if (node.meta) {
|
|
392
|
+
// Render skiping meta
|
|
393
|
+
const skipUndefined = true;
|
|
394
|
+
rendered = this.renderer.render(rendered, node.meta, skipUndefined);
|
|
395
|
+
}
|
|
396
|
+
rendered = this.renderer.render(rendered, this.data);
|
|
371
397
|
let value;
|
|
372
398
|
try {
|
|
373
399
|
value = eval(rendered);
|
|
@@ -388,7 +414,7 @@ class FlowChartExec {
|
|
|
388
414
|
}
|
|
389
415
|
let index = 0;
|
|
390
416
|
const answered = await MyUtilities.replaceAsync2(txt, /(([a-z]+)«([^»]*)»)/ig, async (match, g1, commandName, argsTxt) => {
|
|
391
|
-
const args = this.interpretArguments(argsTxt);
|
|
417
|
+
const args = this.interpretArguments(argsTxt, node);
|
|
392
418
|
let instance = this.createInstance(commandName, id, txt, args);
|
|
393
419
|
index++;
|
|
394
420
|
const response1 = `${commandName}${JSON.stringify(args)}`;
|
|
@@ -416,7 +442,7 @@ class FlowChartExec {
|
|
|
416
442
|
}
|
|
417
443
|
let index = 0;
|
|
418
444
|
const answered = await MyUtilities.replaceAsync2(txt, /(([a-z]+)«([^»]*)»)/ig, async (match, g1, commandName, argsTxt) => {
|
|
419
|
-
const args = this.interpretArguments(argsTxt);
|
|
445
|
+
const args = this.interpretArguments(argsTxt, node);
|
|
420
446
|
let instance = null;
|
|
421
447
|
if (create || !this.instances[id][`${index}`]) {
|
|
422
448
|
instance = this.createInstance(commandName, id, txt, args);
|
|
@@ -20,25 +20,38 @@ class StepMultiple extends StepBasic {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
async execFirst() {
|
|
23
|
+
// console.log(`StepMultiple ${JSON.stringify(this.args)}`);
|
|
23
24
|
// Reads the list to iterate
|
|
24
25
|
const room = this.context.getRoom();
|
|
25
26
|
this.list = SimpleObj.getValue(this.context.data, this.args[1], []);
|
|
26
|
-
const WORKSPACE = SimpleObj.getValue(this.context.data, "env.WORKSPACE", "
|
|
27
|
-
//console.log(`WORKSPACE=${WORKSPACE}`);
|
|
28
|
-
//console.log(`My list ${JSON.stringify(this.list)}`);
|
|
29
|
-
// Loads the draw.io file
|
|
27
|
+
const WORKSPACE = SimpleObj.getValue(this.context.data, "env.WORKSPACE", ".");
|
|
30
28
|
const flowChartTemplateName = this.args[0];
|
|
31
|
-
const
|
|
32
|
-
Print: '${WORKSPACE}/flowcharts/multiple/flow01N.drawio',
|
|
33
|
-
};
|
|
34
|
-
this.completePaths(extraConfiguration, WORKSPACE);
|
|
29
|
+
const indexPath = this.args[2];
|
|
35
30
|
// Force update the model
|
|
36
31
|
const superContext = this.context.getSuperContext();
|
|
37
32
|
const roomData = superContext.getRoomLiveTupleModel(room);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
33
|
+
const routeMultiple = SimpleObj.getValue(roomData, `model.multiples.${flowChartTemplateName}`, null);
|
|
34
|
+
//console.log(`flowChartTemplateName=${flowChartTemplateName} routeMultiple=${routeMultiple}`)
|
|
35
|
+
if (typeof indexPath !== "string") {
|
|
36
|
+
console.log(`In StepMultiple, indexPath is not a string ${JSON.stringify(this.args)}`);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (routeMultiple) {
|
|
40
|
+
const extraConfiguration = {};
|
|
41
|
+
|
|
42
|
+
for (let i = 0; i < this.list.length; i++) {
|
|
43
|
+
extraConfiguration[`${flowChartTemplateName}_${i}`] = routeMultiple;
|
|
44
|
+
}
|
|
45
|
+
this.completePaths(extraConfiguration, WORKSPACE);
|
|
46
|
+
|
|
47
|
+
roomData.model.flowchart = this.context.complementFlowChart(extraConfiguration, indexPath);
|
|
48
|
+
let changes = roomData.builder.trackDifferences(roomData.model, [], null, ["flowchart"]);
|
|
49
|
+
roomData.model = roomData.builder.affect(changes);
|
|
50
|
+
superContext.emitToRoom(room, "flowChartModified");
|
|
51
|
+
} else {
|
|
52
|
+
console.log(`In StepMultiple, can't find model.multiples.${flowChartTemplateName}`);
|
|
53
|
+
//console.log(JSON.stringify(roomData, null, 4));
|
|
54
|
+
}
|
|
42
55
|
}
|
|
43
56
|
|
|
44
57
|
async canContinue() {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const { StepBasic } = require("./StepBasic");
|
|
2
|
+
const { SimpleObj } = require("../../SimpleObj");
|
|
3
|
+
|
|
4
|
+
class StepMultipleDone extends StepBasic {
|
|
5
|
+
list = [];
|
|
6
|
+
constructor(context, id, commandName, argsTxt) {
|
|
7
|
+
super(context, id, commandName, argsTxt);
|
|
8
|
+
super.alwaysEvaluateCanContinue = true;
|
|
9
|
+
}
|
|
10
|
+
async execFirst() { }
|
|
11
|
+
|
|
12
|
+
async canContinue() {
|
|
13
|
+
this.list = SimpleObj.getValue(this.context.data, this.args[0], []);
|
|
14
|
+
if (!(this.list instanceof Array)) {
|
|
15
|
+
console.log(`In StepMultipleDone, warning ${this.args[0]} is not a list!`);
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
for (let i = 0; i < this.list.length; i++) {
|
|
19
|
+
const element = this.list[i];
|
|
20
|
+
if (element.done !== true) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports = {
|
|
29
|
+
StepMultipleDone
|
|
30
|
+
};
|