@lcap/asl
Version:
NetEase Application Specific Language
357 lines • 12.5 kB
JavaScript
;
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.Process = void 0;
const decorators_1 = require("../decorators");
const __1 = require("..");
const process_1 = __importDefault(require("../../service/process"));
/**
* 流程类
*/
class Process extends __1.Vertex {
/**
* @param source 需要合并的部分参数
*/
constructor(source) {
super();
/**
* 概念类型
*/
this.level = __1.LEVEL_ENUM.process;
/**
* 流程 Id
*/
this.id = undefined;
/**
* 流程名称
*/
this.name = undefined;
/**
* 流程标题
*/
this.title = undefined;
/**
* 流程描述
*/
this.description = undefined;
/**
* 流程组件集合
*/
this.childShapes = [];
/**
* 流程输入参数
*/
this.params = [];
/**
* 流程输出参数
*/
this.returns = [];
/**
* 流程内置参数
*/
this.properties = [];
/**
* 启动流程接口
*/
this.launchProcessInterface = undefined;
/**
* 后端服务类型
*/
this.serviceType = 'MICROSERVICE';
/**
* 所属后端服务 Id
*/
this.serviceId = undefined;
/**
* 所属后端服务
*/
this.service = undefined;
/**
* 树组件的子节点字段
*/
this.childrenField = 'childShapes';
/**
* 树组件的子节点字段
*/
this.moreChildrenFields = ['params', 'returns', 'properties', 'interfaces'];
/**
* 已存在名称集合
*/
this.existingNames = [];
/**
* 接口列表,单纯用于 tree 展示
*/
this.interfaces = [];
this.assign(source);
}
/**
* 添加流程
*/
async create(none, actionOptions) {
__1.config.defaultApp?.emit('saving');
this.assign({ editing: false, loading: true });
const body = this.toJSON();
const result = await process_1.default.add({
headers: {
appId: __1.config.defaultApp?.id,
operationAction: actionOptions?.actionName || 'Process.create',
operationDesc: actionOptions?.actionDesc || `添加流程"${this.name}${this.title ? `(${this.title})` : ''}"`,
},
body,
});
this.assign(Process.from(result, this.service));
this.service.emit('interfacesChange');
await __1.config.defaultApp?.history.load();
__1.config.defaultApp?.emit('saved');
return this;
}
/**
* 删除流程
*/
async delete(none, actionOptions) {
__1.config.defaultApp?.emit('saving');
await process_1.default.delete({
headers: {
appId: __1.config.defaultApp?.id,
operationAction: actionOptions?.actionName || 'Process.delete',
operationDesc: actionOptions?.actionDesc || `删除流程"${this.name}${this.title ? `(${this.title})` : ''}"`,
},
path: {
id: this.id,
},
});
__1.typeCheck.deleteByProcess(this.id);
const index = this.service.processes.indexOf(this);
~index && this.service.processes.splice(index, 1);
this.destroy();
this.service.emit('interfacesChange');
await __1.config.defaultApp?.history.load();
__1.config.defaultApp?.emit('saved');
}
/**
* 修改流程
*/
async update(deep, actionOptions, then) {
__1.config.defaultApp?.emit('saving');
const body = this.toPlainJSON();
const result = await process_1.default.update({
headers: {
appId: __1.config.defaultApp?.id,
operationAction: actionOptions?.actionName || 'Process.update',
operationDesc: actionOptions?.actionDesc || `修改流程"${this.name}${this.title ? `(${this.title})` : ''}"`,
},
body,
});
// 深度更新,需要同步更新 流程接口 和 UserTask 中的 完成任务接口
if (deep && result) {
const { childShapes = [], launchProcessInterface } = result;
const { name, path, method } = launchProcessInterface;
this.launchProcessInterface.assign({ name, path, method });
this.launchProcessInterface.logic.assign({ name });
this.childShapes.forEach((childShape) => {
const { type, completeTaskInterface } = childShape;
if (type === 'UserTask') {
const newUserTask = childShapes.find((cShape) => cShape.id === childShape.id);
const { name, path, method } = newUserTask.completeTaskInterface;
completeTaskInterface.assign({ name, path, method });
completeTaskInterface.logic.assign({ name });
}
});
this.service.emit('interfacesChange');
}
await then?.();
await __1.config.defaultApp?.history.load();
__1.config.defaultApp?.emit('saved');
return this;
}
/**
* 批量修改流程组件
*/
async batchComponents(body, actionOptions) {
__1.config.defaultApp?.emit('saving');
const result = await process_1.default.batchComponents({
headers: {
appId: __1.config.defaultApp?.id,
operationAction: actionOptions?.actionName || 'Process.batchComponents',
operationDesc: `批量修改流程组件"${this.name}${this.title ? `(${this.title})` : ''}"`,
},
body,
});
let childShapes = [];
this.childShapes.forEach((processComponent) => {
const isDeleted = result.delete.find((node) => node.id === processComponent.id);
if (isDeleted) {
return;
}
const isUpdatedComp = result.update.find((node) => node.id === processComponent.id);
if (isUpdatedComp) {
childShapes.push(__1.ProcessComponent.from(isUpdatedComp, this));
return;
}
childShapes.push(processComponent);
});
childShapes = childShapes.concat((result.add).map((childShape) => __1.ProcessComponent.from(childShape, this)));
this.assign({ childShapes });
this.service.emit('interfacesChange');
this.checkType();
await __1.config.defaultApp?.history.load();
__1.config.defaultApp?.emit('saved');
}
/**
* 流程级别的类型检查
*/
async checkType() {
const result = await process_1.default.checkTypeProcess({
path: { id: this.id },
});
__1.typeCheck.deleteByProcess(this.id);
__1.typeCheck.pushAll(result);
result.forEach((typeCheckResult) => {
if (typeCheckResult.processComponentId) {
const processComponent = __1.vertexsMap.get(typeCheckResult.processComponentId);
__1.ProcessComponent.assignTypeCheckResult(processComponent, typeCheckResult);
}
if (typeCheckResult.logicId) {
const logicItem = __1.vertexsMap.get(typeCheckResult.id);
__1.LogicItem.assignTypeCheckResult(logicItem, typeCheckResult);
}
});
}
/**
* 设置流程名称
* @param name 名称
*/
async setName(name) {
const oldName = this.name;
this.assign({ name });
await this.update(true, {
actionDesc: `设置流程"${oldName}"的名称为"${name}"`,
});
}
/**
* 设置流程标题
* @param title 标题
*/
async setTitle(title) {
this.assign({ title });
await this.update(false, {
actionDesc: `设置流程"${this.name}"的标题为"${title}"`,
});
}
/**
* 设置流程描述
* @param description 描述
*/
async setDescription(description) {
this.assign({ description });
await this.update(false, {
actionDesc: `设置流程"${this.name}"的描述为"${description}"`,
});
}
/**
* 从后端 JSON 生成规范的 Param 对象
*/
static from(source, service) {
const process = new Process(source);
process.assign({ service });
if (source) {
const { params = [], returns = [], properties = [], childShapes = [], launchProcessInterface } = source;
process.assign({
params: params.map((param) => __1.ProcessParam.from(param, process)),
returns: returns.map((rn) => __1.ProcessReturn.from(rn, process)),
properties: properties.map((property) => __1.ProcessProperty.from(property, process)),
childShapes: childShapes.map((childShape) => __1.ProcessComponent.from(childShape, process)),
});
if (launchProcessInterface) {
const ifce = __1.ProcessInterface.from(launchProcessInterface, process);
process.assign({
launchProcessInterface: ifce,
interfaces: [ifce],
});
}
}
return process;
}
}
__decorate([
decorators_1.immutable()
], Process.prototype, "level", void 0);
__decorate([
decorators_1.immutable()
], Process.prototype, "id", void 0);
__decorate([
decorators_1.immutable()
], Process.prototype, "name", void 0);
__decorate([
decorators_1.immutable()
], Process.prototype, "title", void 0);
__decorate([
decorators_1.immutable()
], Process.prototype, "description", void 0);
__decorate([
decorators_1.immutable()
], Process.prototype, "childShapes", void 0);
__decorate([
decorators_1.immutable()
], Process.prototype, "params", void 0);
__decorate([
decorators_1.immutable()
], Process.prototype, "returns", void 0);
__decorate([
decorators_1.immutable()
], Process.prototype, "properties", void 0);
__decorate([
decorators_1.immutable()
], Process.prototype, "launchProcessInterface", void 0);
__decorate([
decorators_1.immutable()
], Process.prototype, "serviceType", void 0);
__decorate([
decorators_1.immutable()
], Process.prototype, "serviceId", void 0);
__decorate([
decorators_1.circular(),
decorators_1.immutable()
], Process.prototype, "service", void 0);
__decorate([
decorators_1.excludedInJSON(),
decorators_1.immutable()
], Process.prototype, "childrenField", void 0);
__decorate([
decorators_1.excludedInJSON(),
decorators_1.immutable()
], Process.prototype, "moreChildrenFields", void 0);
__decorate([
decorators_1.excludedInJSON(),
decorators_1.immutable()
], Process.prototype, "existingNames", void 0);
__decorate([
decorators_1.excludedInJSON(),
decorators_1.immutable()
], Process.prototype, "interfaces", void 0);
__decorate([
decorators_1.action('添加流程')
], Process.prototype, "create", null);
__decorate([
decorators_1.action('删除流程')
], Process.prototype, "delete", null);
__decorate([
decorators_1.action('设置流程名称')
], Process.prototype, "setName", null);
__decorate([
decorators_1.action('设置流程标题')
], Process.prototype, "setTitle", null);
__decorate([
decorators_1.action('设置流程描述')
], Process.prototype, "setDescription", null);
exports.Process = Process;
exports.default = Process;
//# sourceMappingURL=Process.js.map