@altostra/core
Version:
Core library for shared types and logic
1 lines • 1.52 kB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DeploymentVersion=exports.Deployment=void 0;const common_1=require("../../../common/Models/common"),ServiceError_1=require("./ServiceError");class Deployment{constructor(t,e,s,r,o="default",i){this.project=t,this.owner=e,this.created=s,this.versions=r,this.name=o,this.namespace=i}get id(){return`${this.owner}#${this.name}#${this.project.id}`}getLatestVersion(){return this.versions.filter(t=>t.isLatestVersion)[0]}addVersion(t){const e=this.getLatestVersion();return e?(e.isLatestVersion=!1,t.version=e.version+1):t.version=0,this.versions.push(t),t}static isValidId(t){return"string"==typeof t&&t.length>0&&t.length<common_1.MAX_ID_LEN&&/^[A-z0-9-_|]+#[A-z0-9-_]+#[A-z0-9-_]+$/g.test(t)}}exports.Deployment=Deployment;class DeploymentVersion{constructor(t,e,s,r,o,i,n,a,h=!1,p){this.deployment=t,this.version=e,this.blueprints=r,this.sourcesRef=o,this.projectRef=i,this.updated=n,this.deployedBy=a,this.isLatestVersion=h,this.extraData=p,this.deploymentStatus=s}canChangeStatus(){return"Created"===this.status||"Deploying"===this.status||"PendingDeployment"===this.status}get status(){return this.deploymentStatus}updateStatus(t){if(!this.canChangeStatus())throw new ServiceError_1.ServiceError("The current status of the deployment version cannot be changed.",600,void 0,{deploymentId:this.deployment.id,version:this.version,currentStatus:this.status,proposedStatus:t});this.deploymentStatus=t}}exports.DeploymentVersion=DeploymentVersion;