@altostra/core
Version:
Core library for shared types and logic
1 lines • 4.2 kB
JavaScript
;var _BluePrintGlobalVariablesHelper_blueprint,__classPrivateFieldSet=this&&this.__classPrivateFieldSet||function(e,r,a,t,l){if("m"===t)throw new TypeError("Private method is not writable");if("a"===t&&!l)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof r?e!==r||!l:!r.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===t?l.call(e,a):l?l.value=a:r.set(e,a),a},__classPrivateFieldGet=this&&this.__classPrivateFieldGet||function(e,r,a,t){if("a"===a&&!t)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof r?e!==r||!t:!r.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===a?t:"a"===a?t.call(e):t?t.value:r.get(e)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.BluePrintGlobalVariablesHelper=void 0;const AltoError_1=require("../../common/Errors/AltoError"),iterable_1=require("@reactivex/ix-es2015-cjs/iterable"),map_1=require("@reactivex/ix-es2015-cjs/iterable/operators/map"),ParameterPathBuilder_1=require("../Parameters/ParameterPathBuilder"),ParametersHelper_1=require("./ParametersHelper");class BluePrintGlobalVariablesHelper{constructor(e){_BluePrintGlobalVariablesHelper_blueprint.set(this,void 0),__classPrivateFieldSet(this,_BluePrintGlobalVariablesHelper_blueprint,e,"f")}add(e,r,a){var t,l;null!==(t=(l=__classPrivateFieldGet(this,_BluePrintGlobalVariablesHelper_blueprint,"f").blueprint).globalEnvironmentVariables)&&void 0!==t||(l.globalEnvironmentVariables={}),this._globalEnvironments[e]=r.toString(),a&&__classPrivateFieldGet(this,_BluePrintGlobalVariablesHelper_blueprint,"f").parameters.add(a,ParametersHelper_1.ParametersHelper.globalEnvironmentRoot.append(e).path)}remove(e){var r,a,t;null!==(r=(t=__classPrivateFieldGet(this,_BluePrintGlobalVariablesHelper_blueprint,"f").blueprint).globalEnvironmentVariables)&&void 0!==r||(t.globalEnvironmentVariables={}),null===(a=this._globalEnvironments)||void 0===a||delete a[e],__classPrivateFieldGet(this,_BluePrintGlobalVariablesHelper_blueprint,"f").parameters.deleteAllFromPath(ParametersHelper_1.ParametersHelper.globalEnvironmentRoot.append(e))}getParametrizedValueByName(e){var r;const a=null===(r=this._globalEnvironments)||void 0===r?void 0:r[e],t=__classPrivateFieldGet(this,_BluePrintGlobalVariablesHelper_blueprint,"f").parameters.getPathParameters(ParametersHelper_1.ParametersHelper.globalEnvironmentRoot.append(e)),l=Object.keys(t);if(l.length>1)throw AltoError_1.AltoError.create("More then one parameter path exists in global variables section in blueprint");return 0===l.length?a:{$param$:l[0],defaultValue:a}}getParameterizedBlueprintEnvironment(){const e=Object.assign({},__classPrivateFieldGet(this,_BluePrintGlobalVariablesHelper_blueprint,"f").blueprint.globalEnvironmentVariables),r=__classPrivateFieldGet(this,_BluePrintGlobalVariablesHelper_blueprint,"f").parameters.getPathParameters(ParametersHelper_1.ParametersHelper.globalEnvironmentRoot);for(const[a,t]of Object.entries(r)){if(!t)continue;const r=(0,iterable_1.from)(t.paths).pipe((0,map_1.map)(e=>{const[,r]=new ParameterPathBuilder_1.ParameterPathBuilder(e).parts;return r}));for(const t of r)e[t]={$param$:a,defaultValue:e[t]}}return e}updateFromParameterizedBlueprintEnvironment(e){const r=__classPrivateFieldGet(this,_BluePrintGlobalVariablesHelper_blueprint,"f").parameters.setParametersFrom({root:ParametersHelper_1.ParametersHelper.globalEnvironmentRoot,parameterized:e});__classPrivateFieldGet(this,_BluePrintGlobalVariablesHelper_blueprint,"f").blueprint.globalEnvironmentVariables=r}get _globalEnvironments(){var e;return null!==(e=__classPrivateFieldGet(this,_BluePrintGlobalVariablesHelper_blueprint,"f").blueprint.globalEnvironmentVariables)&&void 0!==e?e:{}}*[(_BluePrintGlobalVariablesHelper_blueprint=new WeakMap,Symbol.iterator)](){var e;const r=this._globalEnvironments;if(r)for(const a of Object.keys(r))a&&(yield[a,null!==(e=r[a])&&void 0!==e?e:""])}isGlobalEnvironmentVariable(e){return!!e&&void 0!==this._globalEnvironments[e]}}exports.BluePrintGlobalVariablesHelper=BluePrintGlobalVariablesHelper;