@lcap/nasl 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/automate/engine/utils.js +16 -0
- package/out/automate/engine/utils.js.map +1 -1
- package/out/common/BaseNode.d.ts +1 -1
- package/out/common/BaseNode.js +13 -3
- package/out/common/BaseNode.js.map +1 -1
- package/out/concepts/App__.d.ts +1 -0
- package/out/concepts/App__.js +4 -1
- package/out/concepts/App__.js.map +1 -1
- package/out/concepts/Assignee__.d.ts +11 -0
- package/out/concepts/Assignee__.js +34 -0
- package/out/concepts/Assignee__.js.map +1 -1
- package/out/concepts/CallFunction__.js +1 -2
- package/out/concepts/CallFunction__.js.map +1 -1
- package/out/concepts/CallQueryComponent__.d.ts +31 -2
- package/out/concepts/CallQueryComponent__.js +286 -51
- package/out/concepts/CallQueryComponent__.js.map +1 -1
- package/out/concepts/Constant__.js +6 -6
- package/out/concepts/Constant__.js.map +1 -1
- package/out/concepts/Destination__.js +18 -4
- package/out/concepts/Destination__.js.map +1 -1
- package/out/concepts/EntityIndex__.js +4 -2
- package/out/concepts/EntityIndex__.js.map +1 -1
- package/out/concepts/EntityProperty__.js +3 -5
- package/out/concepts/EntityProperty__.js.map +1 -1
- package/out/concepts/Entity__.d.ts +1 -0
- package/out/concepts/Entity__.js +7 -1
- package/out/concepts/Entity__.js.map +1 -1
- package/out/concepts/Enum__.d.ts +1 -0
- package/out/concepts/Enum__.js +6 -2
- package/out/concepts/Enum__.js.map +1 -1
- package/out/concepts/Identifier__.js +1 -1
- package/out/concepts/Identifier__.js.map +1 -1
- package/out/concepts/InterfaceParam__.js +9 -4
- package/out/concepts/InterfaceParam__.js.map +1 -1
- package/out/concepts/Param__.d.ts +1 -1
- package/out/concepts/Param__.js +14 -7
- package/out/concepts/Param__.js.map +1 -1
- package/out/concepts/ProcessElement__.js +8 -2
- package/out/concepts/ProcessElement__.js.map +1 -1
- package/out/concepts/QueryAggregateExpression__.js +1 -1
- package/out/concepts/QueryAggregateExpression__.js.map +1 -1
- package/out/concepts/QueryFieldExpression__.d.ts +1 -0
- package/out/concepts/QueryFieldExpression__.js +3 -0
- package/out/concepts/QueryFieldExpression__.js.map +1 -1
- package/out/concepts/QueryGroupByExpression__.d.ts +3 -0
- package/out/concepts/QueryGroupByExpression__.js +20 -0
- package/out/concepts/QueryGroupByExpression__.js.map +1 -1
- package/out/concepts/Return__.d.ts +1 -1
- package/out/concepts/Return__.js +15 -10
- package/out/concepts/Return__.js.map +1 -1
- package/out/concepts/StringLiteral__.js +1 -8
- package/out/concepts/StringLiteral__.js.map +1 -1
- package/out/concepts/StructureProperty__.js +5 -5
- package/out/concepts/StructureProperty__.js.map +1 -1
- package/out/concepts/TypeAnnotation__.js +12 -4
- package/out/concepts/TypeAnnotation__.js.map +1 -1
- package/out/concepts/Variable__.d.ts +1 -1
- package/out/concepts/Variable__.js +15 -10
- package/out/concepts/Variable__.js.map +1 -1
- package/out/concepts/ViewElement__.js +1 -1
- package/out/concepts/ViewElement__.js.map +1 -1
- package/out/concepts/View__.d.ts +1 -1
- package/out/concepts/View__.js +15 -4
- package/out/concepts/View__.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.configuration.js +1 -1
- package/out/concepts/basics/stdlib/nasl.configuration.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.interface.d.ts +2 -0
- package/out/concepts/basics/stdlib/nasl.interface.js +4 -4
- package/out/concepts/basics/stdlib/nasl.interface.js.map +1 -1
- package/out/concepts/basics/stdlib/nasl.util.js +21 -37
- package/out/concepts/basics/stdlib/nasl.util.js.map +1 -1
- package/out/concepts/basics/stdlib/reference2TypeAnnotationList.js +1 -1
- package/out/concepts/basics/stdlib/reference2TypeAnnotationList.js.map +1 -1
- package/out/concepts/basics/types/index.d.ts +1 -0
- package/out/concepts/basics/types/index.js +3 -1
- package/out/concepts/basics/types/index.js.map +1 -1
- package/out/enums/KEYWORDS.js +0 -7
- package/out/enums/KEYWORDS.js.map +1 -1
- package/out/manager/diagnostic.d.ts +1 -1
- package/out/{test/integration/connect-file copy.d.ts → server/extendBaseNode.d.ts} +0 -0
- package/out/server/extendBaseNode.js +323 -0
- package/out/server/extendBaseNode.js.map +1 -0
- package/out/server/getLogics.js +22 -1
- package/out/server/getLogics.js.map +1 -1
- package/out/server/getMemberIdentifier.js +47 -2
- package/out/server/getMemberIdentifier.js.map +1 -1
- package/out/server/getProcesses.d.ts +4 -2
- package/out/server/getProcesses.js +160 -20
- package/out/server/getProcesses.js.map +1 -1
- package/out/server/getScope.d.ts +1 -0
- package/out/server/getScope.js +4 -0
- package/out/server/getScope.js.map +1 -1
- package/out/server/index.d.ts +1 -0
- package/out/server/index.js +1 -0
- package/out/server/index.js.map +1 -1
- package/out/server/naslServer.d.ts +7 -5
- package/out/server/naslServer.js +96 -362
- package/out/server/naslServer.js.map +1 -1
- package/out/server/translator.d.ts +1 -1
- package/out/server/translator.js +3 -1
- package/out/server/translator.js.map +1 -1
- package/out/service/storage/init.js +18 -10
- package/out/service/storage/init.js.map +1 -1
- package/out/templator/genGetBlock.js +1 -1
- package/out/templator/genGetBlock.js.map +1 -1
- package/out/templator/genQueryComponent.js +7 -4
- package/out/templator/genQueryComponent.js.map +1 -1
- package/out/templator/genSelectBlock.js +5 -15
- package/out/templator/genSelectBlock.js.map +1 -1
- package/out/templator/genUpdateBlock.js +1 -1
- package/out/templator/genUpdateBlock.js.map +1 -1
- package/out/templator/utils.d.ts +3 -1
- package/out/templator/utils.js +2 -1
- package/out/templator/utils.js.map +1 -1
- package/package.json +1 -2
- package/src/automate/engine/utils.js +16 -2
- package/src/common/BaseNode.ts +14 -3
- package/src/concepts/App__.ts +6 -39
- package/src/concepts/Assignee__.ts +30 -0
- package/src/concepts/CallFunction__.ts +1 -2
- package/src/concepts/CallQueryComponent__.ts +294 -54
- package/src/concepts/Constant__.ts +6 -6
- package/src/concepts/Destination__.ts +18 -20
- package/src/concepts/EntityIndex__.ts +4 -2
- package/src/concepts/EntityProperty__.ts +3 -5
- package/src/concepts/Entity__.ts +15 -3
- package/src/concepts/Enum__.ts +7 -15
- package/src/concepts/Identifier__.ts +1 -10
- package/src/concepts/InterfaceParam__.ts +9 -4
- package/src/concepts/Param__.ts +14 -7
- package/src/concepts/ProcessElement__.ts +9 -3
- package/src/concepts/QueryAggregateExpression__.ts +1 -1
- package/src/concepts/QueryFieldExpression__.ts +4 -0
- package/src/concepts/QueryGroupByExpression__.ts +23 -0
- package/src/concepts/Return__.ts +15 -10
- package/src/concepts/StringLiteral__.ts +1 -8
- package/src/concepts/StructureProperty__.ts +5 -5
- package/src/concepts/TypeAnnotation__.ts +12 -4
- package/src/concepts/Variable__.ts +15 -10
- package/src/concepts/ViewElement__.ts +2 -2
- package/src/concepts/View__.ts +16 -4
- package/src/concepts/basics/stdlib/nasl.configuration.ts +1 -1
- package/src/concepts/basics/stdlib/nasl.interface.ts +1 -1
- package/src/concepts/basics/stdlib/nasl.util.ts +21 -37
- package/src/concepts/basics/stdlib/reference2TypeAnnotationList.ts +1 -1
- package/src/concepts/basics/types/index.ts +1 -0
- package/src/enums/KEYWORDS.ts +0 -7
- package/src/manager/diagnostic.ts +1 -1
- package/src/server/extendBaseNode.ts +318 -0
- package/src/server/getLogics.ts +22 -1
- package/src/server/getMemberIdentifier.ts +49 -2
- package/src/server/getProcesses.ts +170 -21
- package/src/server/getScope.ts +5 -0
- package/src/server/index.ts +1 -0
- package/src/server/naslServer.ts +100 -355
- package/src/server/translator.ts +3 -1
- package/src/service/storage/init.ts +18 -11
- package/src/templator/genGetBlock.ts +1 -1
- package/src/templator/genQueryComponent.ts +7 -4
- package/src/templator/genSelectBlock.ts +5 -15
- package/src/templator/genUpdateBlock.ts +1 -1
- package/src/templator/utils.ts +3 -0
- package/out/concepts/basics/stdlib/nasl.browser copy.d.ts +0 -3
- package/out/concepts/basics/stdlib/nasl.browser copy.js +0 -70
- package/out/concepts/basics/stdlib/nasl.browser copy.js.map +0 -1
- package/out/terms/LEVEL_NAME_MAP.d.ts +0 -26
- package/out/terms/LEVEL_NAME_MAP.js +0 -30
- package/out/terms/LEVEL_NAME_MAP.js.map +0 -1
- package/out/test/integration/connect-file copy.js +0 -50
- package/out/test/integration/connect-file copy.js.map +0 -1
- package/out/test/integration/node-nasl-server.d.ts +0 -1
- package/out/test/integration/node-nasl-server.js +0 -41
- package/out/test/integration/node-nasl-server.js.map +0 -1
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import naslServer, { FileNode } from './naslServer';
|
|
2
|
+
import * as tsProtocol from 'typescript/lib/protocol';
|
|
3
|
+
import { MinRange } from './translator';
|
|
4
|
+
import { BaseNode, CallLogic, Destination, EnumItem, Interface, Logic, Param, Process, Role, Structure, View, ViewElement } from '../concepts';
|
|
5
|
+
import { EventPayload, invokeCommand, registerCommand } from '../common';
|
|
6
|
+
|
|
7
|
+
interface SetNameNode extends BaseNode {
|
|
8
|
+
setName(name: string): any;
|
|
9
|
+
[propname: string]: any;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
BaseNode.prototype.findReadOnlyLogicUsage = function () {
|
|
13
|
+
let targetNode;
|
|
14
|
+
|
|
15
|
+
if (this.parentNode.concept === 'Namespace' || this.parentNode.parentNode.concept === 'Namespace') {
|
|
16
|
+
const sourceMap = this.parentNode.concept === 'Namespace' ? this.parentNode.parentNode.sourceMap : this.parentNode.parentNode.parentNode.sourceMap;
|
|
17
|
+
for (const item of sourceMap) {
|
|
18
|
+
const logic = item[0] as Logic;
|
|
19
|
+
if (this.concept === 'Logic') {
|
|
20
|
+
if (logic instanceof Logic)
|
|
21
|
+
if (logic.calleewholeKey === (this as Logic).calleewholeKey) {
|
|
22
|
+
targetNode = logic;
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
} else {
|
|
26
|
+
if (logic instanceof Logic)
|
|
27
|
+
if (logic.calleewholeKey === (this.parentNode as Logic).calleewholeKey) {
|
|
28
|
+
targetNode = logic;
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
} else if (this.parentNode.concept === 'Module') {
|
|
34
|
+
// 父级是模块的还是用它本身去查找引用
|
|
35
|
+
targetNode = this;
|
|
36
|
+
} else {
|
|
37
|
+
const sourceMap = this.parentNode.sourceMap;
|
|
38
|
+
for (const item of sourceMap) {
|
|
39
|
+
const logic = item[0] as Logic;
|
|
40
|
+
if (logic.getNamespace && logic.getNamespace() === (this as Logic).getNamespace()) {
|
|
41
|
+
targetNode = logic;
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
return naslServer.findReferences(targetNode);
|
|
49
|
+
} catch (err) {
|
|
50
|
+
console.log(err);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
// 查找引用
|
|
54
|
+
BaseNode.prototype.findUsage = function findUsage() {
|
|
55
|
+
try {
|
|
56
|
+
return naslServer.findReferences(this);
|
|
57
|
+
} catch (err) {
|
|
58
|
+
console.log(err);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
BaseNode.prototype.changeName = async function changeName(newValue: string, updateAll: boolean = false) {
|
|
62
|
+
console.log(newValue);
|
|
63
|
+
console.log(this);
|
|
64
|
+
try {
|
|
65
|
+
/**
|
|
66
|
+
* 查找这个节点是不是有依赖
|
|
67
|
+
*/
|
|
68
|
+
const refsList = await naslServer._isHaveRef(this);
|
|
69
|
+
// 是不是有引用有的话,就返回
|
|
70
|
+
/**
|
|
71
|
+
* @param this 当前重命名的节点
|
|
72
|
+
* @param newValue 传递过来的新值,给MemberExpression用的比较特殊
|
|
73
|
+
* 而且,这个新值不一定会用到,MemberExpression在批量更新的时候,可以取到新的value, 这里需要位置信息防止 a.a.a.a 中的一个a发生修改
|
|
74
|
+
* @returns 找到的引用
|
|
75
|
+
*/
|
|
76
|
+
const res = naslServer._renamePrepare(this, refsList, newValue);
|
|
77
|
+
if (res.length <= 1) {
|
|
78
|
+
(this as SetNameNode).setName(newValue);
|
|
79
|
+
} else {
|
|
80
|
+
const callback = (value: boolean) => {
|
|
81
|
+
if (value) {
|
|
82
|
+
const App = this.rootNode;
|
|
83
|
+
// 收集修改
|
|
84
|
+
App.emit('collect:start', {
|
|
85
|
+
actionMsg: '重命名并更新引用',
|
|
86
|
+
});
|
|
87
|
+
res.forEach((item) => {
|
|
88
|
+
const itemNode = item.node as SetNameNode;
|
|
89
|
+
if (item.newValue) {
|
|
90
|
+
// 如果有指定的修改方法,就用那个,没有就修改名字
|
|
91
|
+
item.setTypeMethods ? itemNode[item.setTypeMethods](item.newValue) : itemNode.setName?.(item.newValue);
|
|
92
|
+
} else {
|
|
93
|
+
item.setTypeMethods ? itemNode[item.setTypeMethods](newValue) : itemNode.setName?.(newValue);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
// 结束修改 ,批量操作
|
|
97
|
+
App.emit('collect:end');
|
|
98
|
+
} else {
|
|
99
|
+
(this as SetNameNode).setName(newValue);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
const confirmParms = {
|
|
103
|
+
actionType: 'rename',
|
|
104
|
+
node: this,
|
|
105
|
+
newValue,
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* nasl和vue的通信,回退,要触发vue的watch。
|
|
109
|
+
* 因为如果没修改的话nasl不会修改view,就不会通知到页面改成旧值
|
|
110
|
+
* 先修改之
|
|
111
|
+
*/
|
|
112
|
+
const closeCallBack = () => {
|
|
113
|
+
if (this.concept === 'EnumItem') {
|
|
114
|
+
const oldValue = (this as EnumItem).value;
|
|
115
|
+
(this as EnumItem).value = oldValue + ' ';
|
|
116
|
+
setTimeout(() => {
|
|
117
|
+
(this as EnumItem).value = oldValue;
|
|
118
|
+
}, 0);
|
|
119
|
+
} else {
|
|
120
|
+
const oldValue = this.name;
|
|
121
|
+
this.name = oldValue + ' ';
|
|
122
|
+
setTimeout(() => {
|
|
123
|
+
this.name = oldValue;
|
|
124
|
+
}, 0);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
updateAll ? callback(true) : invokeCommand('tsConfirm.open', confirmParms, callback, closeCallBack);
|
|
128
|
+
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
} catch (err) {
|
|
132
|
+
console.log(err);
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* 准备删除
|
|
138
|
+
*/
|
|
139
|
+
BaseNode.prototype.prepareDelete = async function prepareDelete() {
|
|
140
|
+
try {
|
|
141
|
+
/**
|
|
142
|
+
* 查找这个节点是不是有依赖
|
|
143
|
+
*/
|
|
144
|
+
const node = this;
|
|
145
|
+
let refsList = await naslServer._isHaveRef(node);
|
|
146
|
+
// 删除的时候过滤一把组件删除提示
|
|
147
|
+
refsList = refsList.filter((item) =>
|
|
148
|
+
// 因为ui组件本身会多渲染一次,就先过滤一个
|
|
149
|
+
!(item.lineText.includes(': nasl.ui.')));
|
|
150
|
+
// 删除参数单独处理
|
|
151
|
+
if (node instanceof Param) {
|
|
152
|
+
const methodRefs: tsProtocol.ReferencesResponseItem[] = [];
|
|
153
|
+
refsList.forEach((item) => {
|
|
154
|
+
// 入参查找引用,查到logic 和自己,内容完全一样,就保留一个
|
|
155
|
+
const find = methodRefs.find((findItem) => item.lineText === findItem.lineText);
|
|
156
|
+
// 而且内容不是跳转链接,跳转链接多个可能会完全一样
|
|
157
|
+
if (!find || find?.lineText?.includes('.$destination')) {
|
|
158
|
+
methodRefs.push(item);
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
refsList = methodRefs;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// delete的弹框展示
|
|
165
|
+
const confirmParms = {
|
|
166
|
+
actionType: 'delete',
|
|
167
|
+
tipFlag: false,
|
|
168
|
+
node,
|
|
169
|
+
icon: 'warning',
|
|
170
|
+
};
|
|
171
|
+
let callback = null;
|
|
172
|
+
if (refsList.length <= 1) {
|
|
173
|
+
// 页面组件直接删除然后return
|
|
174
|
+
if (node instanceof ViewElement) {
|
|
175
|
+
this.delete();
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
callback = () => {
|
|
179
|
+
// Structure 和 Interface是内部有delete方法
|
|
180
|
+
if (node instanceof Structure || node instanceof Interface) {
|
|
181
|
+
(this as any).deleteLogincAndModule();
|
|
182
|
+
} else {
|
|
183
|
+
this.delete();
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
} else {
|
|
187
|
+
// 如果有依赖就有一个查找引用提示
|
|
188
|
+
confirmParms.tipFlag = true;
|
|
189
|
+
const node = this;
|
|
190
|
+
|
|
191
|
+
// 删除页面或者流程
|
|
192
|
+
if (node instanceof View || node instanceof Process) {
|
|
193
|
+
/**
|
|
194
|
+
* 查找这个页面是不是有依赖
|
|
195
|
+
*/
|
|
196
|
+
let viewPath = (this as FileNode).getEmbeddedFilePath();
|
|
197
|
+
viewPath = viewPath.slice(0, viewPath.length - 3);
|
|
198
|
+
const find = refsList.find((record) => !record.file.includes(viewPath));
|
|
199
|
+
// 如果没有别的文件的依赖,就直接delete
|
|
200
|
+
if (!find) {
|
|
201
|
+
this.delete();
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
callback = () => {
|
|
206
|
+
// removeParam
|
|
207
|
+
// 跟rename 还不太一样,部分修改依赖修改好的值,然后在下面的修改需要把自己传递进去
|
|
208
|
+
if (node instanceof Param) {
|
|
209
|
+
const App = this.rootNode;
|
|
210
|
+
const parentNode = this.parentNode;
|
|
211
|
+
// 收集修改
|
|
212
|
+
App.emit('collect:start', {
|
|
213
|
+
actionMsg: '删除参数',
|
|
214
|
+
});
|
|
215
|
+
this.delete();
|
|
216
|
+
refsList.forEach((record) => {
|
|
217
|
+
const fileNode = naslServer.file2NodeMap.get(record.file);
|
|
218
|
+
if (!fileNode)
|
|
219
|
+
return null;
|
|
220
|
+
const minRange: MinRange = naslServer._findMinRange(record, fileNode as FileNode);
|
|
221
|
+
if (minRange) {
|
|
222
|
+
if (minRange.node instanceof CallLogic) {
|
|
223
|
+
minRange.node.setCalleeArgName(parentNode as Logic);
|
|
224
|
+
}
|
|
225
|
+
if (minRange.node instanceof Destination) {
|
|
226
|
+
minRange.node.setViewArgument(parentNode as View);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
// 结束修改 ,批量操作
|
|
231
|
+
App.emit('collect:end');
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
// 删除logic节点,如果有对应的interface要一起删除
|
|
235
|
+
if (node instanceof Logic) {
|
|
236
|
+
const App = this.rootNode;
|
|
237
|
+
// 收集修改
|
|
238
|
+
App.emit('collect:start', {
|
|
239
|
+
actionMsg: '删除逻辑并删除导出的接口',
|
|
240
|
+
});
|
|
241
|
+
this.delete();
|
|
242
|
+
refsList.forEach((record) => {
|
|
243
|
+
const fileNode = naslServer.file2NodeMap.get(record.file);
|
|
244
|
+
if (!fileNode)
|
|
245
|
+
return null;
|
|
246
|
+
const minRange: MinRange = naslServer._findMinRange(record, fileNode as FileNode);
|
|
247
|
+
if (minRange) {
|
|
248
|
+
if (minRange.node instanceof Interface) {
|
|
249
|
+
minRange.node.delete();
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
// 结束修改 ,批量操作
|
|
254
|
+
App.emit('collect:end');
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
// 删除权限节点
|
|
258
|
+
if (node instanceof Role) {
|
|
259
|
+
const App = this.rootNode;
|
|
260
|
+
// 收集修改
|
|
261
|
+
App.emit('collect:start', {
|
|
262
|
+
actionMsg: '删除权限',
|
|
263
|
+
});
|
|
264
|
+
this.delete();
|
|
265
|
+
refsList.forEach((record) => {
|
|
266
|
+
const fileNode = naslServer.file2NodeMap.get(record.file);
|
|
267
|
+
if (!fileNode)
|
|
268
|
+
return null;
|
|
269
|
+
const minRange: MinRange = naslServer._findMinRange(record, fileNode as FileNode);
|
|
270
|
+
if (minRange) {
|
|
271
|
+
if (minRange.node instanceof View || minRange.node instanceof ViewElement) {
|
|
272
|
+
// oldName旧的节点存的值
|
|
273
|
+
// newValue用户输入值
|
|
274
|
+
// node.bindRoles 存的
|
|
275
|
+
const str = minRange.node.bindRoles.toString().replace(this.name, '');
|
|
276
|
+
const newBindRoles = str.split(',').filter((item) => !!item);
|
|
277
|
+
minRange.node.setBindRoles(newBindRoles);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
// 结束修改 ,批量操作
|
|
282
|
+
App.emit('collect:end');
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// 删除页面或者流程,如果上一步没有return 就说明他是有别的引用的,会有引用弹框
|
|
287
|
+
if (node instanceof View || node instanceof Process) {
|
|
288
|
+
this.delete();
|
|
289
|
+
}
|
|
290
|
+
// 其余的都直接调用删除
|
|
291
|
+
// Structure 和 Interface是内部有delete方法
|
|
292
|
+
if (node instanceof Structure || node instanceof Interface) {
|
|
293
|
+
(this as any).deleteLogincAndModule();
|
|
294
|
+
} else {
|
|
295
|
+
this.delete();
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
invokeCommand('tsConfirm.open', confirmParms, callback);
|
|
300
|
+
} catch (err) {
|
|
301
|
+
console.log(err);
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* 如果添加需要触发查找引用并且在之后,对内容产生影响
|
|
307
|
+
*/
|
|
308
|
+
BaseNode.prototype.addParamsPrepare = async function addParamsPrepare(needAdd = true) {
|
|
309
|
+
try {
|
|
310
|
+
/**
|
|
311
|
+
* 查找这个节点是不是有依赖
|
|
312
|
+
*/
|
|
313
|
+
const refsList = await naslServer._isHaveRef(this);
|
|
314
|
+
return naslServer._addParamsPrepare(this, refsList, needAdd);
|
|
315
|
+
} catch (err) {
|
|
316
|
+
console.log(err);
|
|
317
|
+
}
|
|
318
|
+
};
|
package/src/server/getLogics.ts
CHANGED
|
@@ -102,7 +102,7 @@ export async function getLogics(node: CallLogic | BindEvent, needAllLogic: boole
|
|
|
102
102
|
if (Array.isArray(eleLogis) && eleLogis.length) {
|
|
103
103
|
const viewElement = new Namespace({
|
|
104
104
|
title: toHump(item.name),
|
|
105
|
-
logics: eleLogis.map((item: Logic) => Logic.from(item)),
|
|
105
|
+
logics: eleLogis.map((item: Logic) => Logic.from(item.toJSON())),
|
|
106
106
|
path: `elements.${toHump(item.name)}.logics`,
|
|
107
107
|
originConcept: 'ViewElement',
|
|
108
108
|
});
|
|
@@ -151,6 +151,27 @@ export async function getLogics(node: CallLogic | BindEvent, needAllLogic: boole
|
|
|
151
151
|
expanded: true,
|
|
152
152
|
});
|
|
153
153
|
|
|
154
|
+
systemTree.expanded = true;
|
|
155
|
+
systemTree.children.forEach((child) => (child.expanded = true));
|
|
156
|
+
result.push(systemTree);
|
|
157
|
+
} else {
|
|
158
|
+
// 增加全局逻辑中的系统逻辑
|
|
159
|
+
const systemTree = new Namespace({
|
|
160
|
+
name: 'category',
|
|
161
|
+
path: `nasl`,
|
|
162
|
+
title: '系统逻辑',
|
|
163
|
+
children: [
|
|
164
|
+
new Namespace({
|
|
165
|
+
name: 'category',
|
|
166
|
+
path: `configuration`,
|
|
167
|
+
title: '配置',
|
|
168
|
+
logics: stdlibNamespace.findChild('configuration').logics,
|
|
169
|
+
expanded: true,
|
|
170
|
+
})
|
|
171
|
+
],
|
|
172
|
+
expanded: true,
|
|
173
|
+
});
|
|
174
|
+
|
|
154
175
|
systemTree.expanded = true;
|
|
155
176
|
systemTree.children.forEach((child) => (child.expanded = true));
|
|
156
177
|
result.push(systemTree);
|
|
@@ -96,10 +96,49 @@ function createType2Annotation(type: string): TypeAnnotation {
|
|
|
96
96
|
}
|
|
97
97
|
return typeAnnotation;
|
|
98
98
|
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* 把要返回去的数据做一下排序
|
|
102
|
+
* @param result 要返回数据
|
|
103
|
+
* @param node 当前内容的上下级
|
|
104
|
+
* @returns 返回排序后的数组
|
|
105
|
+
* 因为ts会按照 a-z的顺序进行排序
|
|
106
|
+
* 但是影响用户体验,需要先按照页面排序,其次按照logic进行排序
|
|
107
|
+
* 流程的韬哥自己解决了,所以先解决这两部分
|
|
108
|
+
*/
|
|
109
|
+
function sortFirstVariableData(result: CompletionProperty[], node: BaseNode) {
|
|
110
|
+
const newResult: CompletionProperty[] = [];
|
|
111
|
+
const logic = (node as Param).logic;
|
|
112
|
+
const view = (node as Param).view;
|
|
113
|
+
if (view) {
|
|
114
|
+
const { params, variables } = view;
|
|
115
|
+
const list = [...params, ...variables];
|
|
116
|
+
list.forEach((item) => {
|
|
117
|
+
const findIndex = result.findIndex((findItem) => findItem.name === item.name);
|
|
118
|
+
if (findIndex === 0 || findIndex) {
|
|
119
|
+
newResult.push(result[findIndex]);
|
|
120
|
+
result.splice(findIndex, 1);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
if (logic) {
|
|
125
|
+
const { params, returns, variables } = logic;
|
|
126
|
+
const list = [...params, ...returns, ...variables];
|
|
127
|
+
list.forEach((item) => {
|
|
128
|
+
const findIndex = result.findIndex((findItem) => findItem.name === item.name);
|
|
129
|
+
if (findIndex === 0 || findIndex) {
|
|
130
|
+
newResult.push(result[findIndex]);
|
|
131
|
+
result.splice(findIndex, 1);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
newResult.push(...result);
|
|
136
|
+
return newResult;
|
|
137
|
+
}
|
|
99
138
|
// 格式化变量数据
|
|
100
139
|
export function formatVariableData(data: unknown | variableItem[], node: BaseNode, parent?: any) {
|
|
101
140
|
if (Array.isArray(data)) {
|
|
102
|
-
|
|
141
|
+
let result = data.map((item) => {
|
|
103
142
|
// value需要拼接生成
|
|
104
143
|
item.value = parent ? `${parent.value}.${item.text}` : item.text;
|
|
105
144
|
item.name = item.text;
|
|
@@ -134,6 +173,14 @@ export function formatVariableData(data: unknown | variableItem[], node: BaseNod
|
|
|
134
173
|
return completionProperty;
|
|
135
174
|
}
|
|
136
175
|
});
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* 排序result
|
|
179
|
+
* 如果没有父级就是第一集就排序一下当前result,用户体验优化
|
|
180
|
+
*/
|
|
181
|
+
if (!parent) {
|
|
182
|
+
result = sortFirstVariableData(result, node);
|
|
183
|
+
}
|
|
137
184
|
return result;
|
|
138
185
|
}
|
|
139
186
|
}
|
|
@@ -312,7 +359,7 @@ function getCurrentLogic(node: BaseNode,
|
|
|
312
359
|
icon: string;
|
|
313
360
|
}[]) {
|
|
314
361
|
// 只有data-source可以
|
|
315
|
-
if (node instanceof Identifier && node.parentNode instanceof BindAttribute && node.parentNode.name === 'data-source') {
|
|
362
|
+
if (node instanceof Identifier && node.parentNode instanceof BindAttribute && (node.parentNode.name === 'data-source' || node.parentNode.name === 'check-file')) {
|
|
316
363
|
const view = node.view;
|
|
317
364
|
const viewLogics = view.logics;
|
|
318
365
|
const logicVariable = viewLogics.map((item) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Constant from '@nasl/concepts/Constant__';
|
|
2
|
-
import { CompletionProperty, Process, ProcessElement, Namespace, Logic, TypeAnnotation, Return, Variable, StructureProperty, Param, Identifier, MemberExpression, LogicItem } from '..';
|
|
2
|
+
import { CompletionProperty, Process, ProcessElement, Namespace, Logic, TypeAnnotation, Return, Variable, StructureProperty, Param, Identifier, MemberExpression, LogicItem, App, BaseNode, Structure, Entity, EntityProperty } from '..';
|
|
3
3
|
import { getNodeByNodeCallee } from '../automate/engine/utils';
|
|
4
4
|
function alphaUpper(name: string) {
|
|
5
5
|
if (!name) {
|
|
@@ -156,16 +156,25 @@ export function syncMemberExpression(elem: ProcessElement | Process, callback: (
|
|
|
156
156
|
attr.destination.arguments.forEach((arg) => {
|
|
157
157
|
travelDown(arg.expression, (node) => {
|
|
158
158
|
if (node instanceof MemberExpression) {
|
|
159
|
-
console.log('UserTask', node.getValue());
|
|
159
|
+
// console.log('UserTask destination', node.getValue());
|
|
160
|
+
callback(node);
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
if (attr.name === 'assignee') {
|
|
166
|
+
attr.assignee.dynamicUsers.forEach((dy) => {
|
|
167
|
+
travelDown(dy, (node) => {
|
|
168
|
+
if (node instanceof MemberExpression) {
|
|
169
|
+
// console.log('UserTask assignee', node.getValue());
|
|
160
170
|
callback(node);
|
|
161
|
-
// if(node.property.name === oldName) {}
|
|
162
171
|
}
|
|
163
172
|
});
|
|
164
173
|
});
|
|
165
174
|
}
|
|
166
175
|
});
|
|
167
176
|
}
|
|
168
|
-
if (el.type === 'ExclusiveGateway') {
|
|
177
|
+
if (el.type === 'ExclusiveGateway' || el.type === 'AutoTask') {
|
|
169
178
|
travelDown(el.logic, (node) => {
|
|
170
179
|
if (node instanceof MemberExpression) {
|
|
171
180
|
console.log('ExclusiveGateway', node.getValue());
|
|
@@ -175,8 +184,38 @@ export function syncMemberExpression(elem: ProcessElement | Process, callback: (
|
|
|
175
184
|
}
|
|
176
185
|
});
|
|
177
186
|
}
|
|
187
|
+
// a.b.c => MemberExpression
|
|
188
|
+
export function genMemberExpression(path: string) {
|
|
189
|
+
const arr = path.split('.');
|
|
190
|
+
let m: MemberExpression;
|
|
191
|
+
while(arr.length) {
|
|
192
|
+
const ns = arr.shift();
|
|
193
|
+
const cv = new Identifier({ name: ns });
|
|
194
|
+
if (!m) {
|
|
195
|
+
m = new MemberExpression({
|
|
196
|
+
object: cv,
|
|
197
|
+
});
|
|
198
|
+
cv.parentNode = m;
|
|
199
|
+
} else {
|
|
200
|
+
m.property = cv;
|
|
201
|
+
if(arr.length) {
|
|
202
|
+
const tm = new MemberExpression({
|
|
203
|
+
object: m,
|
|
204
|
+
});
|
|
205
|
+
m.parentKey = 'object';
|
|
206
|
+
m.parentNode = tm;
|
|
207
|
+
cv.parentKey = 'property';
|
|
208
|
+
cv.parentNode = tm;
|
|
209
|
+
m = tm;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return m;
|
|
215
|
+
}
|
|
216
|
+
|
|
178
217
|
// ['a','b','c'] => a.b.c
|
|
179
|
-
export function genCompletionProperty(prefix: string[] = []):(v: Variable | Param | Return | Constant) => CompletionProperty {
|
|
218
|
+
export function genCompletionProperty(prefix: string[] = []):(v: Variable | Param | Return | Constant | EntityProperty| StructureProperty) => CompletionProperty {
|
|
180
219
|
return (v) => {
|
|
181
220
|
let m: MemberExpression;
|
|
182
221
|
const p = new Identifier({ name: v.name });
|
|
@@ -238,7 +277,7 @@ export function getPreviousTask(node: ProcessElement) {
|
|
|
238
277
|
if (visitedMap.has(processElem)) {
|
|
239
278
|
return;
|
|
240
279
|
}
|
|
241
|
-
if (processElem !== node && (processElem.type === 'UserTask')) {
|
|
280
|
+
if (processElem !== node && (processElem.type === 'UserTask' || processElem.type === 'AutoTask')) {
|
|
242
281
|
elements.push(processElem);
|
|
243
282
|
}
|
|
244
283
|
visitedMap.set(processElem, true);
|
|
@@ -316,21 +355,21 @@ export function getProcessVariableSuggestions(node: Logic, abandonConstant: bool
|
|
|
316
355
|
scopeVariable.icon = processElem.type;
|
|
317
356
|
processVariables.children.push(scopeVariable);
|
|
318
357
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
358
|
+
if(processElem.type === 'AutoTask') {
|
|
359
|
+
const scopeVariable = new CompletionProperty({
|
|
360
|
+
name: processElem.name,
|
|
361
|
+
value: processElem.name,
|
|
362
|
+
icon: processElem.type,
|
|
363
|
+
noFurther: true,
|
|
364
|
+
children: [
|
|
365
|
+
...processElem.variables.map(genCompletionProperty([process.name, processElem.name])),
|
|
366
|
+
...processElem.returns.map(genCompletionProperty([process.name, processElem.name])),
|
|
367
|
+
]
|
|
368
|
+
});
|
|
369
|
+
scopeVariable.isProcess = true;
|
|
370
|
+
scopeVariable.icon = processElem.type;
|
|
371
|
+
processVariables.children.push(scopeVariable);
|
|
372
|
+
}
|
|
334
373
|
return processVariables;
|
|
335
374
|
}
|
|
336
375
|
|
|
@@ -378,3 +417,113 @@ export function getProcessVaraibleSelections(node: Logic, list: VariableSuggesti
|
|
|
378
417
|
|
|
379
418
|
list.splice(varidx, 1, data);
|
|
380
419
|
}
|
|
420
|
+
|
|
421
|
+
function deduceTypeAnnotation(
|
|
422
|
+
app: App,
|
|
423
|
+
node: Variable | Param | Return | Constant | EntityProperty| StructureProperty,
|
|
424
|
+
typeA: TypeAnnotation,
|
|
425
|
+
prefix: string[],
|
|
426
|
+
records: BaseNode[],
|
|
427
|
+
) {
|
|
428
|
+
const ns = typeA.typeNamespace;
|
|
429
|
+
const name = typeA.typeName;
|
|
430
|
+
const completion = genCompletionProperty(prefix)(node)
|
|
431
|
+
if(ns.startsWith('nasl')) {
|
|
432
|
+
return completion;
|
|
433
|
+
}
|
|
434
|
+
const nsPath = `${ns}.${name}`;
|
|
435
|
+
|
|
436
|
+
const typeNode = getNodeByNodeCallee(app, nsPath);
|
|
437
|
+
if(records.includes(typeNode)){
|
|
438
|
+
return null;
|
|
439
|
+
}
|
|
440
|
+
if(typeNode) {
|
|
441
|
+
records.push(typeNode)
|
|
442
|
+
const children = typeNode.properties.map((p: EntityProperty| StructureProperty) => {
|
|
443
|
+
return deduceTypeAnnotation(app, p, p.typeAnnotation, prefix.concat([node.name]), records.slice())
|
|
444
|
+
}).filter((q: CompletionProperty | null) => !!q);
|
|
445
|
+
completion.children = children;
|
|
446
|
+
completion.expanded = true;
|
|
447
|
+
return completion;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
export function getProcessVariableSuggestionsAll(node: ProcessElement) {
|
|
452
|
+
const processElem = node;
|
|
453
|
+
const process = node.process;
|
|
454
|
+
const app = node.app;
|
|
455
|
+
const elements: ProcessElement[] = getPreviousTask(processElem);
|
|
456
|
+
const prevtasks = elements.map((us) => {
|
|
457
|
+
const cp = new CompletionProperty({
|
|
458
|
+
name: us.name,
|
|
459
|
+
value: us.name,
|
|
460
|
+
noFurther: true,
|
|
461
|
+
children: [
|
|
462
|
+
...us.returns.map(node => deduceTypeAnnotation(app, node, node.typeAnnotation, [process.name, us.name], [])),
|
|
463
|
+
...us.constants.map(node => deduceTypeAnnotation(app, node, node.typeAnnotation, [process.name, us.name], [])),
|
|
464
|
+
],
|
|
465
|
+
});
|
|
466
|
+
cp.expanded = true;
|
|
467
|
+
cp.icon = us.type;
|
|
468
|
+
cp.isProcess = true;
|
|
469
|
+
return cp;
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
const processVariables = new CompletionProperty({
|
|
473
|
+
name: process.name,
|
|
474
|
+
value: process.name,
|
|
475
|
+
noFurther: true,
|
|
476
|
+
children: [
|
|
477
|
+
...process.params.map(node => deduceTypeAnnotation(app, node, node.typeAnnotation, [process.name], [])),
|
|
478
|
+
...process.returns.map(node => deduceTypeAnnotation(app, node, node.typeAnnotation, [process.name], [])),
|
|
479
|
+
...process.constants.map(node => deduceTypeAnnotation(app, node, node.typeAnnotation, [process.name], [])),
|
|
480
|
+
...prevtasks,
|
|
481
|
+
],
|
|
482
|
+
});
|
|
483
|
+
processVariables.expanded = true;
|
|
484
|
+
processVariables.icon = 'Process';
|
|
485
|
+
if (processElem.type === 'ExclusiveGateway') {
|
|
486
|
+
const scopeVariable = new CompletionProperty({
|
|
487
|
+
name: processElem.name,
|
|
488
|
+
value: processElem.name,
|
|
489
|
+
icon: processElem.type,
|
|
490
|
+
noFurther: true,
|
|
491
|
+
children: processElem.variables.map(node => deduceTypeAnnotation(app, node, node.typeAnnotation, [process.name, processElem.name], [])),
|
|
492
|
+
});
|
|
493
|
+
scopeVariable.expanded = true;
|
|
494
|
+
scopeVariable.isProcess = true;
|
|
495
|
+
scopeVariable.icon = processElem.type;
|
|
496
|
+
processVariables.children.push(scopeVariable);
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
if (processElem.type === 'UserTask') {
|
|
500
|
+
const scopeVariable = new CompletionProperty({
|
|
501
|
+
name: processElem.name,
|
|
502
|
+
value: processElem.name,
|
|
503
|
+
icon: processElem.type,
|
|
504
|
+
noFurther: true,
|
|
505
|
+
children: processElem.constants.map(node => deduceTypeAnnotation(app, node, node.typeAnnotation, [process.name, processElem.name], [])),
|
|
506
|
+
});
|
|
507
|
+
scopeVariable.expanded = true;
|
|
508
|
+
scopeVariable.isProcess = true;
|
|
509
|
+
scopeVariable.icon = processElem.type;
|
|
510
|
+
processVariables.children.push(scopeVariable);
|
|
511
|
+
}
|
|
512
|
+
if(processElem.type === 'AutoTask') {
|
|
513
|
+
const scopeVariable = new CompletionProperty({
|
|
514
|
+
name: processElem.name,
|
|
515
|
+
value: processElem.name,
|
|
516
|
+
icon: processElem.type,
|
|
517
|
+
noFurther: true,
|
|
518
|
+
children: [
|
|
519
|
+
...processElem.variables.map(node => deduceTypeAnnotation(app, node, node.typeAnnotation, [process.name, processElem.name], [])),
|
|
520
|
+
...processElem.returns.map(node => deduceTypeAnnotation(app, node, node.typeAnnotation, [process.name, processElem.name], [])),
|
|
521
|
+
]
|
|
522
|
+
});
|
|
523
|
+
scopeVariable.expanded = true;
|
|
524
|
+
scopeVariable.isProcess = true;
|
|
525
|
+
scopeVariable.icon = processElem.type;
|
|
526
|
+
processVariables.children.push(scopeVariable);
|
|
527
|
+
}
|
|
528
|
+
return processVariables;
|
|
529
|
+
}
|