@lcap/asl
Version:
NetEase Application Specific Language
339 lines • 11.4 kB
JavaScript
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProcessComponent = void 0;
const decorators_1 = require("../decorators");
const __1 = require("..");
const process_1 = __importDefault(require("../../service/process"));
/**
* 流程组件类
*/
class ProcessComponent extends __1.Vertex {
/**
* @param source 需要合并的部分参数
*/
constructor(source) {
super();
/**
* 概念类型
*/
this.level = __1.LEVEL_ENUM.processComponent;
/**
* 流程组件 Id
*/
this.id = undefined;
/**
* 流程组件名称
*/
this.name = undefined;
/**
* 流程组件标题
*/
this.title = undefined;
/**
* 流程组件描述
*/
this.description = undefined;
/**
* 流程组件类型
*/
this.type = undefined;
/**
* 流程组件输出参数
*/
this.returns = [];
/**
* 流程组件局部变量
*/
this.variables = [];
/**
* 流程组件逻辑 ID
*/
this.logicId = undefined;
/**
* 流程组件逻辑
*/
this.logic = undefined;
/**
* 流程组件属性
*/
this.destination = undefined;
/**
* 完成任务接口
*/
this.completeTaskInterface = undefined;
/**
* 所属流程 Id
*/
this.parentId = undefined;
/**
* 树组件的隐藏属性
*/
this.hidden = false;
/**
* 类型检查详情
*/
this.typeCheckResult = {};
/**
* 类型检查状态
*/
this.typeCheckStatus = 'success';
/**
* 所属流程
*/
this.process = undefined;
/**
* 树组件的子节点字段
*/
this.moreChildrenFields = ['returns', 'variables', 'properties', 'interfaces'];
/**
* 已存在名称集合
*/
this.existingNames = [];
/**
* 接口列表,单纯用于 tree 展示
*/
this.interfaces = [];
this.assign(source);
}
/**
* 添加流程组件
*/
create() {
this.process.childShapes.push(this);
return this;
}
/**
* 删除流程组件
*/
delete() {
const index = this.process.childShapes.indexOf(this);
~index && this.process.childShapes.splice(index, 1);
this.destroy();
}
/**
* 修改流程组件属性
*/
async updateAttr(updateInterface, actionOptions) {
__1.config.defaultApp?.emit('saving');
const body = this.toPlainJSON();
__1.utils.logger.debug('修改流程组件', body);
const { completeTaskInterface } = await process_1.default.updateComponent({
headers: {
appId: __1.config.defaultApp?.id,
operationAction: actionOptions?.actionName || 'ProcessComponent.updateAttr',
operationDesc: actionOptions?.actionDesc || `修改流程组件属性"${this.name}${this.title ? `(${this.title})` : ''}"`,
},
body,
});
// 流程接口会自动根据流程组件名称变化,更新流程接口的名称
if (updateInterface && completeTaskInterface) {
const { name, path, method } = completeTaskInterface;
this.completeTaskInterface.assign({ name, path, method });
this.completeTaskInterface.logic.assign({ name });
this.process.service.emit('interfacesChange');
}
await __1.config.defaultApp?.history.load();
__1.config.defaultApp?.emit('saved');
return this;
}
/**
* 设置流程组件名称
* @param name 名称
*/
async setName(name) {
const oldName = this.name;
this.assign({ name });
await this.updateAttr(true, {
actionDesc: `设置流程组件"${oldName}"的名称为"${name}"`,
});
// 流程逻辑会自动根据流程组件名称变化,更新逻辑的名称
if (this.logic) {
this.logic.assign({ name });
}
}
/**
* 设置流程组件标题
* @param title 标题
*/
async setTitle(title) {
this.assign({ title });
await this.updateAttr(false, {
actionDesc: `设置流程组件"${this.name}"的标题为"${title}"`,
});
}
/**
* 设置流程组件描述
* @param description 描述
*/
async setDescription(description) {
this.assign({ description });
await this.updateAttr(false, {
actionDesc: `设置流程组件"${this.name}"的描述为"${description}"`,
});
}
/**
* 设置流程组件值 (SequenceFlow)
* @param flowValue 值
*/
async setFlowValue(flowValue) {
this.assign({ flowValue });
await this.updateAttr(false, {
actionDesc: `设置流程组件值`,
});
}
/**
* 设置流程组件任务完成人 (UserTask)
* @param assignee 任务完成人
*/
async setAssignee(assignee) {
this.assign({ assignee });
await this.updateAttr(false, {
actionDesc: `设置流程组件任务完成人`,
});
}
/**
* 从后端 JSON 生成规范的 Param 对象
*/
static from(source, process) {
const processComponent = new ProcessComponent(source);
processComponent.assign({
process,
});
if (source) {
const { returns = [], variables = [], properties = [], logicId, destination, completeTaskInterface, type } = source;
processComponent.assign({
hidden: ['StartNoneEvent', 'EndNoneEvent', 'SequenceFlow'].includes(type),
returns: returns.map((rn) => (__1.ProcessComponentReturn.from(rn, processComponent))),
variables: variables.map((variable) => (__1.ProcessComponentVariable.from(variable, processComponent))),
properties: properties.map((property) => (__1.ProcessComponentProperty.from(property, processComponent))),
});
// 包含 logicId 时,自动初始化 logic
if (logicId) {
// 可能情况下,复用已有 Logic 缓存,防止重复打开多个同样的 logic 编辑器
processComponent.assign({
logic: __1.vertexsMap.get(logicId) || __1.Logic.from({ id: logicId }, processComponent),
});
}
if (destination) {
processComponent.assign({
destination: __1.ProcessComponentAttribute.from(destination, processComponent),
});
}
if (completeTaskInterface) {
const ifce = __1.ProcessInterface.from(completeTaskInterface, processComponent);
processComponent.assign({
completeTaskInterface: ifce,
interfaces: [ifce],
});
}
}
return processComponent;
}
static assignTypeCheckResult(processComponent, typeCheckResult) {
if (!processComponent || !typeCheckResult)
return;
__1.typeCheck.push(typeCheckResult);
const typeCheckStatus = typeCheckResult.typeCheckNote?.status || 'success';
processComponent.assign({
typeCheckResult,
typeCheckStatus,
});
}
}
__decorate([
decorators_1.immutable()
], ProcessComponent.prototype, "level", void 0);
__decorate([
decorators_1.immutable()
], ProcessComponent.prototype, "id", void 0);
__decorate([
decorators_1.immutable()
], ProcessComponent.prototype, "name", void 0);
__decorate([
decorators_1.immutable()
], ProcessComponent.prototype, "title", void 0);
__decorate([
decorators_1.immutable()
], ProcessComponent.prototype, "description", void 0);
__decorate([
decorators_1.immutable()
], ProcessComponent.prototype, "type", void 0);
__decorate([
decorators_1.immutable()
], ProcessComponent.prototype, "returns", void 0);
__decorate([
decorators_1.immutable()
], ProcessComponent.prototype, "variables", void 0);
__decorate([
decorators_1.immutable()
], ProcessComponent.prototype, "logicId", void 0);
__decorate([
decorators_1.immutable()
], ProcessComponent.prototype, "logic", void 0);
__decorate([
decorators_1.immutable()
], ProcessComponent.prototype, "destination", void 0);
__decorate([
decorators_1.immutable()
], ProcessComponent.prototype, "completeTaskInterface", void 0);
__decorate([
decorators_1.immutable()
], ProcessComponent.prototype, "parentId", void 0);
__decorate([
decorators_1.excludedInJSON()
], ProcessComponent.prototype, "hidden", void 0);
__decorate([
decorators_1.excludedInJSON()
], ProcessComponent.prototype, "typeCheckResult", void 0);
__decorate([
decorators_1.excludedInJSON()
], ProcessComponent.prototype, "typeCheckStatus", void 0);
__decorate([
decorators_1.circular(),
decorators_1.immutable()
], ProcessComponent.prototype, "process", void 0);
__decorate([
decorators_1.excludedInJSON(),
decorators_1.immutable()
], ProcessComponent.prototype, "moreChildrenFields", void 0);
__decorate([
decorators_1.excludedInJSON(),
decorators_1.immutable()
], ProcessComponent.prototype, "existingNames", void 0);
__decorate([
decorators_1.excludedInJSON(),
decorators_1.immutable()
], ProcessComponent.prototype, "interfaces", void 0);
__decorate([
decorators_1.action('添加流程组件')
], ProcessComponent.prototype, "create", null);
__decorate([
decorators_1.action('删除流程组件')
], ProcessComponent.prototype, "delete", null);
__decorate([
decorators_1.action('设置流程组件名称')
], ProcessComponent.prototype, "setName", null);
__decorate([
decorators_1.action('设置流程组件标题')
], ProcessComponent.prototype, "setTitle", null);
__decorate([
decorators_1.action('设置流程组件描述')
], ProcessComponent.prototype, "setDescription", null);
__decorate([
decorators_1.action('设置流程组件值')
], ProcessComponent.prototype, "setFlowValue", null);
__decorate([
decorators_1.action('设置流程组件任务完成人')
], ProcessComponent.prototype, "setAssignee", null);
exports.ProcessComponent = ProcessComponent;
exports.default = ProcessComponent;
//# sourceMappingURL=ProcessComponent.js.map