UNPKG

@lcap/asl

Version:

NetEase Application Specific Language

194 lines 7.51 kB
"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; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.GlobalLogicNode = void 0; const decorators_1 = require("../decorators"); const __1 = require(".."); const dataTypes_1 = require("../data/dataTypes"); /** * 数据分类 */ class GlobalLogicNode extends __1.Vertex { /** * @param source 需要合并的部分参数 */ constructor(source) { super(); /** * 概念类型 */ this.level = __1.LEVEL_ENUM.gloablLogicNode; this.type = undefined; this.globalLogics = []; this.entityLogics = []; this.processLogics = []; this.interfaces = []; this.structures = []; this.categories = []; this.service = undefined; source && this.assign(source); } createOrGetCatogory(category) { let ciInstance = this.categories.find((ci) => ci.name === category); if (!ciInstance) { ciInstance = { level: __1.LEVEL_ENUM.category, name: category, categoryInterfaces: [], categoryStructures: [], isLeaf: false, interfaceExpanded: false, structureExpanded: false, }; this.categories.unshift(ciInstance); } return ciInstance; } addCategoryInterface(iface) { const category = iface.category; const ciInstance = this.createOrGetCatogory(category); ciInstance.categoryInterfaces.unshift(iface); } addCategoryStructure(sturct) { const category = sturct.category; const ciInstance = this.createOrGetCatogory(category); const index = ciInstance.categoryStructures.findIndex((s) => s.id === sturct.id); if (index >= 0) { const [oldstruct] = ciInstance.categoryStructures.splice(index, 1, sturct); oldstruct.destroy(); } else { ciInstance.categoryStructures.unshift(sturct); } dataTypes_1.updateDataTypeList(); } checkExternalInterface(category, name) { let itface; const categoryInstance = this.categories.find((ci) => { itface = ci.categoryInterfaces.find((itface) => itface.name === name); return ci.name === category && !!itface; }); return categoryInstance ? { category: categoryInstance, interface: itface, } : null; } removeCategory(categoryInstance) { if (!categoryInstance.categoryInterfaces.length && !categoryInstance.categoryStructures.length) { const index = this.categories.indexOf(categoryInstance); ~index && this.categories.splice(index, 1); } } removeCategoryStructure(sturct) { const category = sturct.category; const ciInstance = this.createOrGetCatogory(category); const index = ciInstance.categoryStructures.findIndex((s) => s.id === sturct.id); if (index >= 0) { ciInstance.categoryStructures.splice(index, 1); } this.removeCategory(ciInstance); } removeInterface(itface) { if (itface.serviceType === 'external') { const category = itface.category; const categoryInstance = this.categories.find((ci) => ci.name === category); const index = categoryInstance.categoryInterfaces.indexOf(itface); ~index && categoryInstance.categoryInterfaces.splice(index, 1); this.removeCategory(categoryInstance); } if (itface.serviceType === 'micro') { if (itface.exportedInterface) { itface.exportedInterface.delete(); } const index = this.globalLogics.indexOf(itface); ~index && this.globalLogics.splice(index, 1); } } syncEntityLogics() { const entityLogics = []; this.service.data.entities.forEach((entity) => { entityLogics.push(entity); }); this.entityLogics = entityLogics; } syncStructures(structuresOrigin) { const structures = this.structures; const smap = {}; // removeRef structures.forEach((s) => { delete __1.dataTypesMap[s.schemaRef]; smap[s.id] = s; }); this.categories.forEach((category) => { category.categoryStructures.forEach((s) => { delete __1.dataTypesMap[s.schemaRef]; smap[s.id] = s; }); }); function replaceInStructureList(structures, structureNode) { const sid = structureNode.id; const index = structures.findIndex((s) => s.id === sid); structures.splice(index, 1, structureNode); delete smap[sid]; } function removeInStructureList(structures, structureNode) { const sid = structureNode.id; const index = structures.findIndex((s) => s.id === sid); structures.splice(index, 1); structureNode.destroy(); } structuresOrigin.forEach((item) => { const structureNode = __1.Structure.from(item, this.service); const sid = structureNode.id; if (structureNode.serviceType === 'external' && structureNode.category) { const category = this.categories.find((c) => c.name === structureNode.category); if (category && smap[sid]) { replaceInStructureList(category.categoryStructures, structureNode); } else { this.addCategoryStructure(structureNode); } } else { if (smap[sid]) { replaceInStructureList(structures, structureNode); } else { structures.unshift(structureNode); } } }); Object.keys(smap).forEach((key) => { const struct = smap[key]; if (struct.category) { const category = this.categories.find((c) => c.name === struct.category); removeInStructureList(category.categoryStructures, struct); } else { removeInStructureList(structures, struct); } }); dataTypes_1.updateDataTypeList(); } } __decorate([ decorators_1.immutable() ], GlobalLogicNode.prototype, "level", void 0); __decorate([ decorators_1.immutable() ], GlobalLogicNode.prototype, "type", void 0); __decorate([ decorators_1.immutable() ], GlobalLogicNode.prototype, "globalLogics", void 0); __decorate([ decorators_1.circular(), decorators_1.immutable() ], GlobalLogicNode.prototype, "service", void 0); exports.GlobalLogicNode = GlobalLogicNode; exports.default = GlobalLogicNode; //# sourceMappingURL=GlobalLogicNode.js.map