forked from KathiraveluLab/DHGWorkflow
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathdefaultValidators.js
More file actions
75 lines (70 loc) · 2.39 KB
/
defaultValidators.js
File metadata and controls
75 lines (70 loc) · 2.39 KB
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
68
69
70
71
72
73
74
75
const nodeValidator = `(node, nodes, edges) => {
var regex = /^[A-za-z0-9]+[:[A-Za-z0-9.]+]|[^$]$/;
let message = { ok: true, err: null };
if (!regex.test(node.label)) {
message = {
ok: false,
err: 'Node with incorrect label.',
}
return message;
}
nodes.forEach((n) => {
if (n.id !== node.id && n.label.split(':')[0] === node.label.split(':')[0]) {
message = {
ok: false,
err: 'Node with same label exists.',
};
}
});
return message;
}`;
const edgeValidator = `(edge, nodes, edges) => {
let message = { ok: true, err: null };
let numEdge = "";
for (let char of edge.label) {
if (!isNaN(parseInt(char))) {
numEdge += char;
} else if (numEdge !== "") {
break;
}
}
edges.forEach((e) => {
if (e.label === edge.label && e.sourceLabel !== edge.sourceLabel) {
message = {
ok: false,
err: 'Edge with same label exists.',
};
}
let numE = "";
for (let char of e.label) {
if (!isNaN(parseInt(char))) {
numE += char;
} else if (numE !== "") {
break;
}
}
if (numE === numEdge && numE != "0" && numE !== "") {
message = {
ok: false,
err: '2 edges cannot have same prefixes if they are number',
};
return message;
}
});
return message;
}`;
/* eslint-disable max-len */
const nodeValidatorFormat = `Takes **\`node\`** details under validation, existing **\`nodes\`**, existing **\`edges\`** and **\`type\`**
**Node:** { label: String, style: Object, id: String | undefined },
**Nodes:** [{ label: String, style: Object, id: String }],
**Edges:** [{ label: String, sourceLabel: String, targetLabel: String, style: Object, id: String }],
**Type:** \`New\` | \`Update\``;
const edgeValidatorFormat = `Takes **\`edge\`** details under validation, existing **\`nodes\`** and existing **\`edges\`** and **\`type\`**
**Edge:** { label: String, sourceLabel: String, targetLabel: String, style: Object, id: String | undefined },
**Nodes:** [{ label: String, style: Object, id: String }],
**Edges:** [{ label: String, sourceLabel: String, targetLabel: String, style: Object, id: String }],
**Type:** \`New\` | \`Update\``;
/* eslint-enable max-len */
export {
nodeValidator, edgeValidator, nodeValidatorFormat, edgeValidatorFormat,
};