-
Notifications
You must be signed in to change notification settings - Fork 1
/
compiler.js
67 lines (50 loc) · 1.37 KB
/
compiler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
Regina's request compiler : compile the requests before execution
*/
var Role = require('./Role')
var utils = require('./utils')
exports.check = (method,params) => {
utils.hey(method,params)
let status = {
valid : true,
error : null
}
for (const param of params) {
let isParamValid = false
let val = param.val
let typeArray = param.role.type
let roleStr = param.role.toString
//console.log("compiler»»»",val,typeArray,roleStr); //debug
for (const type of typeArray){
if(type.valid(val)){
console.log(type.toString,val,'VALID')//debug
isParamValid = true
break;
}else
console.log(type.toString,val,'NOT VALID')//debug
}
if(!isParamValid){
status.valid = false
status.error = {
"type" : "compilation error",
"message" : "Invalid request",
"cause" : compileTypeErrCause(roleStr,typeArray),
"onMethod" : method
}
break;
}
}
console.log('request_status',status)//debug
return status
}
exports.isValidACK = (ack) => { return Role.ack.type[0].valid(ack) }
compileTypeErrCause = (roleStr,typeArray) => {
let str = "Parameter '"+roleStr+"' must be of type : ", i = 1;
for (const type of typeArray){
str+="'"+type.toString+"' "
if(typeArray.length < i)
str+="OR "
i++
}
return str
}