This commit is contained in:
ari committed 2022-07-15 18:35:25 -04:00
1 parent a35e8e127f
commit 2ea96973ad
20 files changed
+372 -150

No files matched your search

+23 -2
View File
@@ -196,6 +196,18 @@ export const validateNode = (
node: AutomationNode,
allowedNodeTypes: AutomationNodeTypes[] = []
): MiniFailure[] | null => {
if (typeof node !== "object") {
return [
{
message: [
`Expected an object but got type of "${typeof node}" = ${JSON.stringify(
node
)}`,
],
path: "$",
},
];
}
let nodeType = getNodeType(node);
let errors: MiniFailure[] = [];
if (allowedNodeTypes.length > 0 && !allowedNodeTypes.includes(nodeType)) {
@@ -203,7 +215,7 @@ export const validateNode = (
message: [
`Got node of type "${nodeType}" but expected one of {${allowedNodeTypes}}`,
],
path: "",
path: "$",
});
nodeType = allowedNodeTypes[0];
}
@@ -214,7 +226,16 @@ export const validateNode = (
errors.push({ message: [`Failed to identifiy subtype`], path: "" });
}
if (nodeSubType) {
const failures = getFailures(node, AllValidators[nodeType][nodeSubType]);
const validator = AllValidators[nodeType][nodeSubType];
if (!validator) {
return errors.concat([
{
message: [`"${nodeSubType}" is not a known type for ${nodeType}`],
path: "$",
},
]);
}
const failures = getFailures(node, validator);
if (failures) {
errors = errors.concat(failures);
}