UNPKG

@lcap/nasl

Version:

NetEase Application Specific Language

68 lines 2.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.setChangedTimeForInstruct = exports.splitInstructList = void 0; const uuid_1 = require("uuid"); const createId = () => (0, uuid_1.v4)().replace(/-/g, ''); /** * 将指令列表拆分成每个指令最多200条指令的数组 * * @description 因为服务端(孙浩然),单个actions太多,会导致服务端处理超时,事务超时。 * 所以在这里把请求拆开,然后存储一下原来的 uuid,然后再请求的时候给一个新的uuid,表示事务不一样 */ function splitInstructList(instructList) { if (!Array.isArray(instructList)) { return instructList; } const transformedArr = []; instructList.forEach((item) => { let tempActions = [...item.actions]; if (tempActions.length > 200) { const { uuid: oldUUid, riskList } = item; while (tempActions.length > 200) { transformedArr.push({ oldUUid, uuid: createId(), actions: tempActions.splice(0, 200), riskList }); } transformedArr.push({ oldUUid, uuid: createId(), actions: tempActions, riskList }); } else { transformedArr.push(item); } }); return transformedArr; } exports.splitInstructList = splitInstructList; /** * 设置节点的修改时间 * * @description 创建节点时需要加上时间,删除节点时需要给上级节点加上时间 */ function setChangedTimeForInstruct(instructList) { const now = Date.now(); for (const instruct of instructList) { for (let i = 0; i < instruct.actions.length; i++) { const action = instruct.actions[i]; if (action.action === 'delete') { const pathArr = action.path.split(/\.(?![^\[]*\])/); const parentNodePath = pathArr.slice(0, pathArr.length - 1).join('.'); instruct.actions.splice(i + 1, 0, { action: 'update', path: parentNodePath, object: { changedTime: now, }, }); i++; } else if (action.action === 'create') { action.object.changedTime = now; } else if (action.action === 'update') { if (!Array.isArray(action.object)) { action.object.changedTime = now; } } } } return instructList.slice(); } exports.setChangedTimeForInstruct = setChangedTimeForInstruct; //# sourceMappingURL=utils.js.map