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

update validator arguments not to use optional object

This commit is contained in:
Hiroyasu Nishiyama 2022-04-12 08:09:46 +09:00
parent ace5f81a17
commit accbf6ecfc
16 changed files with 56 additions and 91 deletions

View File

@ -19,10 +19,10 @@ RED.validators = {
if ((blankAllowed&&(v===''||v===undefined)) || (v!=='' && !isNaN(v))) { if ((blankAllowed&&(v===''||v===undefined)) || (v!=='' && !isNaN(v))) {
return true; return true;
} }
if (mopt && mopt.label) { if (opt && opt.label) {
return opt ? RED._("validator.errors.invalid-num-prop", { return RED._("validator.errors.invalid-num-prop", {
prop: mopt.label prop: opt.label
}) : false; });
} }
return opt ? RED._("validator.errors.invalid-num") : false; return opt ? RED._("validator.errors.invalid-num") : false;
}; };
@ -32,10 +32,10 @@ RED.validators = {
if (re.test(v)) { if (re.test(v)) {
return true; return true;
} }
if (mopt && mopt.label) { if (opt && opt.label) {
return opt ? RED._("validator.errors.invalid-regex-prop", { return RED._("validator.errors.invalid-regex-prop", {
prop: mopt.label prop: opt.label
}) : false; });
} }
return opt ? RED._("validator.errors.invalid-regexp") : false; return opt ? RED._("validator.errors.invalid-regexp") : false;
}; };
@ -48,11 +48,11 @@ RED.validators = {
JSON.parse(v); JSON.parse(v);
return true; return true;
} catch(err) { } catch(err) {
if (mopt && mopt.label) { if (opt && opt.label) {
return opt ? RED._("validator.errors.invalid-json-prop", { return RED._("validator.errors.invalid-json-prop", {
error: err.message, error: err.message,
prop: mopt.label, prop: opt.label,
}) : false; });
} }
return opt ? RED._("validator.errors.invalid-json", { return opt ? RED._("validator.errors.invalid-json", {
error: err.message error: err.message
@ -62,20 +62,20 @@ RED.validators = {
if (RED.utils.validatePropertyExpression(v)) { if (RED.utils.validatePropertyExpression(v)) {
return true; return true;
} }
if (mopt && mopt.label) { if (opt && opt.label) {
return opt ? RED._("validator.errors.invalid-prop-prop", { return RED._("validator.errors.invalid-prop-prop", {
prop: mopt.label prop: opt.label
}) : false; });
} }
return opt ? RED._("validator.errors.invalid-prop") : false; return opt ? RED._("validator.errors.invalid-prop") : false;
} else if (ptype === 'num') { } else if (ptype === 'num') {
if (/^[+-]?[0-9]*\.?[0-9]*([eE][-+]?[0-9]+)?$/.test(v)) { if (/^[+-]?[0-9]*\.?[0-9]*([eE][-+]?[0-9]+)?$/.test(v)) {
return true; return true;
} }
if (mopt && mopt.label) { if (opt && opt.label) {
return opt ? RED._("validator.errors.invalid-num-prop", { return RED._("validator.errors.invalid-num-prop", {
prop: mopt.label prop: opt.label
}) : false; });
} }
return opt ? RED._("validator.errors.invalid-num") : false; return opt ? RED._("validator.errors.invalid-num") : false;
} }

View File

@ -261,9 +261,7 @@
once: {value:false}, once: {value:false},
onceDelay: {value:0.1}, onceDelay: {value:0.1},
topic: {value:""}, topic: {value:""},
payload: {value:"", validate: RED.validators.typedInput("payloadType", false, { payload: {value:"", validate: RED.validators.typedInput("payloadType", false) },
property: "payload"
}) },
payloadType: {value:"date"}, payloadType: {value:"date"},
}, },
icon: "inject.svg", icon: "inject.svg",

View File

@ -260,9 +260,8 @@
name: {value:""}, name: {value:""},
links: { value: [], type:"link in[]"}, links: { value: [], type:"link in[]"},
timeout: { value: "30", timeout: { value: "30",
validate:RED.validators.number(true, { label: RED._("node-red:link.timeout"),
property: RED._("node-red:link.timeout") validate:RED.validators.number(true)
})
} }
}, },
inputs: 1, inputs: 1,

View File

@ -165,9 +165,7 @@
name: {value:""}, name: {value:""},
property: {value:"payload", required:true, property: {value:"payload", required:true,
label:RED._("node-red:common.label.payload"), label:RED._("node-red:common.label.payload"),
validate: RED.validators.typedInput("propertyType", false, { validate: RED.validators.typedInput("propertyType", false)},
property: RED._("node-red:common.label.payload")
})},
propertyType: { value:"msg" }, propertyType: { value:"msg" },
rules: {value:[{t:"eq", v:"", vt:"str"}]}, rules: {value:[{t:"eq", v:"", vt:"str"}]},
checkall: {value:"true", required:true}, checkall: {value:"true", required:true},

View File

