@lcap/asl
Version:
NetEase Application Specific Language
176 lines (171 loc) • 4.11 kB
text/typescript
import { immutable, circular, excludedInJSON } from '../decorators';
import { LEVEL_ENUM, Vertex, Logic, Process, ProcessComponent } from '..';
import { findUsageService } from '../../service/common';
// src/views/designer/asl/src/service/common
// src/views/designer/asl/src/types/process/ProcessInterface.ts
/**
* 接口类
*/
export class ProcessInterface extends Vertex {
/**
* 概念类型
*/
()
public readonly level: LEVEL_ENUM = LEVEL_ENUM.interface;
/**
* Id
*/
()
public readonly id: string = undefined;
/**
* InterfaceKey
*/
()
public readonly key: string = undefined;
/**
* 名称
*/
()
public readonly name: string = undefined;
/**
* 协议
*/
()
public readonly protocol: string = undefined;
/**
* 地址
*/
()
public readonly host: string = undefined;
/**
* 端口
*/
()
public readonly port: string = undefined;
/**
* 路径
*/
()
public readonly path: string = undefined;
/**
* 方法
*/
()
public readonly method: string = undefined;
/**
* 描述
*/
()
public readonly description: string = undefined;
/**
* 逻辑 Id
*/
()
public readonly logicId: string = undefined;
/**
* 逻辑
*/
()
()
public readonly logic: Logic = undefined;
/**
* Service 类型
*/
()
public readonly serviceType: 'micro' | 'entity' | 'process' = undefined;
/**
* Service Id
*/
()
public readonly serviceId: string = undefined;
/**
* Service 名称
*/
()
public readonly serviceName: string = undefined;
/**
* Process
*/
()
()
public readonly process: Process = undefined;
/**
* ProcessComponent
*/
()
()
public readonly processComponent: ProcessComponent = undefined;
/**
* 参数
*/
()
public readonly parameters: string = undefined;
/**
* 返回值
*/
()
public readonly responses: string = undefined;
/**
* 请求数据
*/
()
public readonly requestBody: string = undefined;
/**
* 树组件的子节点字段
*/
()
()
public readonly moreChildrenFields: Array<string> = ['logic.params', 'logic.returns', 'logic.variables'];
/**
* 周边存在的名称
*/
()
public existingNames: Array<string> = [];
/**
* @param source 需要合并的部分参数
*/
constructor(source?: Partial<ProcessInterface>) {
super();
source && this.assign(source);
}
/**
* 按当前 id 加载接口数据
* @requires this.id
*/
load() {
return this;
}
/**
* 从后端 JSON 生成规范的 ProcessInterface 对象
*/
public static from(source: any, parent: Process | ProcessComponent) {
const item = new ProcessInterface(source);
item.assign({
key: `#/${parent.id}/${item.id}`,
expanded: false,
});
item.logic && item.assign({ logic: Logic.from(item.logic, item) });
if (parent instanceof Process) {
item.assign({ process: parent });
} else if (parent instanceof ProcessComponent) {
item.assign({ processComponent: parent });
}
return item;
}
/**
* 查找引用
*/
async findUsage() {
let id = this.id;
if (['entity', 'micro', 'process', 'processComponent'].includes(this.serviceType)) {
id = this.logicId;
}
const result = await findUsageService.findUsage({
query: {
id,
},
});
return result;
}
}
export default ProcessInterface;