1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

simplified meta-data

This commit is contained in:
Hiroyasu Nishiyama 2019-01-30 20:57:51 +09:00
parent 0b05b883cb
commit ce507b3b52
3 changed files with 37 additions and 167 deletions

View File

@ -224,20 +224,6 @@ class Subflow extends Flow {
return null; return null;
} }
function lookupFlow(flow, name) { function lookupFlow(flow, name) {
var prefix = name.substring(0, name.length -5); // len("_{type,info}")==5
if (name.endsWith("_type")) {
var val = lookupFlow0(flow, prefix);
if (val) {
return val.type;
}
}
else if (name.endsWith("_info")) {
var val = lookupFlow0(flow, prefix);
if (val) {
return val.info;
}
}
else {
var val = lookupFlow0(flow, name); var val = lookupFlow0(flow, name);
if (val) { if (val) {
if ((typeof val === "str) && (val.type" !== "str")) { if ((typeof val === "str) && (val.type" !== "str")) {
@ -251,7 +237,6 @@ class Subflow extends Flow {
} }
return val.value; return val.value;
} }
}
return null; return null;
} }
@ -273,21 +258,6 @@ class Subflow extends Flow {
return undefined; return undefined;
} }
/**
* Set environment variable of subflow
* @param {String} name name of env var
* @param {Object} val value of env var
*/
setSetting(name, val) {
var node = this.node;
if (node) {
var env = node.env;
if (env) {
env[name] = { name: name, type: "str", value: val, info: null };
}
}
}
/** /**
* Handle a status event from a node within this flow. * Handle a status event from a node within this flow.
* @param {Node} node The original node that triggered the event * @param {Node} node The original node that triggered the event

View File

@ -135,15 +135,7 @@ describe('subflow', function() {
// Subflow // Subflow
{id:"s1", type:"subflow", name:"Subflow", info:"", {id:"s1", type:"subflow", name:"Subflow", info:"",
env: [ env: [
{name: "K", type: "T", value: "V", {name: "K", type: "str", value: "V"}
info: {
name: "K",
label: "",
value: "V",
type: "T",
target_type: "env var",
"target": "K"
}}
], ],
in:[{ in:[{
x:10, y:10, x:10, y:10,
@ -155,7 +147,7 @@ describe('subflow', function() {
}] }]
}, },
{id:"s1-n1", x:10, y:10, z:"s1", type:"function", {id:"s1-n1", x:10, y:10, z:"s1", type:"function",
func:"msg.V = env.get('K'); msg.T = env.get('K_type'); msg.I = env.get('K_info'); return msg;", func:"msg.V = env.get('K'); return msg;",
wires:[]} wires:[]}
]; ];
helper.load(functionNode, flow, function() { helper.load(functionNode, flow, function() {
@ -164,8 +156,6 @@ describe('subflow', function() {
n2.on("input", function(msg) { n2.on("input", function(msg) {
try { try {
msg.should.have.property("V", "V"); msg.should.have.property("V", "V");
msg.should.have.property("T", "T");
msg.should.have.property("I");
done(); done();
} }
catch (e) { catch (e) {
@ -182,15 +172,7 @@ describe('subflow', function() {
{id:"t0", type:"tab", label:"", disabled:false, info:""}, {id:"t0", type:"tab", label:"", disabled:false, info:""},
{id:"n1", x:10, y:10, z:"t0", type:"subflow:s1", {id:"n1", x:10, y:10, z:"t0", type:"subflow:s1",
env: [ env: [
{name: "K", type: "T", value: "V", {name: "K", type: "str", value: "V"}
info: {
name: "K",
label: "",
value: "V",
type: "T",
target_type: "env var",
"target": "K"
}}
], ],
wires:[["n2"]]}, wires:[["n2"]]},
{id:"n2", x:10, y:10, z:"t0", type:"helper", wires:[]}, {id:"n2", x:10, y:10, z:"t0", type:"helper", wires:[]},
@ -206,7 +188,7 @@ describe('subflow', function() {
}] }]
}, },
{id:"s1-n1", x:10, y:10, z:"s1", type:"function", {id:"s1-n1", x:10, y:10, z:"s1", type:"function",
func:"msg.V = env.get('K'); msg.T = env.get('K_type'); msg.I = env.get('K_info'); return msg;", func:"msg.V = env.get('K'); return msg;",
wires:[]} wires:[]}
]; ];
helper.load(functionNode, flow, function() { helper.load(functionNode, flow, function() {
@ -215,8 +197,6 @@ describe('subflow', function() {
n2.on("input", function(msg) { n2.on("input", function(msg) {
try { try {
msg.should.have.property("V", "V"); msg.should.have.property("V", "V");
msg.should.have.property("T", "T");
msg.should.have.property("I");
done(); done();
} }
catch (e) { catch (e) {
@ -233,33 +213,9 @@ describe('subflow', function() {
{id:"t0", type:"tab", label:"", disabled:false, info:""}, {id:"t0", type:"tab", label:"", disabled:false, info:""},
{id:"n1", x:10, y:10, z:"t0", type:"subflow:s1", {id:"n1", x:10, y:10, z:"t0", type:"subflow:s1",
env: [ env: [
{name: "K", type: "T", value: "V0", {name: "K", type: "str", value: "V0"},
info: { {name: "X", type: "str", value: "VX"},
name: "K", {name: "K", type: "str", value: "V1"}
label: "",
value: "V1",
type: "T",
target_type: "env var",
"target": "K"
}},
{name: "X", type: "T", value: "V",
info: {
name: "X",
label: "",
value: "V",
type: "T",
target_type: "env var",
"target": "X"
}},
{name: "K", type: "T", value: "V1",
info: {
name: "K",
label: "",
value: "V1",
type: "T",
target_type: "env var",
"target": "K"
}}
], ],
wires:[["n2"]]}, wires:[["n2"]]},
{id:"n2", x:10, y:10, z:"t0", type:"helper", wires:[]}, {id:"n2", x:10, y:10, z:"t0", type:"helper", wires:[]},
@ -300,42 +256,13 @@ describe('subflow', function() {
{id:"t0", type:"tab", label:"", disabled:false, info:""}, {id:"t0", type:"tab", label:"", disabled:false, info:""},
{id:"n1", x:10, y:10, z:"t0", type:"subflow:s1", {id:"n1", x:10, y:10, z:"t0", type:"subflow:s1",
env: [ env: [
{name: "KS", type: "str", value: "STR", {name: "KS", type: "str", value: "STR"},
info: { {name: "KN", type: "num", value: "100"},
name: "KS", {name: "KB", type: "bool", value: "true"},
label: "", {name: "KJ", type: "json", value: "[1,2,3]"},
value: "STR", {name: "Kb", type: "bin", value: "[65,65]"},
type: "str", {name: "KR", type: "re", value: "[A-Z]"},
target_type: "env var", {name: "KD", type: "date", value: ""}
target: "KS"
}},
{name: "KN", type: "num", value: "100",
info: {
name: "KN",
label: "",
value: "100",
type: "num",
target_type: "env var",
target: "KN"
}},
{name: "KB", type: "bool", value: "true",
info: {
name: "KB",
label: "",
value: "true",
type: "bool",
target_type: "env var",
target: "KB"
}},
{name: "KJ", type: "json", value: "[1,2,3]",
info: {
name: "KJ",
label: "",
value: "[1,2,3]",
type: "json",
target_type: "env var",
target: "KJ"
}},
], ],
wires:[["n2"]]}, wires:[["n2"]]},
{id:"n2", x:10, y:10, z:"t0", type:"helper", wires:[]}, {id:"n2", x:10, y:10, z:"t0", type:"helper", wires:[]},
@ -351,7 +278,7 @@ describe('subflow', function() {
}] }]
}, },
{id:"s1-n1", x:10, y:10, z:"s1", type:"function", {id:"s1-n1", x:10, y:10, z:"s1", type:"function",
func:"msg.VS = env.get('KS'); msg.VN = env.get('KN'); msg.VB = env.get('KB'); msg.VJ = env.get('KJ'); return msg;", func:"msg.VS = env.get('KS'); msg.VN = env.get('KN'); msg.VB = env.get('KB'); msg.VJ = env.get('KJ'); msg.Vb = env.get('Kb'); msg.VR = env.get('KR'); msg.VD = env.get('KD'); return msg;",
wires:[]} wires:[]}
]; ];
helper.load(functionNode, flow, function() { helper.load(functionNode, flow, function() {
@ -363,6 +290,12 @@ describe('subflow', function() {
msg.should.have.property("VN", 100); msg.should.have.property("VN", 100);
msg.should.have.property("VB", true); msg.should.have.property("VB", true);
msg.should.have.property("VJ", [1,2,3]); msg.should.have.property("VJ", [1,2,3]);
msg.should.have.property("Vb");
should.ok(msg.Vb instanceof Buffer);
msg.should.have.property("VR");
should.ok(msg.VR instanceof RegExp);
msg.should.have.property("VD");
should.ok((typeof msg.VD) === "number");
done(); done();
} }
catch (e) { catch (e) {
@ -379,30 +312,14 @@ describe('subflow', function() {
{id:"t0", type:"tab", label:"", disabled:false, info:""}, {id:"t0", type:"tab", label:"", disabled:false, info:""},
{id:"n1", x:10, y:10, z:"t0", type:"subflow:s1", {id:"n1", x:10, y:10, z:"t0", type:"subflow:s1",
env: [ env: [
{name: "K", type: "T", value: "V", {name: "K", type: "str", value: "V"}
info: {
name: "K",
label: "",
value: "V",
type: "T",
target_type: "env var",
"target": "K"
}}
], ],
wires:[["n2"]]}, wires:[["n2"]]},
{id:"n2", x:10, y:10, z:"t0", type:"helper", wires:[]}, {id:"n2", x:10, y:10, z:"t0", type:"helper", wires:[]},
// Subflow // Subflow
{id:"s1", type:"subflow", name:"Subflow", info:"", {id:"s1", type:"subflow", name:"Subflow", info:"",
env: [ env: [
{name: "K", type: "TT", value: "TV", {name: "K", type: "str", value: "TV"}
info: {
name: "K",
label: "",
value: "TV",
type: "TT",
target_type: "env var",
"target": "K"
}}
], ],
in:[{ in:[{
x:10, y:10, x:10, y:10,
@ -414,7 +331,7 @@ describe('subflow', function() {
}] }]
}, },
{id:"s1-n1", x:10, y:10, z:"s1", type:"function", {id:"s1-n1", x:10, y:10, z:"s1", type:"function",
func:"msg.V = env.get('K'); msg.T = env.get('K_type'); msg.I = env.get('K_info'); return msg;", func:"msg.V = env.get('K'); return msg;",
wires:[]} wires:[]}
]; ];
helper.load(functionNode, flow, function() { helper.load(functionNode, flow, function() {
@ -423,8 +340,6 @@ describe('subflow', function() {
n2.on("input", function(msg) { n2.on("input", function(msg) {
try { try {
msg.should.have.property("V", "V"); msg.should.have.property("V", "V");
msg.should.have.property("T", "T");
msg.should.have.property("I");
done(); done();
} }
catch (e) { catch (e) {
@ -444,15 +359,7 @@ describe('subflow', function() {
// Subflow1 // Subflow1
{id:"s1", type:"subflow", name:"Subflow1", info:"", {id:"s1", type:"subflow", name:"Subflow1", info:"",
env: [ env: [
{name: "K", type: "T", value: "V", {name: "K", type: "str", value: "V"},
info: {
name: "K",
label: "",
value: "V",
type: "T",
target_type: "env var",
"target": "K"
}}
], ],
in:[{ in:[{
x:10, y:10, x:10, y:10,
@ -498,15 +405,7 @@ describe('subflow', function() {
{id:"t0", type:"tab", label:"", disabled:false, info:""}, {id:"t0", type:"tab", label:"", disabled:false, info:""},
{id:"n1", x:10, y:10, z:"t0", type:"subflow:s1", {id:"n1", x:10, y:10, z:"t0", type:"subflow:s1",
env: [ env: [
{name: "K", type: "T", value: "V", {name: "K", type: "str", value: "V"}
info: {
name: "K",
label: "",
value: "V",
type: "T",
target_type: "env var",
"target": "K"
}}
], ],
wires:[["n2"]]}, wires:[["n2"]]},
{id:"n2", x:10, y:10, z:"t0", type:"helper", wires:[]}, {id:"n2", x:10, y:10, z:"t0", type:"helper", wires:[]},

View File

@ -574,6 +574,7 @@ describe('Subflow', function() {
sfi.env = [ sfi.env = [
{ {
name: key, name: key,
type: "str",
value: val value: val
} }
]; ];