@lcap/asl
Version:
NetEase Application Specific Language
304 lines • 8.88 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.App = void 0;
const decorators_1 = require("../decorators");
const __1 = require("..");
const app_1 = __importDefault(require("../../service/app"));
/**
* 应用类
* @example OA
* @category App
*/
class App extends __1.Vertex {
/**
* @param source 需要合并的部分参数
*/
constructor(source) {
super();
/**
* 概念类型
*/
this.level = __1.LEVEL_ENUM.app;
/**
* App Id
*/
this.id = undefined;
/**
* Alias of id
*/
this.appId = undefined;
/**
* 应用标识
*/
this.name = undefined;
/**
* 应用标题
*/
this.title = undefined;
/**
* 应用图标
*/
this.icon = undefined;
/**
* 应用描述
*/
this.description = undefined;
/**
* 域名
*/
this.dnsAddr = undefined;
/**
* IDE 版本
*/
this.ideVersion = undefined;
/**
* 轻舟项目 Id
*/
this.projectId = undefined;
/**
* 租户 Id
*/
this.tenantId = undefined;
/**
* 租户 Id
*/
this.userGroupId = undefined;
/**
* h5 pc type
*/
this.scope = undefined;
/**
* 发布状态
*/
this.deploying = undefined;
/**
* 发布 Id,用于获取CICD详情
*/
this.deploymentId = undefined;
/**
* 应用下的服务
*/
this.services = [];
/**
* 首个 Web 服务
* 后续 App 创建不了多个模块了,默认处理该服务
*/
this.firstWebService = undefined;
/**
* 首个 Web 服务
* 后续 App 创建不了多个模块了,默认处理该服务
*/
this.firstMicroService = undefined;
/**
* 历史记录
* 用于处理撤销重做
*/
this.history = undefined;
source && this.assign(source);
this.history = new __1.History({ app: this });
}
/**
* 加载详情并同步 envList 信息
* @requires this.id
*/
async loadEnvList(appDetail) {
if (!appDetail) {
appDetail = await app_1.default.loadApp({
query: {
id: this.id,
},
});
}
const { envList } = appDetail.services
.find((service) => service.type === 'microService') || {};
this.assign({ envList });
}
/**
* 加载详情并同步 App 信息
* @requires this.id
*/
async load() {
const result = await app_1.default.loadApp({
query: {
id: this.id,
},
});
await this.loadEnvList(result);
delete result.services;
this.assign(result);
return this;
}
/**
* 加载 App 下的所有服务
*/
async loadServices() {
const result = await app_1.default.loadServices({
query: {
appId: this.id,
},
});
const services = result.map((service) => {
if (service.type === __1.SERVICE_TYPE.web) {
service = __1.WebService.from(service, this);
if (!this.firstWebService)
this.assign({ firstWebService: service });
}
else {
service = __1.MicroService.from(service, this);
if (!this.firstMicroService)
this.assign({ firstMicroService: service });
}
service.assign({ app: this });
return service;
});
await this.firstWebService.loadPackageInfo();
this.assign({ services });
return services;
}
/**
* 加载页面和逻辑详情
*/
async _loadViewsDetail() {
const tasks = [];
this.firstWebService.pages.forEach((page) => {
__1.utils.traverse((current) => {
if (current.node.level === 'view') {
const view = current.node;
view.$def.logics = []; // load syncDef 不会添加重复逻辑
tasks.push(view.load());
}
}, { node: page.rootView });
});
// 自动 load,不用 await
await Promise.all(tasks);
this.emit('loadViewsDetail');
}
/**
* 需要先调用 loadServices 之后再调用此函数
* 加载 App 下的服务具体内容
*/
async _loadServicesDetail(options = {
asyncLoadServicesDetail: false,
asyncLoadViewsDetail: false,
}) {
// 前端许多功能依赖后端数据,所以必须先 load 后端服务
// loadMicroService
await Promise.all([
this.firstMicroService.loadEntities(),
this.firstMicroService.loadStructures(),
this.firstMicroService.loadEnums(),
]);
// interfaces params 的 children 依赖 entities 和 structures,所以必须拆成两个 Promise
await Promise.all([
this.firstMicroService.loadInterfaces(),
this.firstMicroService.loadProcesses(),
]);
// loadWebService
await this.firstWebService.loadPages();
if (options.asyncLoadViewsDetail)
this._loadViewsDetail();
else
await this._loadViewsDetail();
this.emit('loadedAll');
}
/**
* 加载 App 下所有子节点
* @example
* const app = new App({ id: appId });
* await app.loadAll();
*/
async loadAll(options = {
asyncLoadServicesDetail: false,
asyncLoadViewsDetail: false,
}) {
await Promise.all([
this.load(),
this.loadServices(),
__1.updateGenericTypeList(),
]);
if (options.asyncLoadServicesDetail)
this._loadServicesDetail(options);
else
await this._loadServicesDetail(options);
}
/**
* 从后端 JSON 生成规范的 App 对象
* @param source JSON
*/
from(source) {
return new App(source);
}
}
__decorate([
decorators_1.immutable()
], App.prototype, "level", void 0);
__decorate([
decorators_1.immutable()
], App.prototype, "id", void 0);
__decorate([
decorators_1.immutable()
], App.prototype, "appId", void 0);
__decorate([
decorators_1.immutable()
], App.prototype, "name", void 0);
__decorate([
decorators_1.immutable()
], App.prototype, "title", void 0);
__decorate([
decorators_1.immutable()
], App.prototype, "icon", void 0);
__decorate([
decorators_1.immutable()
], App.prototype, "description", void 0);
__decorate([
decorators_1.immutable()
], App.prototype, "dnsAddr", void 0);
__decorate([
decorators_1.immutable()
], App.prototype, "officialType", void 0);
__decorate([
decorators_1.immutable()
], App.prototype, "ideVersion", void 0);
__decorate([
decorators_1.immutable()
], App.prototype, "projectId", void 0);
__decorate([
decorators_1.immutable()
], App.prototype, "tenantId", void 0);
__decorate([
decorators_1.immutable()
], App.prototype, "userGroupId", void 0);
__decorate([
decorators_1.immutable()
], App.prototype, "scope", void 0);
__decorate([
decorators_1.immutable()
], App.prototype, "deploying", void 0);
__decorate([
decorators_1.immutable()
], App.prototype, "deploymentId", void 0);
__decorate([
decorators_1.immutable()
], App.prototype, "services", void 0);
__decorate([
decorators_1.immutable()
], App.prototype, "firstWebService", void 0);
__decorate([
decorators_1.immutable()
], App.prototype, "firstMicroService", void 0);
__decorate([
decorators_1.immutable(),
decorators_1.excludedInJSON()
], App.prototype, "history", void 0);
exports.App = App;
exports.default = App;
//# sourceMappingURL=App.js.map