@altostra/core
Version:
Core library for shared types and logic
1 lines • 2.67 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0}),exports.integrityCheck=void 0;const Object_1=require("../../common/Utils/Object"),Iterable_1=require("../Helpers/Iterable"),Parameters_1=require("../Parameters"),TypeMapping_1=require("../Parameters/TypeMapping"),Resources_1=require("../Resources");function integrityCheck(e){return[...function*(){for(const[t,r]of Object.entries(e.resources)){if(!r)continue;const e=["resources",t];(0,Resources_1.isResourceId)(t)||(yield{path:e,reason:`Invalid resource id [${t}]`}),t!==r.id&&(yield{path:e,reason:`The resource id must be identical to the path id.\nThe resource id [${r.id}] is different than the path id [${t}]`,item:r})}}(),...function*(){for(const[t,r]of Object.entries(e.connections))if(r)for(const[o,n]of Object.entries(r)){if(!n)continue;const r=["connections",t,o];e.resources[t]||(yield{path:["connections",t],reason:`The connection's source resource could not be found.\nThe [${t}] resource does not exist`,item:n}),e.resources[o]||(yield{path:r,reason:`The connection's target resource could not be found.\nThe [${o}] resource does not exist`,item:n}),t!==n.from&&(yield{path:r,reason:`The connection \`from\` property must be identical to the path source id (the first segment after 'connections').\nThe connection \`from\` property [${n.from}] is different that the path source id [${t}].`,item:n}),o!==n.to&&(yield{path:r,reason:`The connection \`to\` property must be identical to the path target id (the second segment after 'connections').\nThe connection \`to\` property [${n.to}] is different that the path target id [${o}].`,item:n})}}(),...function*(){var t,r;if(!e.parameters)return;for(const[o,n]of Object.entries(e.parameters))if(n)for(const[i,s]of(0,Iterable_1.withIndex)(n.paths)){const n=new Parameters_1.ParameterPathBuilder(i),[c,a,p]=n.parts;let u=!0;if("resources"===c||"connections"===c){let h=void 0;if("resources"===c){const t=e.resources[a];(null==t?void 0:t.type)&&(h={resource:t.type})}else{const r=null===(t=e.connections[a])||void 0===t?void 0:t[p];(null==r?void 0:r.type)&&(h={connection:r.type})}if(h){const e=(0,TypeMapping_1.resolveParameterType)(n,h);e?u=null!==(r=e.required)&&void 0!==r&&r:(u=!1,yield{path:["parameters",o,"paths",String(s)],reason:"The parameter's path is not supported",item:i})}}u&&!pathExists([...n.parts],e)&&(yield{path:["parameters",o,"paths",String(s)],reason:"The parameter's path does not exist in the blueprint",item:i})}}()]}function pathExists(e,t){if(0===e.length)return!0;const[r,...o]=e;if(!(r in t))return!1;const n=t[r];return(0,Object_1.isObject)(n)?pathExists(o,n):0===o.length}exports.integrityCheck=integrityCheck;