@ -43,24 +43,16 @@
defaults: { defaults: {
minin: {value:"", required: true, minin: {value:"", required: true,
label:RED._("node-red:range.label.minin"), label:RED._("node-red:range.label.minin"),
validate:RED.validators.number(false, { validate:RED.validators.number(false)},
property: RED._("node-red:range.label.minin")
})},
maxin: {value:"", required: true, maxin: {value:"", required: true,
label:RED._("node-red:range.label.maxin"), label:RED._("node-red:range.label.maxin"),
validate:RED.validators.number(false, { validate:RED.validators.number(false)},
property: RED._("node-red:range.label.maxin")
})},
minout: {value:"", required:true, minout: {value:"", required:true,
label:RED._("node-red:range.label.minout"), label:RED._("node-red:range.label.minout"),
validate:RED.validators.number(false, { validate:RED.validators.number(false)},
property: RED._("node-red:range.label.minout")
})},
maxout: {value:"", required:true, maxout: {value:"", required:true,
label:RED._("node-red:range.label.maxout"), label:RED._("node-red:range.label.maxout"),
validate:RED.validators.number(false, { validate:RED.validators.number(false)},
property: RED._("node-red:range.label.maxout")
})},
action: {value:"scale"}, action: {value:"scale"},
round: {value:false}, round: {value:false},
property: {value:"payload",required:true, property: {value:"payload",required:true,

View File

@ -57,9 +57,8 @@
defaults: { defaults: {
name: {value:""}, name: {value:""},
field: {value:"payload", field: {value:"payload",
validate:RED.validators.typedInput("fieldType", false, { label:"payload",
property: "payload" validate:RED.validators.typedInput("fieldType", false)},
})},
fieldType: {value:"msg"}, fieldType: {value:"msg"},
format: {value:"handlebars"}, format: {value:"handlebars"},
syntax: {value:"mustache"}, syntax: {value:"mustache"},

View File

@ -141,7 +141,6 @@
rateUnits: {value: "second"}, rateUnits: {value: "second"},
randomFirst: { randomFirst: {
value:"1", required:true, value:"1", required:true,
label:RED._("node-red:delay.label.random-first"),
validate:function(v,opt) { validate:function(v,opt) {
if (RED.validators.number(v) && (v >= 0)) { if (RED.validators.number(v) && (v >= 0)) {
return true; return true;
@ -150,7 +149,6 @@
}}, }},
randomLast: { randomLast: {
value:"5", required:true, value:"5", required:true,
label:RED._("node-red:delay.label.random-last"),
validate:function(v,opt) { validate:function(v,opt) {
if (RED.validators.number(v) && (v >= 0)) { if (RED.validators.number(v) && (v >= 0)) {
return true; return true;

View File

@ -88,21 +88,17 @@
defaults: { defaults: {
name: {value:""}, name: {value:""},
op1: {value:"1", op1: {value:"1",
validate: RED.validators.typedInput("op1type", false, { label: RED._("node-red:trigger.send"),
property: RED._("node-red:trigger.send") validate: RED.validators.typedInput("op1type", false)},
})},
op2: {value:"0", op2: {value:"0",
validate: RED.validators.typedInput("op2type", false, { label: RED._("node-red:trigger.then-send"),
property: RED._("node-red:trigger.then-send") validate: RED.validators.typedInput("op2type", false)},
})},
op1type: {value:"val"}, op1type: {value:"val"},
op2type: {value:"val"}, op2type: {value:"val"},
duration: { duration: {
value:"250", required:true, value:"250", required:true,
label:RED._("node-red:trigger.label.duration"), label:RED._("node-red:trigger.label.duration"),
validate:RED.validators.number(false, { validate:RED.validators.number(false)},
property: RED._("node-red:trigger.label.duration")
})},
extend: {value:"false"}, extend: {value:"false"},
overrideDelay: {value:"false"}, overrideDelay: {value:"false"},
units: {value:"ms"}, units: {value:"ms"},

View File

@ -50,9 +50,8 @@
name: {value:""}, name: {value:""},
func: {value:"rbe"}, func: {value:"rbe"},
gap: {value:"", gap: {value:"",
validate:RED.validators.regex(/^(\d*[.]*\d*|)(%|)$/, { label: RED._("node-red:rbe.label.gap"),
property: RED._("node-red:rbe.label.gap") validate:RED.validators.regex(/^(\d*[.]*\d*|)(%|)$/)},
})},
start: {value:""}, start: {value:""},
inout: {value:"out"}, inout: {value:"out"},
septopics: {value:true}, septopics: {value:true},

View File

@ -450,9 +450,8 @@
broker: {value:"",required:true}, broker: {value:"",required:true},
port: { port: {
value:1883,required:false, value:1883,required:false,
validate:RED.validators.number(true, { label: RED._("node-red:mqtt.label.port"),
property: RED._("node-red:mqtt.label.port") validate:RED.validators.number(true)},
})},
tls: {type:"tls-config",required: false, tls: {type:"tls-config",required: false,
label:RED._("node-red:mqtt.label.use-tls") }, label:RED._("node-red:mqtt.label.use-tls") },
clientid: {value:"", validate: function(v, opt) { clientid: {value:"", validate: function(v, opt) {
@ -475,9 +474,8 @@
protocolVersion: { value: 4}, protocolVersion: { value: 4},
keepalive: { keepalive: {
value:60, value:60,
validate:RED.validators.number(false, { label: RED._("node-red:mqtt.label.keepalive"),
property: RED._("node-red:mqtt.label.keepalive") validate:RED.validators.number(false)},
})},
cleansession: {value: true}, cleansession: {value: true},
birthTopic: {value:""}, birthTopic: {value:""},
birthQos: {value:"0"}, birthQos: {value:"0"},

View File

@ -149,9 +149,8 @@
name: {value:""}, name: {value:""},
statusCode: { statusCode: {
value:"", value:"",
validate: RED.validators.number(true,{ label: RED._("node-red:httpin.label.status"),
property: RED._("node-red:httpin.label.status") validate: RED.validators.number(true)},
})},
headers: {value:{}} headers: {value:{}}
}, },
inputs:1, inputs:1,

View File

@ -145,9 +145,8 @@
category: 'config', category: 'config',
defaults: { defaults: {
path: {value:"",required:true, path: {value:"",required:true,
validate:RED.validators.regex(/^((?!\/debug\/ws).)*$/, { label:RED._("node-red:websocket.label.path"),
property:RED._("node-red:websocket.label.path") validate:RED.validators.regex(/^((?!\/debug\/ws).)*$/)},
})},
wholemsg: {value:"false"} wholemsg: {value:"false"}
}, },
inputs:0, inputs:0,
@ -185,16 +184,14 @@
defaults: { defaults: {
path: { path: {
value:"",required:true, value:"",required:true,
validate:RED.validators.regex(/^((?!\/debug\/ws).)*$/, { label:RED._("node-red:websocket.label.path"),
property:RED._("node-red:websocket.label.path") validate:RED.validators.regex(/^((?!\/debug\/ws).)*$/)},
})},
tls: {type:"tls-config",required: false}, tls: {type:"tls-config",required: false},
wholemsg: {value:"false"}, wholemsg: {value:"false"},
hb: { hb: {
value: "", value: "",
validate: RED.validators.number(/*blank allowed*/true, { label:RED._("node-red:websocket.sendheartbeat"),
property:RED._("node-red:websocket.sendheartbeat") validate: RED.validators.number(/*blank allowed*/true) },
}) },
subprotocol: {value:"",required: false} subprotocol: {value:"",required: false}
}, },
inputs:0, inputs:0,

View File

@ -82,9 +82,7 @@
port: { port: {
value:"", required:true, value:"", required:true,
label:RED._("node-red:tcpin.label.port"), label:RED._("node-red:tcpin.label.port"),
validate:RED.validators.number(false, { validate:RED.validators.number(false)},
property: RED._("node-red:tcpin.label.port")
})},
datamode:{value:"stream"}, datamode:{value:"stream"},
datatype:{value:"buffer"}, datatype:{value:"buffer"},
newline:{value:""}, newline:{value:""},
@ -334,9 +332,8 @@
server: {value:""}, server: {value:""},
port: { port: {
value:"", value:"",
validate:RED.validators.regex(/^(\d*|)$/, { label: RED._("node-red:tcpin.label.port"),
property: RED._("node-red:tcpin.label.port") validate:RED.validators.regex(/^(\d*|)$/)
})
}, },
out: {value:"time", required:true}, out: {value:"time", required:true},
ret: {value:"buffer"}, ret: {value:"buffer"},

View File

@ -65,9 +65,7 @@
port: { port: {
value:"", required:true, value:"", required:true,
label:RED._("node-red:udp.label.port"), label:RED._("node-red:udp.label.port"),
validate:RED.validators.number(false, { validate:RED.validators.number(false)
property: RED._("node-red:udp.label.port")
})
}, },
ipv: {value:"udp4"}, ipv: {value:"udp4"},
multicast: {value:"false"}, multicast: {value:"false"},

View File

@ -78,9 +78,7 @@
sep: { sep: {
value:',', required:true, value:',', required:true,
label:RED._("node-red:csv.label.separator"), label:RED._("node-red:csv.label.separator"),
validate:RED.validators.regex(/^.{1,2}$/, { validate:RED.validators.regex(/^.{1,2}$/)},
property: RED._("node-red:csv.label.separator")
})},
//quo: {value:'"',required:true}, //quo: {value:'"',required:true},
hdrin: {value:""}, hdrin: {value:""},
hdrout: {value:"none"}, hdrout: {value:"none"},

View File

@ -204,9 +204,8 @@
build: { value:"object"}, build: { value:"object"},
property: { property: {
value:"payload", value:"payload",
validate:RED.validators.typedInput("propertyType", false, { label: RED._("node-red:join.message-prop"),
property: RED._("node-red:join.message-prop") validate:RED.validators.typedInput("propertyType", false)
})
}, },
propertyType: { value:"msg"}, propertyType: { value:"msg"},
key: {value:"topic"}, key: {value:"topic"},