UNPKG

@altostra/core

Version:

Core library for shared types and logic

1 lines 5.81 kB
"use strict";var _BlueprintParametersHelper_blueprint,_BlueprintParametersHelper_parameterTypes,__classPrivateFieldSet=this&&this.__classPrivateFieldSet||function(e,r,t,a,i){if("m"===a)throw new TypeError("Private method is not writable");if("a"===a&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof r?e!==r||!i:!r.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===a?i.call(e,t):i?i.value=t:r.set(e,t),t},__classPrivateFieldGet=this&&this.__classPrivateFieldGet||function(e,r,t,a){if("a"===t&&!a)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof r?e!==r||!a:!r.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===t?a:"a"===t?a.call(e):a?a.value:r.get(e)},__rest=this&&this.__rest||function(e,r){var t={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&r.indexOf(a)<0&&(t[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(a=Object.getOwnPropertySymbols(e);i<a.length;i++)r.indexOf(a[i])<0&&Object.prototype.propertyIsEnumerable.call(e,a[i])&&(t[a[i]]=e[a[i]])}return t};Object.defineProperty(exports,"__esModule",{value:!0}),exports.CONN_ROOT_PATH_PARTS_COUNT=exports.RESOURCE_ROOT_PATH_PARTS_COUNT=exports.resolveParameterPath=exports.BlueprintParametersHelper=void 0;const LogicalId_1=require("../../../aws/CloudFormation/LogicalId"),Errors_1=require("../../../common/Errors"),elementat_1=require("@reactivex/ix-es2015-cjs/iterable/elementat"),from_1=require("@reactivex/ix-es2015-cjs/iterable/from"),Blueprint_1=require("../../Blueprint"),Parameters_1=require("../../Parameters"),TypeMapping_1=require("../../Parameters/TypeMapping");Object.defineProperty(exports,"CONN_ROOT_PATH_PARTS_COUNT",{enumerable:!0,get:function(){return TypeMapping_1.CONN_ROOT_PATH_PARTS_COUNT}}),Object.defineProperty(exports,"resolveParameterPath",{enumerable:!0,get:function(){return TypeMapping_1.resolveParameterPath}}),Object.defineProperty(exports,"RESOURCE_ROOT_PATH_PARTS_COUNT",{enumerable:!0,get:function(){return TypeMapping_1.RESOURCE_ROOT_PATH_PARTS_COUNT}});const common_1=require("../../Parameters/TypeMapping/common"),ParametersHelper_1=require("./ParametersHelper");class BlueprintParametersHelper extends ParametersHelper_1.ParametersHelper{constructor(e,r){super(e.blueprint),_BlueprintParametersHelper_blueprint.set(this,void 0),_BlueprintParametersHelper_parameterTypes.set(this,void 0),__classPrivateFieldSet(this,_BlueprintParametersHelper_blueprint,e,"f"),__classPrivateFieldSet(this,_BlueprintParametersHelper_parameterTypes,r?void 0:{resources:TypeMapping_1.parameterizedResourcePropertiesTypes,connections:TypeMapping_1.parameterizedConnectionPropertiesTypes},"f")}add(e,r){const t=(0,Parameters_1.isParameterSpec)(r)?r:{paths:[r]};return t.paths.forEach(r=>{if(!this.hasParamAt(r))throw Errors_1.AltoError.create(`Adding parameter at [${r}] is not supported.`,{data:{paramName:e,spec:t,invalidPath:r}})}),super.add(e,t)}isGlobalEnvironmentVariablesPath(e){return Parameters_1.globalEnvironmentVariablesPathRx.test(e.toString())}getParamParent(e){return e instanceof Parameters_1.ParameterPathBuilder||(e=new Parameters_1.ParameterPathBuilder(e)),(0,TypeMapping_1.resolveParameterPath)(e.parts,__classPrivateFieldGet(this,_BlueprintParametersHelper_blueprint,"f").blueprint)}hasParamAt(e){return!__classPrivateFieldGet(this,_BlueprintParametersHelper_parameterTypes,"f")||this.isGlobalEnvironmentVariablesPath(e)||!!this.getParamTypeAt(e)}getParamTypeAt(e){if(!__classPrivateFieldGet(this,_BlueprintParametersHelper_parameterTypes,"f"))return;if(e=e instanceof Parameters_1.ParameterPathBuilder?e:new Parameters_1.ParameterPathBuilder(e),this.isGlobalEnvironmentVariablesPath(e))return common_1.stringType;const r=e.startsWith("resources"),t=(0,from_1.from)(e.parts);let a=void 0;if(r){if(1===e.length)return;const r=(0,elementat_1.elementAt)(t,1);a=__classPrivateFieldGet(this,_BlueprintParametersHelper_blueprint,"f").resources.get(r)}else{if(TypeMapping_1.CONN_ROOT_PATH_PARTS_COUNT>=e.length)return;const[r,i,s]=t;if(!(0,LogicalId_1.isLogicalId)(i)||!(0,LogicalId_1.isLogicalId)(s))return;a=__classPrivateFieldGet(this,_BlueprintParametersHelper_blueprint,"f").connections.get(new Blueprint_1.ConnectionId(i,s))}return a?(0,TypeMapping_1.resolveParameterType)(e,r?{resource:a.type}:{connection:a.type},__classPrivateFieldGet(this,_BlueprintParametersHelper_parameterTypes,"f")):void 0}setParametersFrom(e){var{defaultParameterValue:r}=e,t=__rest(e,["defaultParameterValue"]);const a=this;return super.setParametersFrom(Object.assign(Object.assign({},t),{defaultParameterValue:null!=r?r:function(e){var r;try{const t=(0,TypeMapping_1.resolveParameterPath)(e.parts,__classPrivateFieldGet(a,_BlueprintParametersHelper_blueprint,"f").blueprint,!1);return null===(r=null==t?void 0:t.parent)||void 0===r?void 0:r[t.key]}catch(e){return}}}))}getParameterUsage(e){var r;let t=void 0;const a=[],i=[];if(this.parameters){const s=null===(r=this.parameters[e])||void 0===r?void 0:r.paths;if(s)for(const e of s){const r=new Parameters_1.ParameterPathBuilder(e),s=(0,from_1.from)(r.parts),[n,l,p]=s;if("resources"===n)t=__classPrivateFieldGet(this,_BlueprintParametersHelper_blueprint,"f").resources.get(l),t&&a.push(t);else if("connections"===n){if(!(0,LogicalId_1.isLogicalId)(l)||!(0,LogicalId_1.isLogicalId)(p))break;t=__classPrivateFieldGet(this,_BlueprintParametersHelper_blueprint,"f").connections.get(new Blueprint_1.ConnectionId(l,p)),t&&i.push(t)}}}return{resources:a,connections:i}}}exports.BlueprintParametersHelper=BlueprintParametersHelper,_BlueprintParametersHelper_blueprint=new WeakMap,_BlueprintParametersHelper_parameterTypes=new WeakMap;