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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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