UNPKG

@lcap/nasl

Version:

NetEase Application Specific Language

1,029 lines 47.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.dealWithEntityPropertyWithProcessBindV2 = exports.allowAdjustProcessEntity = exports.allowAdjustEntityProperty = exports.allowAdjustReferenceEntityProperty = exports.allowAdjustEntity = void 0; const nasl_concepts_1 = require("@lcap/nasl-concepts"); const asserts_1 = require("@lcap/nasl-concepts/asserts"); const nasl_concepts_2 = require("@lcap/nasl-concepts"); const service_1 = require("@lcap/nasl-concepts/service"); const utils_1 = require("../utils"); const common_1 = require("../common"); const nasl_sentry_1 = require("@lcap/nasl-sentry"); const templator_1 = require("../templator"); const vue_1 = require("../utils/vue"); nasl_concepts_1.BaseNode.prototype.findReadOnlyLogicUsage = function () { let targetNode; if (this.parentNode.concept === 'Namespace' || this.parentNode.parentNode.concept === 'Namespace') { const sourceMap = this.parentNode.concept === 'Namespace' ? this.parentNode.parentNode.sourceMap : this.parentNode.parentNode.parentNode.sourceMap; for (const item of sourceMap || []) { const logic = item[0]; if (this.concept === 'Logic') { if (logic instanceof nasl_concepts_1.Logic) if (logic.calleewholeKey === this.calleewholeKey) { targetNode = logic; break; } } else { if (logic instanceof nasl_concepts_1.Logic) if (logic.calleewholeKey === this.parentNode.calleewholeKey) { targetNode = logic; break; } } } } else if (this.parentNode.concept === 'Module') { // 父级是模块的还是用它本身去查找引用 targetNode = this; } else if (this.getAncestor('Connector')) { // 如果是连接器下的操作还是用它本身去查找引用 targetNode = this; } else { const sourceMap = this.parentNode.sourceMap; for (const item of sourceMap) { const logic = item[0]; if (logic.calleewholeKey && logic.calleewholeKey === this.calleewholeKey) { targetNode = logic; break; } } if (!targetNode) for (const item of sourceMap) { const logic = item[0]; if (logic.getNamespace && logic.getNamespace() === this.getNamespace()) { targetNode = logic; break; } } } try { const app = this.getAncestor('App'); const naslServer = app.naslServer; return naslServer.findReferenceAndRender((targetNode || this)); } catch (err) { console.log(err); } }; // 查找引用,指用户点击 “查找引用” 这一 “产品功能”,不是 LS 的严格意义的查找引用 nasl_concepts_1.BaseNode.prototype.findUsage = function findUsage() { try { const app = this.getAncestor('App'); const naslServer = app.naslServer; return naslServer.findReferenceAndRender(this); } catch (err) { console.log(err); } }; // 通过当前节点,查找被引用的节点 nasl_concepts_1.BaseNode.prototype.nodeFindRefNodes = function nodeFindRefNodes() { try { const app = this.getAncestor('App'); const naslServer = app.naslServer; return naslServer.nodeFindRefNodes(this); } catch (err) { console.log(err); } }; /** * AuthLogicForCallInterface 通过当前节点,查找被引用的节点 * 以下面代码为例由于相关文件TS代码翻译的特殊性, * 导致在查找引用的时候是以类型参数为准,而不是实际参数 * 此种行为会导致函数体内的参数无法查找到引用 * ({par, pa, api}:{ par: nasl.core.String, pa: nasl.core.String, api?: ApiReturn}) * 为此需要重新查找一次引用 */ async function extensionRefForAuthLogicForCallInterfaceParams(refsList, node, naslServer) { const target = refsList[0]; const newRefs = await naslServer.references({ file: refsList[0].file, line: target.start.line, offset: target.start.offset, }); return [...newRefs.refs]; } /** * Handle directory update when renaming */ function handleDirectoryRename(node, newValue) { const app = node.rootNode; app.emit('collect:start', { actionMsg: `重命名${node.constructor?.nodeTitle}`, }); const oldCompleteName = node.completeName; const directory = node.directory; const definition = directory.definitions.find((item) => item.completeName === oldCompleteName); node.setName(newValue); if (definition) { definition.setName(newValue); } app.emit('collect:end'); } nasl_concepts_1.BaseNode.prototype.changeName = async function changeName(newValue, updateAll = false) { try { const allowAdjust = await (0, exports.allowAdjustEntityProperty)(this); if (!allowAdjust) { const confirmParms = { actionType: 'processEntity', node: this, icon: 'warning', }; (0, common_1.invokeCommand)('tsConfirm.open', confirmParms); return; } /** * 查找这个节点是不是有依赖 */ const app = this.getAncestor('App'); const naslServer = app.naslServer; // const refsListOld = await naslServer._isHaveRefOld(this as any); const refsList = await naslServer._isHaveRef(this); // TODO: 理论上这里的查询不再需要,但是需要验证 // // 鉴权方式 参数修改需要协同变更相关参数 // // 但由于鉴权返回实现TS的特殊性,在查询节点的时候,只会查询类型参数的引用,导致引用查找缺失 // // 因此需要手动更新一下 // if (isParam(this) && isAuthLogicForCallInterface(this.parentNode)) { // refsList = await extensionRefForAuthLogicForCallInterfaceParams(refsList, this, naslServer); // } // 是不是有引用有的话,就返回 /** * @param this 当前重命名的节点 * @param newValue 传递过来的新值,给MemberExpression用的比较特殊 * 而且,这个新值不一定会用到,MemberExpression在批量更新的时候,可以取到新的value, 这里需要位置信息防止 a.a.a.a 中的一个a发生修改 * @returns 找到的引用 */ const res = naslServer._renamePrepare(this, refsList, newValue); // 针对外部接口的鉴权方式,sourceMap 定位仅仅 定位到 CallAuthInterfacer // 因此这里需要保存this来做上下文判断 const _this = this; if (res.length <= 1) { if (this.concept === 'enumItem') { this.setValue(newValue); } else if (this.concept === 'Process' || (this.concept === 'ProcessElement' && ['InitiateTask', 'ApprovalTask', 'UserTask'].includes(this.type))) { const confirmParms = { actionType: 'rename', node: this, newValue, unReference: true, icon: 'warning', }; if (this.concept === 'Process') { confirmParms.title = '重命名流程名称'; confirmParms.process = true; } else if (this.concept === 'ProcessElement') { confirmParms.title = '修改节点名称'; confirmParms.process = true; } const callback = () => { this.setName(newValue); }; updateAll ? callback() : (0, common_1.invokeCommand)('tsConfirm.open', confirmParms, callback); } else if ((nasl_concepts_2.asserts.isLogic(this) || nasl_concepts_2.asserts.isEntity(this) || nasl_concepts_2.asserts.isStructure(this) || nasl_concepts_2.asserts.isEnum(this)) && this.directory) { handleDirectoryRename(this, newValue); } else this.setName(newValue); } else { const callback = (value, toast) => { if (value) { const App = this.rootNode; // 实体重命名时需要同步更新绑定该实体的审批页面 if (this.concept === 'Entity') { const originEvent = []; this.__bindView?.forEach((view) => { originEvent.push({ originEvent: { action: 'update', target: view, } }); }); naslServer.embeddedTSEmitter?.emit('change', { value: originEvent, }); } // 收集修改 App.emit('collect:start', { actionMsg: '重命名并更新引用', }); res.forEach((item) => { if (item.doNotChange) return; const itemNode = item.node; // MsgTriggerLauncher 比较特殊,实际更名的应该为成员表达式 if (itemNode instanceof nasl_concepts_1.MsgTriggerLauncher) { itemNode.callBackLogic.setName(newValue); return; } if (item.newValue) { // 如果有指定的修改方法,就用那个,没有就修改名字 if (item.setTypeMethods) { const func = itemNode && itemNode[item.setTypeMethods]; typeof func === 'function' && itemNode[item.setTypeMethods](item.newValue); } else { itemNode.setName?.(item.newValue); } } else { if (_this.concept === 'AuthLogicForCallInterface' && itemNode.concept === 'CallAuthInterface') { const { calleewholeKey } = itemNode; let targetItf; const connector = itemNode.getAncestor('Connector'); if (connector) { targetItf = connector.interfaces?.find((itf) => { return calleewholeKey.endsWith(itf.name); }); } else { targetItf = (0, service_1.getNodeByNodeCallee)(App, calleewholeKey); } targetItf?.setAuthLogic?.(newValue); // 需要触发更新,否则对应的ts文件不会更新会导致鉴权方式找不到报错 itemNode.update({}); } else if ((nasl_concepts_2.asserts.isLogic(itemNode) || nasl_concepts_2.asserts.isEntity(itemNode) || nasl_concepts_2.asserts.isStructure(itemNode) || nasl_concepts_2.asserts.isEnum(itemNode)) && itemNode.directory) { handleDirectoryRename(itemNode, newValue); } else { item.setTypeMethods ? itemNode[item.setTypeMethods](newValue) : itemNode.setName?.(newValue); } } }); // 结束修改 ,批量操作 App.emit('collect:end'); toast && toast(); } else { if ((nasl_concepts_2.asserts.isLogic(this) || nasl_concepts_2.asserts.isEntity(this) || nasl_concepts_2.asserts.isStructure(this) || nasl_concepts_2.asserts.isEnum(this)) && this.directory) { handleDirectoryRename(this, newValue); } else { this.setName(newValue); } } }; const confirmParms = { actionType: 'rename', node: this, newValue, icon: 'warning', }; if (this.concept === 'Process') { confirmParms.title = '重命名流程名称'; confirmParms.process = true; } else if (this.concept === 'ProcessElement' && ['InitiateTask', 'ApprovalTask', 'UserTask'].includes(this.type)) { confirmParms.title = '修改节点名称'; confirmParms.process = true; } updateAll ? callback(true) : (0, common_1.invokeCommand)('tsConfirm.open', confirmParms, callback); return; } } catch (err) { console.error(err); } }; nasl_concepts_1.BaseNode.prototype.removeBindEntityPropertyViewEelment = async function removeBindEntityPropertyViewEelment() { const app = this.getAncestor('App'); const naslServer = app.naslServer; const refsList = await naslServer._isHaveRef(this); // 查找到引用链 const entity = this.getAncestor('Entity')?.toJSON(); entity.properties = entity.properties.filter((property) => property.name !== this.name); refsList.forEach(({ node }) => { while (node) { if (node instanceof nasl_concepts_1.ViewElement && node.getBindAttribute('bindEntityProperty')) { node.delete(); } if (node instanceof nasl_concepts_1.CallQueryComponent && node?.label === '数据查询') { node.update({ where: (0, templator_1.genWhereExpression)(entity), }); } node = node.parentNode; } }); }; /** 删除连接器 */ function delConnection(node) { const app = node.rootNode; app.emit('collect:start', { actionMsg: '删除连接器', }); // 删除相关的触发器 [...app.triggerLaunchers].forEach((launcher) => { if (launcher.calleeConnectionName === node.name) { launcher.delete(); } }); node.delete(); app.emit('collect:end'); } /** * 允许调整实体 * @param node * @param refsList * @returns */ const allowAdjustEntity = async (node) => { let allowAdjust = true; // 删除实体时,需要计算在流程中是否有使用 if (node instanceof nasl_concepts_1.Entity) { const app = node.getAncestor('App'); const naslServer = app.naslServer; const refsList = await naslServer._isHaveRef(node); for (let i = 0; i < refsList.length; i++) { const { node: minRangeNode } = refsList[i]; const processV2 = minRangeNode.getAncestor('ProcessV2'); if (minRangeNode && processV2) { // 流程关联的实体不允许删除 if (minRangeNode instanceof nasl_concepts_1.ProcessBindV2 || minRangeNode.getAncestor('ProcessBindV2')) { allowAdjust = false; break; } if (minRangeNode instanceof nasl_concepts_1.TypeAnnotation) { const processBindV2 = minRangeNode.getAncestor('ProcessBindV2'); const structureProperty = minRangeNode.getAncestor('StructureProperty'); // 流程关联的实体外键关联的实体 if (processBindV2 && structureProperty) { let structurePropertyRefsList = await naslServer._isHaveRef(structureProperty); structurePropertyRefsList.find(({ node: minRangeNode }) => { const processV2 = minRangeNode.getAncestor('ProcessV2'); if (processV2 && minRangeNode !== structureProperty) { if (processV2.__isVirtual) { allowAdjust = false; return true; } } return false; }); } } } } } return allowAdjust; }; exports.allowAdjustEntity = allowAdjustEntity; /** * 是否允许调整关联实体属性 * @param node * @returns */ const allowAdjustReferenceEntityProperty = async (node) => { let allowAdjust = true; // 删除实体属性时,需要计算在流程中是否有使用 if (node instanceof nasl_concepts_1.EntityProperty) { const { relationNamespace, relationEntity } = node || {}; if (relationNamespace && relationEntity) { const app = node.getAncestor('App'); // 属性关联的实体绑定的流程 const bindedProcessV2s = app?.processV2s?.filter((processV2) => { const { refNamespace, refName } = processV2?.bind || {}; return relationNamespace === refNamespace && relationEntity === refName; }); if (bindedProcessV2s?.length) { const naslServer = app.naslServer; const refsList = await naslServer._isHaveRef(node); refsList.find(({ node: minRangeNode }) => { const processV2 = minRangeNode.getAncestor('ProcessV2'); if (minRangeNode && processV2) { // 被权限字段引用不算引用 const isInFieldPermission = minRangeNode.concept === 'FieldPermissionV2' || minRangeNode.getAncestor('FieldPermissionV2'); if (!isInFieldPermission && processV2.__isVirtual && bindedProcessV2s.includes(processV2)) { allowAdjust = false; return true; } } }); } } } return allowAdjust; }; exports.allowAdjustReferenceEntityProperty = allowAdjustReferenceEntityProperty; /** * 允许调整实体属性 * @param node * @param refsList * @returns */ const allowAdjustEntityProperty = async (node) => { let allowAdjust = true; // 删除实体属性时,需要计算在流程中是否有使用 if (node instanceof nasl_concepts_1.EntityProperty) { const app = node.getAncestor('App'); const naslServer = app.naslServer; const refsList = await naslServer._isHaveRef(node); refsList.find(({ node: minRangeNode }) => { const processV2 = minRangeNode.getAncestor('ProcessV2'); if (minRangeNode && processV2) { // 被权限字段引用不算引用 const isInFieldPermission = minRangeNode.concept === 'FieldPermissionV2' || minRangeNode.getAncestor('FieldPermissionV2'); if (!isInFieldPermission && processV2.__isVirtual) { allowAdjust = false; return true; } } }); } return allowAdjust; }; exports.allowAdjustEntityProperty = allowAdjustEntityProperty; /** * 允许调整流程实体 * @param node * @param refsList * @returns */ const allowAdjustProcessEntity = async (node) => { return await (0, exports.allowAdjustEntity)(node) && await (0, exports.allowAdjustEntityProperty)(node); }; exports.allowAdjustProcessEntity = allowAdjustProcessEntity; /** * 删除/解除关联关系的时候,处理流程中的绑定数据 */ const dealWithEntityPropertyWithProcessBindV2 = (node) => { if (node instanceof nasl_concepts_1.EntityProperty) { const { relationNamespace, relationEntity } = node; const entity = node.entity; // 有关联实体的情况下,需要判断关联实体是否需要在流程绑定实体中删除 if (relationNamespace && relationEntity) { const property = entity.properties.find((property) => { return property !== node && property.relationNamespace === relationNamespace && property.relationEntity === relationEntity; }); // 如果当前实体有另一个属性也关联了那个实体,就不用处理 if (!property) { const app = node.app; // 收集修改 app.emit('collect:start', { actionMsg: '实体属性', }); app.processV2s.forEach((processV2) => { const { refNamespace, refName } = processV2?.bind || {}; if (relationNamespace === refNamespace && relationEntity === refName) { const { typeAnnotation } = processV2?.bind || {}; const { properties } = typeAnnotation; const entityNamespace = entity.getNamespace(); const entityName = entity.name; let relationName = ''; properties?.forEach((property) => { const { typeArguments } = property?.typeAnnotation || {}; if (typeArguments?.length === 1) { const { typeNamespace, typeName } = typeArguments[0]; if (typeNamespace === entityNamespace && typeName === entityName) { relationName = property.name; property.delete(); } } }); // 删除子表单权限字段 const elements = []; processV2.processDefinitions.forEach((processDefinition) => { if (processDefinition.status === 'designing') { elements.push(...processDefinition.elements); } }); elements.forEach((ele) => { if (['InitiateTask', 'ApprovalTask', 'SubmitTask', 'CCTask'].includes(ele.type)) { const fieldPermission = ele.fieldPermissions.find((fieldPermission) => fieldPermission.propertyName === relationName); fieldPermission?.delete?.(); } }); } }); app.emit('collect:end'); } } } }; exports.dealWithEntityPropertyWithProcessBindV2 = dealWithEntityPropertyWithProcessBindV2; /** * 准备删除 */ nasl_concepts_1.BaseNode.prototype.prepareDelete = async function prepareDelete(cb) { try { const allowAdjust = await (0, exports.allowAdjustProcessEntity)(this); if (!allowAdjust) { const confirmParms = { actionType: 'processEntity', node: this, icon: 'warning', }; (0, common_1.invokeCommand)('tsConfirm.open', confirmParms); return; } /** * 查找这个节点是不是有依赖 */ const app = this.getAncestor('App'); const naslServer = app.naslServer; const node = this; const refsList = await naslServer._isHaveRef(node); const handleComposeDel = async () => { // case1: 删除流程审批页面时,需要删除流程节点绑定的该页面的跳转 await this.delProcessViewDestination(); // case2: 删除页面或端的时候,如果存在组合节点,需要同步删除封装态分组内容 const excludedKeySet = new Set([ 'parentNode', 'sourceMap', 'storageJSON', 'tsErrorDetail', 'NaslAnnotatedJSON', 'calledFrom', '_events', '_collectingList', '_historyList', ]); (0, utils_1.traverse)((current) => { const currentNode = current.node; if (currentNode && currentNode?.concept === 'ViewElement' && currentNode?.composedBy?.length) { currentNode.app.deleteCompose(currentNode.composedBy); } }, { node: this }, { mode: 'anyObject', excludedKeySet }); }; // delete的弹框展示 const confirmParms = { actionType: 'delete', tipFlag: false, node, icon: 'warning', }; let callback = null; if (refsList.length <= 1 || (node instanceof nasl_concepts_1.Param && node.parentNode instanceof nasl_concepts_1.Logic && refsList.length <= 2)) { // 平台类型直接删除然后return if (node instanceof nasl_concepts_1.ViewElement) { this.delete(); return; } callback = async () => { if (node instanceof nasl_concepts_1.EntityProperty) { const app = this.rootNode; // 收集修改 app.emit('collect:start', { actionMsg: '删除实体属性', }); this.delete(); (0, exports.dealWithEntityPropertyWithProcessBindV2)(node); // 结束修改 ,批量操作 app.emit('collect:end'); return; } // 外部接口删除时,只需要删除自己,不需要删除数据结构 if (node instanceof nasl_concepts_1.Interface && node.parentNode.concept === 'App') { this.delete(); return; } // Structure 和 Interface是内部有delete方法 if (node instanceof nasl_concepts_1.Interface || node instanceof nasl_concepts_1.MetadataType) { this.deleteLogincAndModule(); } else if (node instanceof nasl_concepts_1.Structure) { this.app.emit('collect:start', { actionMsg: `删除数据结构`, }); this.deleteLogincAndModule(); if (node.directory) { updateDirectoryDefinitions(node, node.directory); } this.app.emit('collect:end'); } else if (node instanceof nasl_concepts_1.Connection) { delConnection(node); if (cb) { cb(); } } else if (node instanceof nasl_concepts_1.View || node instanceof nasl_concepts_1.Frontend) { this.app.emit('collect:start', { actionMsg: `删除节点`, }); await handleComposeDel(); this.delete(); this.app.emit('collect:end'); } else if ((0, asserts_1.isSubLogic)(node)) { this.app.emit('collect:start', { actionMsg: `删除子逻辑`, }); (this?.parentNode).resetExpression(); this.app.emit('collect:end'); } else if (node instanceof nasl_concepts_1.Logic && this?.processV2) { this.app.emit('collect:start', { actionMsg: `删除逻辑`, }); this.delete(); if (this.parentNode.logics?.length === 0) { this.parentNode.delete(); } this.app.emit('collect:end'); } else if (node instanceof nasl_concepts_1.Entity || node instanceof nasl_concepts_1.Enum || node instanceof nasl_concepts_1.Logic) { this.app.emit('collect:start', { actionMsg: `删除${node.constructor?.nodeTitle}`, }); this.delete(); if (node.directory) { updateDirectoryDefinitions(node, node.directory); } this.app.emit('collect:end'); } else { this.delete(); } }; } else { // 如果有依赖就有一个查找引用提示 confirmParms.tipFlag = true; const node = this; if (node instanceof nasl_concepts_1.EntityProperty) { const effectiveRefs = refsList.filter(({ node: recordNode }) => { return !(recordNode instanceof nasl_concepts_1.FieldPermissionV2) && recordNode !== node; }); if (!effectiveRefs.length) { confirmParms.tipFlag = false; } } // 删除页面或者流程 if (node instanceof nasl_concepts_1.View || node instanceof nasl_concepts_1.Process || node instanceof nasl_concepts_1.Frontend) { /** * 查找这个页面是不是有依赖 */ let viewPath = this.getEmbeddedFilePath(); viewPath = viewPath.slice(0, viewPath.length - 3); const find = refsList.find((record) => !record.file.includes(viewPath)); // 如果没有别的文件的依赖,就直接delete if (!find) { if (node instanceof nasl_concepts_1.Process) { const App = this.rootNode; App.emit('collect:start', { actionMsg: `删除流程${node.name}`, }); await Promise.all(node.elements.map((ele) => ele.isUserTask && ele.cancelBindDelete(true))); this.delete(); App.emit('collect:end'); } else { if (node instanceof nasl_concepts_1.View || node instanceof nasl_concepts_1.Frontend) await handleComposeDel(); this.delete(); if (node instanceof nasl_concepts_1.Frontend) { return; } } return; } else { if (node instanceof nasl_concepts_1.Frontend) { let viewPath = this.getEmbeddedFilePath(); viewPath = viewPath.slice(0, viewPath.length - 3); const refsTempList = refsList.filter((record) => !record.file.includes(viewPath)); // 删除流程节点绑定的该端的页面跳转 const result = refsTempList .map(({ node }) => { if (node?.parentNode?.parentNode?.concept === 'ProcessElement') { return node.parentNode; } }); const App = this.rootNode; App.emit('collect:start', { actionMsg: `删除端${node.name}`, }); await Promise.all(result.map((ele) => ele.delete())); await handleComposeDel(); this.delete(); App.emit('collect:end'); return; } } } callback = async () => { // removeParam // 跟rename 还不太一样,部分修改依赖修改好的值,然后在下面的修改需要把自己传递进去 if (node instanceof nasl_concepts_1.Param) { const App = this.rootNode; const parentNode = this.parentNode; // 收集修改 App.emit('collect:start', { actionMsg: '删除参数', }); const Index = node.getIndexOfParent(); this.delete(); refsList.forEach(({ node }) => { /** * 调用方是 调用逻辑或者跳转页面, 去删除对应位置的内容 * 如果是跳转页面,因为流程下的特殊翻译,需要过滤下 非页面下的参数修改,查找到页面跳转 */ if (node instanceof nasl_concepts_1.CallLogic || (node.parentNode instanceof nasl_concepts_1.View && node instanceof nasl_concepts_1.Destination) || node instanceof nasl_concepts_1.CallAuthInterface) { node.deleteCalleeArg(Index); } }); // 结束修改 ,批量操作 App.emit('collect:end'); return; } // 删除logic节点,如果有对应的interface要一起删除 if (node instanceof nasl_concepts_1.Logic) { const App = this.rootNode; // 收集修改 App.emit('collect:start', { actionMsg: '删除逻辑并删除导出的接口', }); this.delete(); if (node.directory) { updateDirectoryDefinitions(node, node.directory); } refsList.forEach(({ node }) => { if (node instanceof nasl_concepts_1.Interface) { node.delete(); } }); // 结束修改 ,批量操作 App.emit('collect:end'); return; } // 删除权限节点 if (node instanceof nasl_concepts_1.Role) { const App = this.rootNode; // 收集修改 App.emit('collect:start', { actionMsg: '删除权限', }); this.delete(); refsList.forEach(({ node }) => { if (node instanceof nasl_concepts_1.View || node instanceof nasl_concepts_1.ViewElement) { // oldName旧的节点存的值 // newValue用户输入值 // node.bindRoles 存的 const str = node.bindRoles.toString().replace(this.name, ''); const newBindRoles = str.split(',').filter((item) => !!item); node.setBindRoles(newBindRoles); } }); // 结束修改 ,批量操作 App.emit('collect:end'); return; } // 允许删除的实体说明在启用/历史流程中没有用到 if (node instanceof nasl_concepts_1.Entity) { const app = this.rootNode; // 收集修改 app.emit('collect:start', { actionMsg: '解除流程关联实体', }); this.delete(); const entityNamespace = node.getNamespace(); const entityName = node.name; app?.processV2s?.forEach((processV2) => { const { properties } = processV2?.bind?.typeAnnotation || {}; properties?.forEach((property) => { const { typeArguments } = property?.typeAnnotation || {}; if (typeArguments?.length === 1) { const { typeNamespace, typeName } = typeArguments[0]; if (typeNamespace === entityNamespace && typeName === entityName) { property.delete(); } } }); }); if (node.directory) { updateDirectoryDefinitions(node, node.directory); } // 收集修改 app.emit('collect:end'); return; } if (node instanceof nasl_concepts_1.EntityProperty) { const app = this.rootNode; // 收集修改 app.emit('collect:start', { actionMsg: '删除实体属性', }); this.delete(); refsList.forEach(({ node }) => { // 删除实体字段的时候需要删除流程任务中的实体字段权限 if (node instanceof nasl_concepts_1.FieldPermissionV2) { node.delete(); } }); (0, exports.dealWithEntityPropertyWithProcessBindV2)(node); // 结束修改 ,批量操作 app.emit('collect:end'); return; } // 删除页面或者流程,如果上一步没有return 就说明他是有别的引用的,会有引用弹框 if (node instanceof nasl_concepts_1.View) { this.app.emit('collect:start', { actionMsg: `删除节点`, }); await handleComposeDel(); this.delete(); this.app.emit('collect:end'); } if (node instanceof nasl_concepts_1.Process) { const App = this.rootNode; App.emit('collect:start', { actionMsg: `删除流程${node.name}`, }); await Promise.all(node.elements.map((ele) => ele.isUserTask && ele.cancelBindDelete(true))); this.delete(); App.emit('collect:end'); } // 外部接口删除时,只需要删除自己,不需要删除数据结构 if (node instanceof nasl_concepts_1.Interface && node.parentNode.concept === 'App') { this.delete(); return; } if (node instanceof nasl_concepts_1.Connection) { delConnection(node); if (cb) { cb(); } return; } // 其余的都直接调用删除 // Structure 和 Interface是内部有delete方法 if (node instanceof nasl_concepts_1.Interface) { this.deleteLogincAndModule(); } else if (node instanceof nasl_concepts_1.Structure) { this.app.emit('collect:start', { actionMsg: `删除数据结构`, }); this.deleteLogincAndModule(); if (node.directory) { updateDirectoryDefinitions(node, node.directory); } this.app.emit('collect:end'); } else if (node instanceof nasl_concepts_1.Enum) { this.app.emit('collect:start', { actionMsg: `删除枚举`, }); this.delete(); if (node.directory) { updateDirectoryDefinitions(node, node.directory); } this.app.emit('collect:end'); } else { this.delete(); } }; } (0, common_1.invokeCommand)('tsConfirm.open', confirmParms, callback); } catch (err) { console.log(err); } }; /** * 如果添加需要触发查找引用并且在之后,对内容产生影响 */ nasl_concepts_1.BaseNode.prototype.addParamsPrepare = async function addParamsPrepare(needAdd = true) { try { /** * 查找这个节点是不是有依赖 */ const app = this.getAncestor('App'); const naslServer = app.naslServer; const refsList = await naslServer._isHaveRef(this); console.log('------------addParamsPrepare------------', refsList, needAdd); return naslServer._addParamsPrepare(this, refsList, needAdd); } catch (err) { console.log(err); } }; /** * 在原型上增加方法来调用 */ nasl_concepts_1.BaseNode.prototype.getCurrentTypeAnnotation = async function getCurrentTypeAnnotation(outTime) { try { /** * 查找这个节点是不是有依赖 */ const app = this.getAncestor('App'); const naslServer = app.naslServer; return naslServer.getCurrentTypeAnnotation((0, vue_1.toRaw)(this)); } catch (err) { console.log(err); } }; function newNode(node, parentNode, needNewStructure) { if (needNewStructure && node?.toJSON) { return nasl_concepts_1.BaseNode.from(node.toJSON(), parentNode, ''); } return node; } function findStructInConnectorByName(name, connector) { return connector?.structures?.find((struct) => struct.name === name); } /** * 获取下一级变量 */ nasl_concepts_1.BaseNode.prototype.getSelectRef = function getSelectRef(newTypeAnnotation, needNewStructure = false) { try { const typeAnnotation = newTypeAnnotation || this.typeAnnotation || this.__TypeAnnotation; const { typeName, typeKind, typeNamespace, typeArguments, properties: typeProperties } = typeAnnotation; const parentNode = this; let completionChildren; // 连接器需要区分 编辑态和稳定态 const connector = this.getAncestor('Connector'); const isInConnector = !!connector; const isInIntegration = !!this.getAncestor('Integration'); const isInEditableConnector = isInConnector && isInIntegration; if (typeKind === 'reference') { if (typeNamespace === 'nasl.ui' || typeNamespace === 'nasl.process' || typeNamespace === 'nasl.auth' || typeNamespace === 'nasl.http') { const node = newNode((0, service_1.getNaslNodeByNodeCallee)(typeNamespace, typeName), parentNode, needNewStructure); const properties = node?.properties || []; completionChildren = properties; } else if (typeNamespace.endsWith('.enums')) { completionChildren = []; } else { let app; if (this.concept === 'App') { app = this; } else { app = this.rootNode || typeAnnotation.app; } let node; if (isInEditableConnector) { const target = findStructInConnectorByName(typeName, connector); node = newNode(target, parentNode, needNewStructure); } else { node = newNode((0, service_1.getNodeByNodeCallee)(app, typeNamespace + '.' + typeName), parentNode, needNewStructure); } const properties = node?.properties || []; completionChildren = properties; } } else if (typeKind === 'generic') { const node = newNode((0, service_1.getNaslNodeByNodeCallee)(typeNamespace, typeName), parentNode, needNewStructure); const properties = (node?.properties && [...node?.properties]) || []; for (let i = 0; i < properties.length; i++) { const item = properties[i]; if (item?.typeAnnotation?.typeKind === 'typeParam') { if (item.name === 'columnItem' && typeArguments[1]) { item.typeAnnotation = nasl_concepts_1.TypeAnnotation.from(typeArguments[1].toJSON(), node, 'typeAnnotation'); } else if (typeArguments[0]) { item.typeAnnotation = nasl_concepts_1.TypeAnnotation.from(typeArguments[0].toJSON(), node, 'typeAnnotation'); } properties[i]; } } completionChildren = properties; } else if (typeNamespace === 'nasl.core' && ['String', 'Text', 'Email'].includes(typeName)) { const node = newNode((0, service_1.getNaslNodeByNodeCallee)(typeNamespace, typeName), parentNode, needNewStructure); const properties = (node?.properties && [...node?.properties]) || []; completionChildren = properties; } else if (typeKind === 'anonymousStructure' && typeProperties?.length) { const node = newNode(typeAnnotation, parentNode, needNewStructure); const properties = (node?.properties && [...node?.properties]) || []; completionChildren = properties; } return completionChildren; } catch (err) { console.log(err); } }; (0, nasl_sentry_1.extendSentryMonitorNaslNode)(nasl_concepts_1.BaseNode); /** * Update directory definitions after node deletion */ function updateDirectoryDefinitions(node, directory) { const completeName = node.completeName; const definitions = directory.definitions.filter((item) => item.completeName === completeName); definitions.forEach((def) => { def.delete(); }); } //# sourceMappingURL=extendBaseNode.js.map