@ejfdelgado/ejflab-back 1.16.8 → 1.17.1

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@ejfdelgado/ejflab-back",
3
- "version": "1.16.8",
3
+ "version": "1.17.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ejfdelgado/ejflab-back.git"
@@ -18,7 +18,7 @@
18
18
  "license": "ISC",
19
19
  "private": false,
20
20
  "dependencies": {
21
- "@ejfdelgado/ejflab-common": "1.10.6",
21
+ "@ejfdelgado/ejflab-common": "1.11.1",
22
22
  "@google-cloud/compute": "^4.7.0",
23
23
  "@google-cloud/firestore": "^7.9.0",
24
24
  "@google-cloud/storage": "^7.11.3",
@@ -2,6 +2,7 @@ import { FlowChartExec } from "@ejfdelgado/ejflab-common/src/flowchart/FlowChart
2
2
  import { GenericProcessor } from "./GenericProcessor.mjs";
3
3
  import fs from "fs";
4
4
  import { SimpleObj } from "@ejfdelgado/ejflab-common/src/SimpleObj.js";
5
+ import { MyTuples } from "@ejfdelgado/ejflab-common/src/MyTuples.js";
5
6
  import { Buffer } from 'buffer';
6
7
 
7
8
  const WORKSPACE = process.env.WORKSPACE;
@@ -24,6 +25,24 @@ export class LoadFlowChartProcessor extends GenericProcessor {
24
25
  }
25
26
  }
26
27
 
28
+ overwriteProcessorEnvVariables(dataObject) {
29
+ //console.log(JSON.stringify(dataObject, null, 4));
30
+ const tuples = MyTuples.getTuples(dataObject);
31
+ //console.log(JSON.stringify(tuples, null, 4));
32
+ const keys = Object.keys(tuples);
33
+ for (let i = 0; i < keys.length; i++) {
34
+ const key = keys[i];
35
+ const currentValue = tuples[key];
36
+ if (typeof currentValue == "string") {
37
+ const envKey = key.replace(".", "_").toUpperCase();
38
+ if (envKey in process.env) {
39
+ SimpleObj.recreate(dataObject, key, process.env[envKey]);
40
+ }
41
+ console.log(`${envKey}=${SimpleObj.getValue(dataObject, key)}`);
42
+ }
43
+ }
44
+ }
45
+
27
46
  async execute(args) {
28
47
  let {
29
48
  names,
@@ -59,7 +78,12 @@ export class LoadFlowChartProcessor extends GenericProcessor {
59
78
  const keysData = Object.keys(dataPath);
60
79
  for (let i = 0; i < keysData.length; i++) {
61
80
  const keyData = keysData[i];
62
- const dataObject = JSON.parse(fs.readFileSync(dataPath[keyData], 'utf8'));
81
+ const fileName = dataPath[keyData];
82
+ const dataObject = JSON.parse(fs.readFileSync(fileName, 'utf8'));
83
+ // Here we can intercept the data model and overwrite given env variables
84
+ if (fileName.endsWith("processors.json")) {
85
+ this.overwriteProcessorEnvVariables(dataObject);
86
+ }
63
87
  if (keyData.length == 0) {
64
88
  Object.assign(data, dataObject);
65
89
  } else {
@@ -79,13 +79,15 @@ export class ProcessResponseProcessor extends GenericProcessor {
79
79
  if (!!outputConnectionsConf) {
80
80
  outputConnectionsConf.forEach((outputConnectionsConfOne) => {
81
81
  const { key, val } = outputConnectionsConfOne;
82
- const output = val;
83
- const dataLocal = data[key];
82
+ const outputPath = val;
83
+ let dataLocal = data[key];
84
+ //console.log(`Assigning ${outputPath}`);
85
+ //console.log(JSON.stringify(dataLocal, null, 4));
84
86
  if (dataLocal != undefined) {
85
87
  // Sends dataResponse to val
86
- const outputParts = /^(b\.([^.]+)\.([^.]+)|d\.(.+))$/i.exec(output);
88
+ const outputParts = /^(b\.([^.]+)\.([^.]+)|d\.(.+))$/i.exec(outputPath);
87
89
  if (!outputParts) {
88
- console.log(`${output} does not match ^(b\.([^.]+)\.([^.]+)|d\.(.+))$`);
90
+ console.log(`${outputPath} does not match ^(b\.([^.]+)\.([^.]+)|d\.(.+))$`);
89
91
  return;
90
92
  }
91
93
  if (!outputParts[4]) {
@@ -98,7 +100,7 @@ export class ProcessResponseProcessor extends GenericProcessor {
98
100
  }
99
101
  instance.saveBufferData(processorIdLocal, sourcePathIndexed, dataLocal);
100
102
  // Publish to others the not indexed?
101
- const destiny = `${room}.${output}`;
103
+ const destiny = `${room}.${outputPath}`;
102
104
  //console.log(`Publishing to ${destiny} ok?`);
103
105
  this.io.to(destiny).emit("processResponse", {
104
106
  processorId,
@@ -107,6 +109,7 @@ export class ProcessResponseProcessor extends GenericProcessor {
107
109
  });
108
110
  } else {
109
111
  // Json case
112
+ dataLocal = JSON.parse(JSON.stringify(dataLocal));
110
113
  // Affect the model in the given point
111
114
  const path = outputParts[4];
112
115
  let pathIndexed = path;
@@ -125,7 +128,7 @@ export class ProcessResponseProcessor extends GenericProcessor {
125
128
  });
126
129
  }
127
130
  } else {
128
- console.log(`Skip output connection ${val} with no value`);
131
+ console.log(`Skip output connection ${outputPath} with no value`);
129
132
  }
130
133
  });
131
134
  }