@ejfdelgado/ejflab-common 1.8.4 → 1.9.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ejfdelgado/ejflab-common",
3
3
  "type": "commonjs",
4
- "version": "1.8.4",
4
+ "version": "1.9.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/ejfdelgado/ejflab-common.git"
@@ -85,19 +85,28 @@ class FlowChartExec {
85
85
  }
86
86
 
87
87
  saveBufferData(sourceId, pathId, buffer) {
88
- //console.log(`saveBufferData ${sourceId} ${pathId}`, buffer);
89
- if (!this.bufferData[sourceId]) {
90
- this.bufferData[sourceId] = {};
88
+ let pathId2 = pathId;
89
+ if (!pathId2.startsWith(".")) {
90
+ pathId2 = "." + pathId2;
91
91
  }
92
- this.bufferData[sourceId][pathId] = buffer;
92
+ const compoundKey = `${sourceId}${pathId2}`;
93
+ const parts = /^(.*)\.([^.]+)$/.exec(compoundKey);
94
+ if (!parts) {
95
+ console.log("ERROR! Key must contain at least two parts separated with a dot");
96
+ return;
97
+ }
98
+ const baseKey = parts[1];
99
+ const endKey = parts[2];
100
+ SimpleObj.recreate(this.bufferData, compoundKey, true);
101
+ const baseObject = SimpleObj.getValue(this.bufferData, baseKey, {});
102
+ baseObject[endKey] = buffer;
93
103
  }
94
104
 
95
105
  readBufferData(sourceId, pathId) {
96
- //console.log(`readBufferData ${sourceId} ${pathId}`);
97
- if (!this.bufferData[sourceId]) {
98
- this.bufferData[sourceId] = {};
106
+ if (!pathId.startsWith(".")) {
107
+ pathId = "." + pathId;
99
108
  }
100
- return this.bufferData[sourceId][pathId];
109
+ return SimpleObj.getValue(this.bufferData, `${sourceId}${pathId}`, null);
101
110
  }
102
111
 
103
112
  registerPendingCall(id, val = true) {
@@ -278,12 +287,13 @@ class FlowChartExec {
278
287
  return this.loadFlowChartInternal(paths, true);
279
288
  }
280
289
 
281
- complementFlowChart(paths, indexPath) {
282
- console.log("complementFlowChart...");
283
- return this.loadFlowChartInternal(paths, false, indexPath);
290
+ complementFlowChart(paths, indexPath, parentNode) {
291
+ //console.log(`complementFlowChart indexPath=${indexPath}`);
292
+ return this.loadFlowChartInternal(paths, false, indexPath, parentNode);
284
293
  }
285
294
 
286
- loadFlowChartInternal(paths, initialize, indexPath) {
295
+ loadFlowChartInternal(paths, initialize, indexPath, parentNode = {}) {
296
+ //console.log(`loadFlowChartInternal indexPath=${indexPath}`);
287
297
  if (initialize) {
288
298
  this.flowchart = {
289
299
  shapes: [],
@@ -316,7 +326,12 @@ class FlowChartExec {
316
326
  // Write metadata of node
317
327
  const placeMetadata = (node) => {
318
328
  node.indexPath = indexPath;
329
+ // Read the parent meta
330
+ if (parentNode.meta) {
331
+ SimpleObj.recreate(node, "meta", JSON.parse(JSON.stringify(parentNode.meta)));
332
+ }
319
333
  SimpleObj.recreate(node, `meta.${indexPath}`, index);
334
+ //console.log(node.prefix + ":" + JSON.stringify(node.meta));
320
335
  }
321
336
  localFlowChart.shapes.forEach(placeMetadata);
322
337
  localFlowChart.arrows.forEach(placeMetadata);
@@ -391,7 +406,9 @@ class FlowChartExec {
391
406
  if (node.meta) {
392
407
  // Render skiping meta
393
408
  const skipUndefined = true;
409
+ //console.log(`${rendered} ${JSON.stringify(node.meta)}`);
394
410
  rendered = this.renderer.render(rendered, node.meta, skipUndefined);
411
+ //console.log(`${rendered}`);
395
412
  }
396
413
  rendered = this.renderer.render(rendered, this.data);
397
414
  let value;
@@ -418,7 +435,7 @@ class FlowChartExec {
418
435
  let instance = this.createInstance(commandName, id, txt, args);
419
436
  index++;
420
437
  const response1 = `${commandName}${JSON.stringify(args)}`;
421
- const { canContinue, abort } = await instance.executeAsNode(args, argsTxt);
438
+ const { canContinue, abort } = await instance.executeAsNode(args, argsTxt, node);
422
439
  if (abort) {
423
440
  // Panic and halt all
424
441
  this.mustEnd = true;
@@ -455,7 +472,7 @@ class FlowChartExec {
455
472
  }
456
473
  index++;
457
474
  const response1 = `${commandName}${JSON.stringify(args)}`;
458
- const { canContinue, abort } = await instance.executeAsArrow(args, argsTxt);
475
+ const { canContinue, abort } = await instance.executeAsArrow(args, argsTxt, node);
459
476
  if (abort) {
460
477
  // Panic and halt all
461
478
  this.mustEnd = true;
@@ -8,12 +8,17 @@ class CommandMinio extends CommandBasic {
8
8
  const minioSrv = this.context.getSuperContext().getMinioClient();
9
9
 
10
10
  if (action == "write") {
11
- const objectPath = this.args[2];
11
+ let objectPath = this.args[2];
12
12
  const sourcePath = this.args[3];
13
13
  const metadata = this.args[4];
14
+ let extra = this.resolveArgument(objectPath);
15
+ if (typeof extra == "string") {
16
+ objectPath = extra;
17
+ }
14
18
  //console.log(`CommandMinio.write bucket ${bucketName} objectPath ${objectPath} from ${sourcePath}`);
15
19
  //console.log(metadata);
16
20
  const bytes = this.resolveArgument(sourcePath);
21
+ //console.log(bytes);
17
22
  // Armar el payload para minio
18
23
  const payload = {
19
24
  objectPath, bytes, metadata
@@ -5,7 +5,7 @@ class CommandSet extends CommandBasic {
5
5
  async computation() {
6
6
  const path = this.args[0];
7
7
  const val = this.args[1];
8
- SimpleObj.recreate(this.context.data, path, val);
8
+ this.writeArgument(path, val);
9
9
  }
10
10
  }
11
11
 
@@ -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,
@@ -202,7 +204,7 @@ class StepBasic {
202
204
  // It reads from buffer
203
205
  buffer = this.context.readBufferData(sourceId, pathId);
204
206
  if (!buffer) {
205
- console.log(`No buffer in ${sourceId} ${pathId}`);
207
+ console.log(`No buffer in ${sourceId}${pathId}`);
206
208
  return undefined;
207
209
  }
208
210
  } else {
@@ -212,15 +214,43 @@ class StepBasic {
212
214
  return buffer;
213
215
  }
214
216
 
215
- resolveArgument(val) {
216
- const partsSource = /^(b\.([^.]+)\.([^.]+)|d\.(.+))$/i.exec(val);
217
+ breakPath(val) {
218
+ const partsSource = /^(b\.([^.]+)([^\s]+)|d.(.+))$/i.exec(val);
217
219
  if (partsSource == null) {
218
- console.log(`${val} doesn't match ^(b\.([^.]+)\.([^.]+)|d\.(.+))$`);
220
+ //console.log(`${val} doesn't match ^(b\.([^.]+)([^\s]+)|d.(.+))$`);
219
221
  return undefined;
220
222
  }
221
- const buffer = this.readInputFrom(!partsSource[4], partsSource[2], partsSource[3], partsSource[4]);
223
+ return {
224
+ isBuffer: !partsSource[4],
225
+ sourceId: partsSource[2],
226
+ pathId: partsSource[3],
227
+ completePath: partsSource[4]
228
+ };
229
+ }
230
+
231
+ resolveArgument(val) {
232
+ const breaked = this.breakPath(val);
233
+ let buffer = null;
234
+ if (breaked) {
235
+ buffer = this.readInputFrom(breaked.isBuffer, breaked.sourceId, breaked.pathId, breaked.completePath);
236
+ } else {
237
+ buffer = SimpleObj.getValue(this.context.data, val, null);
238
+ }
222
239
  return buffer;
223
240
  }
241
+
242
+ writeArgument(path, val) {
243
+ const braked = this.breakPath(path);
244
+ if (braked) {
245
+ if (braked.isBuffer) {
246
+ this.context.saveBufferData(braked.sourceId, braked.pathId, val);
247
+ } else {
248
+ SimpleObj.recreate(this.context.data, braked.completePath, val);
249
+ }
250
+ } else {
251
+ SimpleObj.recreate(this.context.data, path, val);
252
+ }
253
+ }
224
254
  }
225
255
 
226
256
  module.exports = {
@@ -23,7 +23,7 @@ class StepMultiple extends StepBasic {
23
23
  // console.log(`StepMultiple ${JSON.stringify(this.args)}`);
24
24
  // Reads the list to iterate
25
25
  const room = this.context.getRoom();
26
- this.list = SimpleObj.getValue(this.context.data, this.args[1], []);
26
+ this.list = this.resolveArgument(this.args[1]);
27
27
  const WORKSPACE = SimpleObj.getValue(this.context.data, "env.WORKSPACE", ".");
28
28
  const flowChartTemplateName = this.args[0];
29
29
  const indexPath = this.args[2];
@@ -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");
@@ -10,7 +10,7 @@ class StepMultipleDone extends StepBasic {
10
10
  async execFirst() { }
11
11
 
12
12
  async canContinue() {
13
- this.list = SimpleObj.getValue(this.context.data, this.args[0], []);
13
+ this.list = this.resolveArgument(this.args[0]);
14
14
  if (!(this.list instanceof Array)) {
15
15
  console.log(`In StepMultipleDone, warning ${this.args[0]} is not a list!`);
16
16
  return true;