@ejfdelgado/ejflab-common 1.8.3 → 1.8.5

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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ejfdelgado/ejflab-common",
3
3
  "type": "commonjs",
4
- "version": "1.8.3",
4
+ "version": "1.8.5",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/ejfdelgado/ejflab-common.git"
package/src/MyTemplate.js CHANGED
@@ -209,7 +209,7 @@ class MyTemplate extends CsvWithFilters {
209
209
  } while (iteration.times > 0);
210
210
 
211
211
  // Replace values
212
- return this.replaceBareValues(template, data, "\\{", "\\}", "}", false, skipUndefined);
212
+ return this.replaceBareValues(template, data, undefined, undefined, undefined, false, skipUndefined);
213
213
  }
214
214
  replaceBareValues(template, data, open = "\\{", close = "\\}", closeNoScape = "}", useStringify = false, skipUndefined = false) {
215
215
  const myPattern = new RegExp("\\$\\s*" + open + "([^" + closeNoScape + "]+)\\s*" + close, "g");
@@ -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,12 +278,13 @@ class FlowChartExec {
276
278
  return this.loadFlowChartInternal(paths, true);
277
279
  }
278
280
 
279
- complementFlowChart(paths, indexPath) {
280
- console.log("complementFlowChart...");
281
- return this.loadFlowChartInternal(paths, false, indexPath);
281
+ complementFlowChart(paths, indexPath, parentNode) {
282
+ //console.log(`complementFlowChart indexPath=${indexPath}`);
283
+ return this.loadFlowChartInternal(paths, false, indexPath, parentNode);
282
284
  }
283
285
 
284
- loadFlowChartInternal(paths, initialize, indexPath) {
286
+ loadFlowChartInternal(paths, initialize, indexPath, parentNode = {}) {
287
+ //console.log(`loadFlowChartInternal indexPath=${indexPath}`);
285
288
  if (initialize) {
286
289
  this.flowchart = {
287
290
  shapes: [],
@@ -314,10 +317,19 @@ class FlowChartExec {
314
317
  // Write metadata of node
315
318
  const placeMetadata = (node) => {
316
319
  node.indexPath = indexPath;
320
+ // Read the parent meta
321
+ if (parentNode.meta) {
322
+ SimpleObj.recreate(node, "meta", JSON.parse(JSON.stringify(parentNode.meta)));
323
+ }
317
324
  SimpleObj.recreate(node, `meta.${indexPath}`, index);
325
+ //console.log(node.prefix + ":" + JSON.stringify(node.meta));
318
326
  }
319
327
  localFlowChart.shapes.forEach(placeMetadata);
320
328
  localFlowChart.arrows.forEach(placeMetadata);
329
+ const startingPoints = this.getNodesWithText("start", undefined, localFlowChart);
330
+ if (this.actualNodes instanceof Array && startingPoints instanceof Array) {
331
+ this.actualNodes.push(...startingPoints);
332
+ }
321
333
  }
322
334
  this.flowchart.shapes.push(...localFlowChart.shapes);
323
335
  this.flowchart.arrows.push(...localFlowChart.arrows);
@@ -385,7 +397,9 @@ class FlowChartExec {
385
397
  if (node.meta) {
386
398
  // Render skiping meta
387
399
  const skipUndefined = true;
400
+ //console.log(`${rendered} ${JSON.stringify(node.meta)}`);
388
401
  rendered = this.renderer.render(rendered, node.meta, skipUndefined);
402
+ //console.log(`${rendered}`);
389
403
  }
390
404
  rendered = this.renderer.render(rendered, this.data);
391
405
  let value;
@@ -412,7 +426,7 @@ class FlowChartExec {
412
426
  let instance = this.createInstance(commandName, id, txt, args);
413
427
  index++;
414
428
  const response1 = `${commandName}${JSON.stringify(args)}`;
415
- const { canContinue, abort } = await instance.executeAsNode(args, argsTxt);
429
+ const { canContinue, abort } = await instance.executeAsNode(args, argsTxt, node);
416
430
  if (abort) {
417
431
  // Panic and halt all
418
432
  this.mustEnd = true;
@@ -449,7 +463,7 @@ class FlowChartExec {
449
463
  }
450
464
  index++;
451
465
  const response1 = `${commandName}${JSON.stringify(args)}`;
452
- const { canContinue, abort } = await instance.executeAsArrow(args, argsTxt);
466
+ const { canContinue, abort } = await instance.executeAsArrow(args, argsTxt, node);
453
467
  if (abort) {
454
468
  // Panic and halt all
455
469
  this.mustEnd = true;
@@ -66,7 +66,8 @@ class StepBasic {
66
66
  SimpleObj.recreate(this.context.data, `performance.${id}.time`, val.time);
67
67
  }
68
68
  }
69
- async executeAsNode(args, argsTxtIndividual) {
69
+ async executeAsNode(args, argsTxtIndividual, node) {
70
+ this.node = node;
70
71
  this.argsTxtIndividual = argsTxtIndividual;
71
72
  const answer = {
72
73
  canContinue: false,
@@ -100,7 +101,8 @@ class StepBasic {
100
101
  return answer;
101
102
  }
102
103
  }
103
- async executeAsArrow(args, argsTxtIndividual) {
104
+ async executeAsArrow(args, argsTxtIndividual, node) {
105
+ this.node = node;
104
106
  this.argsTxtIndividual = argsTxtIndividual;
105
107
  const answer = {
106
108
  canContinue: false,
@@ -38,13 +38,15 @@ class StepMultiple extends StepBasic {
38
38
  }
39
39
  if (routeMultiple) {
40
40
  const extraConfiguration = {};
41
-
41
+ let prefixName = `${flowChartTemplateName}_`;
42
+ if (typeof this.node.prefix == "string") {
43
+ prefixName = this.node.prefix + "_" + prefixName;
44
+ }
42
45
  for (let i = 0; i < this.list.length; i++) {
43
- extraConfiguration[`${flowChartTemplateName}_${i}`] = routeMultiple;
46
+ extraConfiguration[prefixName + i] = routeMultiple;
44
47
  }
45
48
  this.completePaths(extraConfiguration, WORKSPACE);
46
-
47
- roomData.model.flowchart = this.context.complementFlowChart(extraConfiguration, indexPath);
49
+ roomData.model.flowchart = this.context.complementFlowChart(extraConfiguration, indexPath, this.node);
48
50
  let changes = roomData.builder.trackDifferences(roomData.model, [], null, ["flowchart"]);
49
51
  roomData.model = roomData.builder.affect(changes);
50
52
  superContext.emitToRoom(room, "flowChartModified");
@@ -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
+ };