@lcap/nasl 2.18.0-beta.3 → 2.18.0
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/bak/translator.js +1 -1
- package/out/bak/translator.js.map +1 -1
- package/out/concepts/LogicItem__.js.map +1 -1
- package/out/concepts/Logic__.js +4 -4
- package/out/concepts/Logic__.js.map +1 -1
- package/out/concepts/MatchExpression__.d.ts +97 -0
- package/out/concepts/MatchExpression__.js +281 -0
- package/out/concepts/MatchExpression__.js.map +1 -0
- package/out/concepts/Match__.js +1 -1
- package/out/concepts/Match__.js.map +1 -1
- package/out/concepts/MemberExpression__.js.map +1 -1
- package/out/concepts/OqlQueryComponent__.js.map +1 -1
- package/out/concepts/Param__.js +2 -2
- package/out/concepts/Param__.js.map +1 -1
- package/out/concepts/Return__.js +1 -1
- package/out/concepts/Return__.js.map +1 -1
- package/out/concepts/StringInterpolation__.d.ts +16 -16
- package/out/concepts/StringInterpolation__.js +12 -12
- package/out/concepts/StringInterpolation__.js.map +1 -1
- package/out/concepts/ValidationRule__.js.map +1 -1
- package/out/concepts/Variable__.js +1 -1
- package/out/concepts/Variable__.js.map +1 -1
- package/out/concepts/View__.js +2 -2
- package/out/concepts/View__.js.map +1 -1
- package/out/server/naslServer.d.ts +2 -1
- package/out/server/naslServer.js +84 -38
- package/out/server/naslServer.js.map +1 -1
- package/out/templator/genQueryComponent.d.ts +2 -2
- package/out/templator/genQueryComponent.js +4 -1
- package/out/templator/genQueryComponent.js.map +1 -1
- package/out/templator/sql-parser/index.d.ts +1 -0
- package/out/templator/sql-parser/index.js +228 -0
- package/out/templator/sql-parser/index.js.map +1 -0
- package/out/templator/sql-parser/parser.js +26664 -0
- package/out/templator/sql-parser/parser.js.map +1 -0
- package/package.json +3 -4
- package/src/automate/engine/dist/index.dev.js +517 -0
- package/src/bak/translator.js +1 -1
- package/src/common/dist/BaseNode.js +1101 -0
- package/src/concepts/CallInterface__.ts +9 -9
- package/src/concepts/Destination__.ts +9 -9
- package/src/concepts/ExternalDestination__.ts +5 -5
- package/src/concepts/LogicItem__.ts +4 -0
- package/src/concepts/Logic__.ts +42 -5
- package/src/concepts/Match__.ts +21 -1
- package/src/concepts/MemberExpression__.ts +11 -0
- package/src/concepts/OqlQueryComponent__.ts +7 -0
- package/src/concepts/Param__.ts +3 -2
- package/src/concepts/Return__.ts +5 -1
- package/src/concepts/StringInterpolation__.ts +26 -26
- package/src/concepts/UnaryExpression__.ts +4 -4
- package/src/concepts/ValidationRule__.ts +1 -1
- package/src/concepts/Variable__.ts +1 -1
- package/src/concepts/ViewElement__.ts +1 -1
- package/src/concepts/View__.ts +2 -2
- package/src/concepts/basics/stdlib/dist/reference2TypeAnnotationList.js +24 -0
- package/src/concepts/dist/Anchor__.js +179 -0
- package/src/concepts/dist/Assignment__.js +301 -0
- package/src/concepts/dist/CallFunction__.js +473 -0
- package/src/concepts/dist/CallInterface__.js +533 -0
- package/src/concepts/dist/CallLogic__.js +864 -0
- package/src/concepts/dist/ForEachStatement__.js +426 -0
- package/src/concepts/dist/MatchCase__.js +587 -0
- package/src/concepts/dist/MemberExpression__.js +348 -0
- package/src/concepts/dist/Param__.js +537 -0
- package/src/concepts/dist/Return__.js +493 -0
- package/src/generator/dist/genBundleFiles.js +414 -0
- package/src/server/dist/formatTsUtils.js +683 -0
- package/src/server/dist/naslServer.js +3396 -0
- package/src/server/naslServer.ts +84 -39
- package/src/service/storage/dist/init.js +541 -0
- package/src/templator/genQueryComponent.ts +8 -3
- package/ts-worker/dist/webpack.config.dev.js +104 -0
- package/ts-worker/lib/cancellationToken.js +67 -0
- package/ts-worker/lib/dist/tsserver.dev.js +22953 -0
- package/ts-worker/lib/harness.js +1 -1
- package/ts-worker/sources/lib/dist/tsserver.dev.js +22912 -0
- package/ts-worker/src/start.js +1 -1
- package/ts-worker/webpack.config.js +3 -1
- package/dist/bundle.js +0 -3962
- package/dist/bundle.js.LICENSE.txt +0 -16
- package/out/generator/release.d.ts +0 -1
- package/out/generator/release.js +0 -51
- package/out/generator/release.js.map +0 -1
|
@@ -0,0 +1,683 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
3
|
+
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
4
|
+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
5
|
+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
6
|
+
r[k] = a[j];
|
|
7
|
+
return r;
|
|
8
|
+
};
|
|
9
|
+
exports.__esModule = true;
|
|
10
|
+
exports.formatFrontEndVariables = exports.formatVariableData = exports.nextFindTypeChild = exports.isNoChildType = exports.getPlatformType = exports.displayString2TypeAnnotation = exports.type2TypeAnnotation = void 0;
|
|
11
|
+
var __1 = require("..");
|
|
12
|
+
var utils_1 = require("../automate/engine/utils");
|
|
13
|
+
/**
|
|
14
|
+
* 把ts返回的详细信息截取成一个类型字符串
|
|
15
|
+
* @param displayParts ts返回的key value
|
|
16
|
+
* // 0: {text: 'let', kind: 'keyword'}
|
|
17
|
+
// 1: {text: ' ', kind: 'space'}
|
|
18
|
+
// 2: {text: 'bindRoles', kind: 'text'}
|
|
19
|
+
// 3: {text: ':', kind: 'punctuation'}
|
|
20
|
+
// 4: {text: ' ', kind: 'space'}
|
|
21
|
+
// 5: {text: 'roles', kind: 'moduleName'}
|
|
22
|
+
// 6: {text: '.', kind: 'punctuation'}
|
|
23
|
+
// 7: {text: 'DEV_AdminRole', kind: 'enumName'}
|
|
24
|
+
* @returns type roles.DEV_AdminRole
|
|
25
|
+
*/
|
|
26
|
+
function formatTs2TypeString(displayParts) {
|
|
27
|
+
var str = '';
|
|
28
|
+
displayParts.forEach(function (item) {
|
|
29
|
+
str += item.text;
|
|
30
|
+
});
|
|
31
|
+
return str;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 解析 Completion 和 QuickInfo 的 displayString
|
|
35
|
+
* 生成 TypeAnnotation
|
|
36
|
+
* @param displayString
|
|
37
|
+
* @returns TypeAnnotation
|
|
38
|
+
*/
|
|
39
|
+
function type2TypeAnnotation(oldType) {
|
|
40
|
+
if (!oldType)
|
|
41
|
+
return null;
|
|
42
|
+
var type = oldType;
|
|
43
|
+
if (Array.isArray(oldType)) {
|
|
44
|
+
type = oldType[0];
|
|
45
|
+
}
|
|
46
|
+
var typeAnnotation;
|
|
47
|
+
try {
|
|
48
|
+
var _a = type, typeName = _a.typeName, typeNamespace = _a.typeNamespace, typeArguments = _a.typeArguments, typeKind = _a.typeKind, properties = _a.properties;
|
|
49
|
+
if (typeKind === 'anonymousStructure' && Array.isArray(properties) && properties.length) {
|
|
50
|
+
// 自定义类型
|
|
51
|
+
var newProperties_1 = [];
|
|
52
|
+
properties.forEach(function (item) {
|
|
53
|
+
var _a;
|
|
54
|
+
if (!((_a = item === null || item === void 0 ? void 0 : item.name) === null || _a === void 0 ? void 0 : _a.startsWith('__'))) {
|
|
55
|
+
var itemType = type2TypeAnnotation(item.typeInfo);
|
|
56
|
+
var structureProperty = __1.StructureProperty.from({ name: item.name, typeAnnotation: itemType }, typeAnnotation, 'properties');
|
|
57
|
+
newProperties_1.push(structureProperty);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
typeAnnotation = __1.TypeAnnotation.createTypeAnonymousStructure(newProperties_1);
|
|
61
|
+
}
|
|
62
|
+
else if (!typeName || typeName === 'Promise' || typeName === 'nasl' || typeName === '___IDENTIFIER__') {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
else if (typeName === 'String' || typeName === 'Boolean') {
|
|
66
|
+
typeAnnotation = __1.TypeAnnotation.createPrimitive(typeName);
|
|
67
|
+
}
|
|
68
|
+
else if (typeName === 'Union') {
|
|
69
|
+
typeAnnotation = __1.TypeAnnotation.createPrimitive('Union');
|
|
70
|
+
typeAnnotation.typeArguments = [];
|
|
71
|
+
typeArguments.forEach(function (item) {
|
|
72
|
+
var typeItem = type2TypeAnnotation(item);
|
|
73
|
+
if (typeItem) {
|
|
74
|
+
typeAnnotation.typeArgumentsPush(typeItem);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
else if (typeNamespace && typeNamespace.startsWith('nasl.core')) {
|
|
79
|
+
typeAnnotation = __1.TypeAnnotation.createPrimitive(typeName);
|
|
80
|
+
}
|
|
81
|
+
else if (typeNamespace && typeNamespace.startsWith('nasl.collection')) {
|
|
82
|
+
// nasl的泛型类型
|
|
83
|
+
typeAnnotation = __1.TypeAnnotation.createGeneric(typeName, {
|
|
84
|
+
typeNamespace: typeNamespace
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
else if (typeNamespace && typeNamespace.startsWith('nasl.')) {
|
|
88
|
+
// nasl的引用类型
|
|
89
|
+
typeAnnotation = __1.TypeAnnotation.createReference(typeName, {
|
|
90
|
+
typeNamespace: typeNamespace
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
typeAnnotation = __1.TypeAnnotation.createReference(typeName, {
|
|
95
|
+
typeNamespace: typeNamespace
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
// 如果有泛型处理泛型
|
|
99
|
+
if (Array.isArray(typeArguments)) {
|
|
100
|
+
typeAnnotation.typeArguments = [];
|
|
101
|
+
typeArguments.forEach(function (item) {
|
|
102
|
+
var typeItem = type2TypeAnnotation(item);
|
|
103
|
+
if (typeItem) {
|
|
104
|
+
typeAnnotation.typeArgumentsPush(typeItem);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
console.log(err, type);
|
|
111
|
+
}
|
|
112
|
+
return typeAnnotation;
|
|
113
|
+
}
|
|
114
|
+
exports.type2TypeAnnotation = type2TypeAnnotation;
|
|
115
|
+
/**
|
|
116
|
+
* 解析 Completion 和 QuickInfo 的 displayString
|
|
117
|
+
* 生成 TypeAnnotation
|
|
118
|
+
* @param displayString
|
|
119
|
+
* @returns TypeAnnotation
|
|
120
|
+
*/
|
|
121
|
+
function displayString2TypeAnnotation(typeStr, parentPrefix) {
|
|
122
|
+
var type = '';
|
|
123
|
+
if (typeStr === null || typeStr === void 0 ? void 0 : typeStr.includes(': ')) {
|
|
124
|
+
var lastIndexOf = typeStr.lastIndexOf(': ');
|
|
125
|
+
type = typeStr.substring(lastIndexOf + 2, typeStr.length);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
type = typeStr;
|
|
129
|
+
}
|
|
130
|
+
type = type.replaceAll(' ', '');
|
|
131
|
+
if (type === 'Promise<void>')
|
|
132
|
+
return null;
|
|
133
|
+
// 把后面结尾里带()的比如
|
|
134
|
+
// 'function nasl.core.add(left: nasl.core.Integer, right: nasl.core.Integer): nasl.core.Integer (+12 overloads)'
|
|
135
|
+
if (type.includes('(') && type.includes(')')) {
|
|
136
|
+
type = type.replace(/\([^\)]*\)/g, '');
|
|
137
|
+
}
|
|
138
|
+
var typeAnnotation;
|
|
139
|
+
try {
|
|
140
|
+
if (type.includes('<') && type.includes('>')) {
|
|
141
|
+
// 泛型的处理
|
|
142
|
+
typeAnnotation = createGenericTypeAnnotation(type, parentPrefix);
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
typeAnnotation = createType2Annotation(type, parentPrefix);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
catch (err) {
|
|
149
|
+
console.log(err);
|
|
150
|
+
}
|
|
151
|
+
return typeAnnotation;
|
|
152
|
+
}
|
|
153
|
+
exports.displayString2TypeAnnotation = displayString2TypeAnnotation;
|
|
154
|
+
function createGenericTypeAnnotation(type, parentPrefix) {
|
|
155
|
+
// 取出匹配的内容
|
|
156
|
+
var childType = type.substring(0, type.indexOf('<'));
|
|
157
|
+
var typeAnnotation = createType2Annotation(childType);
|
|
158
|
+
// 如果还有匹配到的多层泛型;
|
|
159
|
+
// 取出匹配到的内容
|
|
160
|
+
var types = /\<([^()]+)\>/g.exec(type);
|
|
161
|
+
var newtext = types[1];
|
|
162
|
+
// 把匹配的值,的内容在,检索一遍,看是不是泛型套泛型
|
|
163
|
+
var newTypes = /\<([^()]+)\>/g.exec(newtext);
|
|
164
|
+
// 如果是的话就去递归
|
|
165
|
+
if (newTypes) {
|
|
166
|
+
var argTypeAnnotation = createGenericTypeAnnotation(newtext, parentPrefix);
|
|
167
|
+
typeAnnotation.typeArguments = [argTypeAnnotation];
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
var argTypeAnnotation = createType2Annotation(newtext, parentPrefix);
|
|
171
|
+
// 如果不是就创造内部的真正类型
|
|
172
|
+
if (newtext.includes(',')) {
|
|
173
|
+
typeAnnotation.typeArguments = newtext.split(',').map(function (item) { return createType2Annotation(item); });
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
typeAnnotation.typeArguments = [argTypeAnnotation];
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return typeAnnotation;
|
|
180
|
+
}
|
|
181
|
+
function createType2Annotation(type, parentPrefix) {
|
|
182
|
+
var typeAnnotation;
|
|
183
|
+
// 没有泛型类型的
|
|
184
|
+
var types = type.split('.');
|
|
185
|
+
// 长度等于1就说明是
|
|
186
|
+
if (types.length === 1) {
|
|
187
|
+
typeAnnotation = __1.TypeAnnotation.createPrimitive(types[0]);
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
var typeName = types.pop();
|
|
191
|
+
var typeNamespace = types.join('.');
|
|
192
|
+
if (type.startsWith('nasl.core')) {
|
|
193
|
+
typeAnnotation = __1.TypeAnnotation.createPrimitive(typeName);
|
|
194
|
+
}
|
|
195
|
+
else if (type.startsWith('nasl.ui')) {
|
|
196
|
+
typeAnnotation = __1.TypeAnnotation.createReference(typeName, {
|
|
197
|
+
typeNamespace: typeNamespace
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
else if (type.startsWith('nasl.process')) {
|
|
201
|
+
// nasl的引用类型
|
|
202
|
+
typeAnnotation = __1.TypeAnnotation.createReference(typeName, {
|
|
203
|
+
typeNamespace: typeNamespace
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
else if (type.startsWith('nasl.collection')) {
|
|
207
|
+
// nasl的泛型类型
|
|
208
|
+
typeAnnotation = __1.TypeAnnotation.createGeneric(typeName, {
|
|
209
|
+
typeNamespace: typeNamespace
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
else if (type.startsWith('dataSources.') || type.startsWith('structures.') || type.startsWith('enums.')) {
|
|
213
|
+
typeAnnotation = __1.TypeAnnotation.createReference(typeName, {
|
|
214
|
+
typeNamespace: (parentPrefix || 'app.') + typeNamespace
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
typeAnnotation = __1.TypeAnnotation.createReference(typeName, {
|
|
219
|
+
typeNamespace: typeNamespace
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return typeAnnotation;
|
|
224
|
+
}
|
|
225
|
+
function getPlatformType(type) {
|
|
226
|
+
var tsType = '';
|
|
227
|
+
if (type === null || type === void 0 ? void 0 : type.includes(': ')) {
|
|
228
|
+
var lastIndexOf = type.lastIndexOf(': ');
|
|
229
|
+
tsType = type.substring(lastIndexOf + 2, type.length);
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
tsType = type;
|
|
233
|
+
}
|
|
234
|
+
tsType = tsType.replaceAll(' ', '');
|
|
235
|
+
var namespacePrefix = ['app', 'extensions', 'apis', 'components', 'nasl'];
|
|
236
|
+
if (tsType === 'String') {
|
|
237
|
+
return 'nasl.core.String';
|
|
238
|
+
}
|
|
239
|
+
else if (tsType === 'Boolean') {
|
|
240
|
+
return 'nasl.core.Boolean';
|
|
241
|
+
}
|
|
242
|
+
var strTypes = tsType.split('.');
|
|
243
|
+
if (strTypes.length) {
|
|
244
|
+
var first = strTypes[0];
|
|
245
|
+
// 如果不是这几个前缀就加一个namespace
|
|
246
|
+
if (!namespacePrefix.includes(first)) {
|
|
247
|
+
return 'app.' + tsType;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return tsType;
|
|
251
|
+
}
|
|
252
|
+
exports.getPlatformType = getPlatformType;
|
|
253
|
+
function isNoChildType(type) {
|
|
254
|
+
return (type === null || type === void 0 ? void 0 : type.startsWith('nasl.core')) || (type === null || type === void 0 ? void 0 : type.startsWith('app.enums'));
|
|
255
|
+
}
|
|
256
|
+
exports.isNoChildType = isNoChildType;
|
|
257
|
+
function findNode(typeKey, node) {
|
|
258
|
+
var _a, _b;
|
|
259
|
+
var newType;
|
|
260
|
+
if (typeKey.startsWith('nasl.') && typeKey.includes('<')) {
|
|
261
|
+
var findGenericsIndex = typeKey.indexOf('<');
|
|
262
|
+
typeKey = typeKey.substring(0, findGenericsIndex);
|
|
263
|
+
var typeIndex = typeKey.lastIndexOf('.');
|
|
264
|
+
newType = utils_1.getNaslNodeByNodeCallee(typeKey.substring(0, typeIndex), typeKey.substring(typeIndex + 1, typeKey.length));
|
|
265
|
+
}
|
|
266
|
+
else if (typeKey.startsWith('nasl.')) {
|
|
267
|
+
var typeIndex = typeKey.lastIndexOf('.');
|
|
268
|
+
newType = utils_1.getNaslNodeByNodeCallee(typeKey.substring(0, typeIndex), typeKey.substring(typeIndex + 1, typeKey.length));
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
newType = (_b = (_a = node) === null || _a === void 0 ? void 0 : _a.app) === null || _b === void 0 ? void 0 : _b.findNodeByCompleteName(typeKey);
|
|
272
|
+
}
|
|
273
|
+
return newType;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* 获取下一级的节点进行递归
|
|
277
|
+
* @param typeKey 当前节点的类型,主要为了取出内部的 T中的实际类型
|
|
278
|
+
* @param item 当前节点的内容
|
|
279
|
+
* @param parent 父级节点的内容
|
|
280
|
+
* @param node 获取变量框的位置
|
|
281
|
+
*/
|
|
282
|
+
function nextFindTypeChild(typeKey, item, parent, node) {
|
|
283
|
+
var _a;
|
|
284
|
+
// 有一个当前树分支的全部节点的node map,用作防止数据无限递归,只保留3层
|
|
285
|
+
var nodeMap = parent ? parent.nodeMap : new Map();
|
|
286
|
+
item.nodeMap = nodeMap;
|
|
287
|
+
var newType = findNode(typeKey, node);
|
|
288
|
+
if (((_a = newType) === null || _a === void 0 ? void 0 : _a.properties) && newType.properties.length) {
|
|
289
|
+
// 处理泛型的内容要取到值
|
|
290
|
+
var StructureJson = newType.toJSON();
|
|
291
|
+
var newStructure = new __1.Structure(StructureJson);
|
|
292
|
+
newStructure.properties.forEach(function (item) {
|
|
293
|
+
var _a;
|
|
294
|
+
var itemType = (_a = item === null || item === void 0 ? void 0 : item.typeAnnotation) === null || _a === void 0 ? void 0 : _a.typeKey;
|
|
295
|
+
if (itemType === 'T' && /\<([^()]+)\>/g.exec(typeKey)) {
|
|
296
|
+
var newTypes = /\<([^()]+)\>/g.exec(typeKey);
|
|
297
|
+
// 找到当前原来的类型
|
|
298
|
+
var contentType = getPlatformType(newTypes[1]);
|
|
299
|
+
var typeNamespace = contentType.substring(0, contentType.lastIndexOf('.'));
|
|
300
|
+
var typeName = contentType.substring(contentType.lastIndexOf('.') + 1, contentType.length);
|
|
301
|
+
item.typeAnnotation = new __1.TypeAnnotation({
|
|
302
|
+
typeKind: 'reference',
|
|
303
|
+
typeNamespace: typeNamespace,
|
|
304
|
+
typeName: typeName
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
var index = nodeMap.get(newType) || 0;
|
|
309
|
+
if (index) {
|
|
310
|
+
nodeMap.set(newType, index + 1);
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
nodeMap.set(newType, 1);
|
|
314
|
+
}
|
|
315
|
+
// 最多保留3层
|
|
316
|
+
if (index < 3) {
|
|
317
|
+
item.children = formatVariableData(newStructure.properties, node, item);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
exports.nextFindTypeChild = nextFindTypeChild;
|
|
322
|
+
/**
|
|
323
|
+
* 获取scope下一级的展示
|
|
324
|
+
* @param type 返回的字符串如下展示
|
|
325
|
+
* `nasl.ui.Current<{
|
|
326
|
+
__name: "AStructure_dc8bcbaf";
|
|
327
|
+
entity1: dataSources.defaultDS.entities.Entity1;
|
|
328
|
+
lCAPRolePerMapping: dataSources.defaultDS.entities.LCAPRolePerMapping;
|
|
329
|
+
}>`
|
|
330
|
+
*/
|
|
331
|
+
function getAStructureScopeType(type, parent, node) {
|
|
332
|
+
var newType = type.replaceAll(' ', '').replaceAll('\n', '').replace(/__name:"AStructure_\w{8}";/g, '');
|
|
333
|
+
var parentItem = parent;
|
|
334
|
+
// 如果没有父节点就是Identifier
|
|
335
|
+
// value需要拼接生成
|
|
336
|
+
var identifier = new __1.Identifier({ name: parentItem.text });
|
|
337
|
+
parentItem.expression = identifier;
|
|
338
|
+
parentItem.value = parentItem.text;
|
|
339
|
+
parentItem.name = parentItem.text;
|
|
340
|
+
// 处理泛型的内容要取到值
|
|
341
|
+
var newNode = findNode(newType, node);
|
|
342
|
+
var StructureJson = newNode.toJSON();
|
|
343
|
+
var newStructure = new __1.Structure(StructureJson);
|
|
344
|
+
var children = newStructure.properties;
|
|
345
|
+
if (children && children.length) {
|
|
346
|
+
var newChildren = children.map(function (structureProperty) {
|
|
347
|
+
var structureItem = structureProperty;
|
|
348
|
+
// 如果没有父节点就是Identifier
|
|
349
|
+
structureItem.value = parentItem.value + "." + structureItem.name;
|
|
350
|
+
var memberExpression = new __1.MemberExpression({
|
|
351
|
+
object: parentItem.expression,
|
|
352
|
+
property: new __1.Identifier({ name: structureItem.name })
|
|
353
|
+
});
|
|
354
|
+
structureItem.expression = memberExpression;
|
|
355
|
+
// 如果是从实体或者数据结构取的属性,就需要重置一下类型
|
|
356
|
+
structureItem.concept = 'CompletionProperty';
|
|
357
|
+
var completionProperty = new __1.CompletionProperty(structureItem);
|
|
358
|
+
completionProperty.icon = 'refProperty';
|
|
359
|
+
if (structureItem.name === 'item') {
|
|
360
|
+
var context = /\{([^()]+)\}/.exec(newType);
|
|
361
|
+
newType = context[1];
|
|
362
|
+
var res_1 = [];
|
|
363
|
+
newType.split(';').forEach(function (item) {
|
|
364
|
+
if (item) {
|
|
365
|
+
var itemArr = item.split(':');
|
|
366
|
+
var name = itemArr[0];
|
|
367
|
+
var typeKey = itemArr[1];
|
|
368
|
+
if (typeKey && typeKey.startsWith('dataSources')) {
|
|
369
|
+
typeKey = 'app.' + typeKey;
|
|
370
|
+
}
|
|
371
|
+
res_1.push({
|
|
372
|
+
name: name,
|
|
373
|
+
typeKey: typeKey
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
res_1 = res_1.map(function (item) {
|
|
378
|
+
var newItem = item;
|
|
379
|
+
// 如果没有父节点就是Identifier
|
|
380
|
+
newItem.value = structureItem.value + "." + newItem.name;
|
|
381
|
+
var memberExpression = new __1.MemberExpression({
|
|
382
|
+
object: structureItem.expression,
|
|
383
|
+
property: new __1.Identifier({ name: newItem.name })
|
|
384
|
+
});
|
|
385
|
+
newItem.expression = memberExpression;
|
|
386
|
+
// 如果是从实体或者数据结构取的属性,就需要重置一下类型
|
|
387
|
+
newItem.concept = 'CompletionProperty';
|
|
388
|
+
// 如果有类型而且类型不是没有子集的类型,就把他当前的类型拿到
|
|
389
|
+
if (item.typeKey && !isNoChildType(item.typeKey)) {
|
|
390
|
+
newItem.children = nextObjectTypeChild(item.typeKey, newItem, parentItem, node);
|
|
391
|
+
}
|
|
392
|
+
var completionProperty = new __1.CompletionProperty(newItem);
|
|
393
|
+
completionProperty.icon = 'refProperty';
|
|
394
|
+
return completionProperty;
|
|
395
|
+
});
|
|
396
|
+
completionProperty.children = res_1;
|
|
397
|
+
return completionProperty;
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
return completionProperty;
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
parentItem.children = newChildren;
|
|
404
|
+
}
|
|
405
|
+
var completionProperty = new __1.CompletionProperty(parentItem);
|
|
406
|
+
// 变量 param return 在这里添加图标
|
|
407
|
+
completionProperty.icon = getNodeiconFromLogic(completionProperty, node);
|
|
408
|
+
return completionProperty;
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* 获取对象类型的下一级展示
|
|
412
|
+
* @param type 返回的字符串如下展示
|
|
413
|
+
* `{
|
|
414
|
+
__name: "AStructure_bf19c4d5";
|
|
415
|
+
list: nasl.collection.List<{
|
|
416
|
+
__name: "AStructure_dc8bcbaf";
|
|
417
|
+
entity1: app.dataSources.defaultDS.entities.Entity1;
|
|
418
|
+
lCAPRolePerMapping: app.dataSources.defaultDS.entities.LCAPRolePerMapping;
|
|
419
|
+
}>;
|
|
420
|
+
total: nasl.core.Integer;
|
|
421
|
+
}`
|
|
422
|
+
*/
|
|
423
|
+
function getAStructureObjectStringType(type, parent, node) {
|
|
424
|
+
var newType = type.replaceAll(' ', '').replaceAll('\n', '').replace(/__name:"AStructure_\w{8}";/g, '');
|
|
425
|
+
newType = newType.substring(1, newType.length - 1);
|
|
426
|
+
if (!parent.keyMap) {
|
|
427
|
+
parent.keyMap = new Map();
|
|
428
|
+
}
|
|
429
|
+
if (/\{([^()]+)\}/.exec(newType)) {
|
|
430
|
+
newType = newType.replace(/\{([^()]+)\}/, '');
|
|
431
|
+
}
|
|
432
|
+
var res = [];
|
|
433
|
+
newType.split(';').forEach(function (item) {
|
|
434
|
+
if (item) {
|
|
435
|
+
var itemArr = item.split(':');
|
|
436
|
+
var name = itemArr[0];
|
|
437
|
+
var typeKey = itemArr[1];
|
|
438
|
+
res.push({
|
|
439
|
+
name: name,
|
|
440
|
+
typeKey: typeKey
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
var parentItem = parent;
|
|
445
|
+
// 如果没有父节点就是Identifier
|
|
446
|
+
// value需要拼接生成
|
|
447
|
+
var identifier = new __1.Identifier({ name: parentItem.text });
|
|
448
|
+
parentItem.expression = identifier;
|
|
449
|
+
parentItem.value = parentItem.text;
|
|
450
|
+
parentItem.name = parentItem.text;
|
|
451
|
+
// 如果是从实体或者数据结构取的属性,就需要重置一下类型
|
|
452
|
+
parentItem.concept = 'CompletionProperty';
|
|
453
|
+
res = res.map(function (item) {
|
|
454
|
+
var newItem = item;
|
|
455
|
+
// 如果没有父节点就是Identifier
|
|
456
|
+
newItem.value = parentItem.value + "." + newItem.name;
|
|
457
|
+
var memberExpression = new __1.MemberExpression({
|
|
458
|
+
object: parentItem.expression,
|
|
459
|
+
property: new __1.Identifier({ name: newItem.name })
|
|
460
|
+
});
|
|
461
|
+
newItem.expression = memberExpression;
|
|
462
|
+
// 如果是从实体或者数据结构取的属性,就需要重置一下类型
|
|
463
|
+
newItem.concept = 'CompletionProperty';
|
|
464
|
+
// 如果有类型而且类型不是没有子集的类型,就把他当前的类型拿到
|
|
465
|
+
if (item.typeKey && !isNoChildType(item.typeKey)) {
|
|
466
|
+
newItem.children = nextObjectTypeChild(getPlatformType(item.typeKey), newItem, parentItem, node);
|
|
467
|
+
}
|
|
468
|
+
var completionProperty = new __1.CompletionProperty(newItem);
|
|
469
|
+
completionProperty.icon = 'refProperty';
|
|
470
|
+
return completionProperty;
|
|
471
|
+
});
|
|
472
|
+
parentItem.children = res;
|
|
473
|
+
var completionProperty = new __1.CompletionProperty(parentItem);
|
|
474
|
+
// 变量 param return 在这里添加图标
|
|
475
|
+
completionProperty.icon = getNodeiconFromLogic(completionProperty, node);
|
|
476
|
+
return completionProperty;
|
|
477
|
+
}
|
|
478
|
+
function nextObjectTypeChild(typeKey, item, parent, node) {
|
|
479
|
+
var _a;
|
|
480
|
+
// 有一个当前树分支的全部节点的node map,用作防止数据无限递归,只保留3层
|
|
481
|
+
var nodeMap = parent.nodeMap || new Map();
|
|
482
|
+
item.nodeMap = nodeMap; // 有一个当前树分支的全部节点的node map,用作防止数据无限递归,只保留3层
|
|
483
|
+
var keyMap = parent.keyMap;
|
|
484
|
+
item.keyMap = keyMap;
|
|
485
|
+
var newType = findNode(typeKey, node);
|
|
486
|
+
if (((_a = newType) === null || _a === void 0 ? void 0 : _a.properties) && newType.properties.length) {
|
|
487
|
+
// 处理泛型的内容要取到值
|
|
488
|
+
var StructureJson = newType.toJSON();
|
|
489
|
+
var newStructure = new __1.Structure(StructureJson);
|
|
490
|
+
newStructure.properties.forEach(function (item) {
|
|
491
|
+
var _a;
|
|
492
|
+
var itemType = (_a = item === null || item === void 0 ? void 0 : item.typeAnnotation) === null || _a === void 0 ? void 0 : _a.typeKey;
|
|
493
|
+
if (itemType === 'T' && /\<([^()]+)\>/g.exec(typeKey)) {
|
|
494
|
+
var newTypes = /\<([^()]+)\>/g.exec(typeKey);
|
|
495
|
+
// 找到当前原来的类型
|
|
496
|
+
var contentType = getPlatformType(newTypes[1]);
|
|
497
|
+
var typeNamespace = contentType.substring(0, contentType.lastIndexOf('.'));
|
|
498
|
+
var typeName = contentType.substring(contentType.lastIndexOf('.') + 1, contentType.length);
|
|
499
|
+
item.typeAnnotation = new __1.TypeAnnotation({
|
|
500
|
+
typeKind: 'reference',
|
|
501
|
+
typeNamespace: typeNamespace,
|
|
502
|
+
typeName: typeName
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
});
|
|
506
|
+
var index = nodeMap.get(newType) || 0;
|
|
507
|
+
if (index) {
|
|
508
|
+
nodeMap.set(newType, index + 1);
|
|
509
|
+
}
|
|
510
|
+
else {
|
|
511
|
+
nodeMap.set(newType, 1);
|
|
512
|
+
}
|
|
513
|
+
// 最多保留3层
|
|
514
|
+
if (index < 3) {
|
|
515
|
+
return formatVariableData(newStructure.properties, node, item);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
// 格式化变量数据
|
|
520
|
+
function formatVariableData(data, node, parent) {
|
|
521
|
+
if (Array.isArray(data)) {
|
|
522
|
+
var result = data.map(function (item) {
|
|
523
|
+
var _a;
|
|
524
|
+
item.children = [];
|
|
525
|
+
// 当前的类型如 app.entitys.entity1 nasl.core.String
|
|
526
|
+
var typeKey;
|
|
527
|
+
if (item.completionDetail) {
|
|
528
|
+
if (item.completionDetail.nodeType) {
|
|
529
|
+
var typeAnnotation = type2TypeAnnotation(item.completionDetail.nodeType);
|
|
530
|
+
typeKey = typeAnnotation === null || typeAnnotation === void 0 ? void 0 : typeAnnotation.typeKey;
|
|
531
|
+
}
|
|
532
|
+
else {
|
|
533
|
+
// 当前节点的完整类型,主要是在有T的内容使用 nasl.list<Enum1> 内部匹配内容给里面子集的T赋值类型
|
|
534
|
+
var currentType = formatTs2TypeString(item.completionDetail.displayParts);
|
|
535
|
+
if (currentType) {
|
|
536
|
+
if (currentType === null || currentType === void 0 ? void 0 : currentType.includes(': ')) {
|
|
537
|
+
var indexOf = currentType.indexOf(': ');
|
|
538
|
+
var newCurrentType = currentType.substring(indexOf + 2, currentType.length);
|
|
539
|
+
// 如果是对象形式的就单独处理
|
|
540
|
+
if (newCurrentType.startsWith('{') && newCurrentType.endsWith('}')) {
|
|
541
|
+
var completionProperty_1 = getAStructureObjectStringType(newCurrentType, item, node);
|
|
542
|
+
return completionProperty_1;
|
|
543
|
+
}
|
|
544
|
+
else if (newCurrentType.startsWith('nasl.ui.Current<{')) {
|
|
545
|
+
var completionProperty_2 = getAStructureScopeType(newCurrentType, item, node);
|
|
546
|
+
return completionProperty_2;
|
|
547
|
+
}
|
|
548
|
+
else if (newCurrentType.startsWith('nasl.collection.List<{') && newCurrentType.endsWith('}>')) {
|
|
549
|
+
currentType = 'nasl.collection.List<nasl.core.Any>';
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
typeKey = getPlatformType(currentType);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
else if (item instanceof __1.StructureProperty) {
|
|
557
|
+
typeKey = (_a = item === null || item === void 0 ? void 0 : item.typeAnnotation) === null || _a === void 0 ? void 0 : _a.typeKey;
|
|
558
|
+
}
|
|
559
|
+
// 如果没有父节点就是Identifier
|
|
560
|
+
if (!parent) {
|
|
561
|
+
// value需要拼接生成
|
|
562
|
+
item.value = parent ? parent.value + "." + item.text : item.text;
|
|
563
|
+
item.name = item.text;
|
|
564
|
+
var identifier = new __1.Identifier({ name: item.name });
|
|
565
|
+
item.expression = identifier;
|
|
566
|
+
}
|
|
567
|
+
else {
|
|
568
|
+
item.value = parent.value + "." + item.name;
|
|
569
|
+
var memberExpression = new __1.MemberExpression({
|
|
570
|
+
object: parent.expression,
|
|
571
|
+
property: new __1.Identifier({ name: item.name })
|
|
572
|
+
});
|
|
573
|
+
item.expression = memberExpression;
|
|
574
|
+
}
|
|
575
|
+
// 如果有类型而且类型不是没有子集的类型,就把他当前的类型拿到
|
|
576
|
+
if (typeKey && !isNoChildType(typeKey)) {
|
|
577
|
+
nextFindTypeChild(typeKey, item, parent, node);
|
|
578
|
+
}
|
|
579
|
+
// 如果是从实体或者数据结构取的属性,就需要重置一下类型
|
|
580
|
+
item.concept = 'CompletionProperty';
|
|
581
|
+
var completionProperty = new __1.CompletionProperty(item);
|
|
582
|
+
if (!parent) {
|
|
583
|
+
// 变量 param return 在这里添加图标
|
|
584
|
+
completionProperty.icon = getNodeiconFromLogic(completionProperty, node);
|
|
585
|
+
}
|
|
586
|
+
else {
|
|
587
|
+
completionProperty.icon = 'refProperty';
|
|
588
|
+
}
|
|
589
|
+
return completionProperty;
|
|
590
|
+
});
|
|
591
|
+
/**
|
|
592
|
+
* 排序result
|
|
593
|
+
* 如果没有父级就是第一集就排序一下当前result,用户体验优化
|
|
594
|
+
*/
|
|
595
|
+
if (!parent) {
|
|
596
|
+
result = sortFirstVariableData(result, node);
|
|
597
|
+
}
|
|
598
|
+
return result;
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
exports.formatVariableData = formatVariableData;
|
|
602
|
+
// 从logic获取节点的icon
|
|
603
|
+
function getNodeiconFromLogic(completionProperty, node) {
|
|
604
|
+
var logic = node.logic;
|
|
605
|
+
var view = node.view;
|
|
606
|
+
if (view) {
|
|
607
|
+
var params = view.params;
|
|
608
|
+
if (params.find(function (item) { return item.name === completionProperty.name; }))
|
|
609
|
+
return 'param';
|
|
610
|
+
}
|
|
611
|
+
if (logic) {
|
|
612
|
+
var params = logic.params, returns = logic.returns;
|
|
613
|
+
if (params.find(function (item) { return item.name === completionProperty.name; }))
|
|
614
|
+
return 'param';
|
|
615
|
+
if (returns.find(function (item) { return item.name === completionProperty.name; }))
|
|
616
|
+
return 'return';
|
|
617
|
+
// if (variables.find((item) => item.name === completionProperty.name))
|
|
618
|
+
// return 'variable';
|
|
619
|
+
// 其余的全部按variable展示
|
|
620
|
+
return 'variable';
|
|
621
|
+
}
|
|
622
|
+
return 'variable';
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* 把要返回去的数据做一下排序
|
|
626
|
+
* @param result 要返回数据
|
|
627
|
+
* @param node 当前内容的上下级
|
|
628
|
+
* @returns 返回排序后的数组
|
|
629
|
+
* 因为ts会按照 a-z的顺序进行排序
|
|
630
|
+
* 但是影响用户体验,需要先按照页面排序,其次按照logic进行排序
|
|
631
|
+
* 流程的韬哥自己解决了,所以先解决这两部分
|
|
632
|
+
*/
|
|
633
|
+
function sortFirstVariableData(result, node) {
|
|
634
|
+
var newResult = [];
|
|
635
|
+
var logic = node.logic;
|
|
636
|
+
var view = node.view;
|
|
637
|
+
if (view) {
|
|
638
|
+
var params = view.params, variables = view.variables;
|
|
639
|
+
var list = __spreadArrays(params, variables);
|
|
640
|
+
list.forEach(function (item) {
|
|
641
|
+
var findIndex = result.findIndex(function (findItem) { return findItem.name === item.name; });
|
|
642
|
+
if (findIndex !== -1) {
|
|
643
|
+
newResult.push(result[findIndex]);
|
|
644
|
+
result.splice(findIndex, 1);
|
|
645
|
+
}
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
if (logic) {
|
|
649
|
+
var params = logic.params, returns = logic.returns, variables = logic.variables;
|
|
650
|
+
var list = __spreadArrays(params, returns, variables);
|
|
651
|
+
list.forEach(function (item) {
|
|
652
|
+
var findIndex = result.findIndex(function (findItem) { return findItem.name === item.name; });
|
|
653
|
+
if (findIndex !== -1) {
|
|
654
|
+
newResult.push(result[findIndex]);
|
|
655
|
+
result.splice(findIndex, 1);
|
|
656
|
+
}
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
newResult.push.apply(newResult, result);
|
|
660
|
+
return newResult;
|
|
661
|
+
}
|
|
662
|
+
function formatFrontEndVariables(frontEndVariables) {
|
|
663
|
+
var result = frontEndVariables.map(function (item) {
|
|
664
|
+
var namespace = item.getNamespace();
|
|
665
|
+
var newItem = {
|
|
666
|
+
name: item.name,
|
|
667
|
+
value: item.name,
|
|
668
|
+
expression: new __1.Identifier({
|
|
669
|
+
name: item.name,
|
|
670
|
+
namespace: namespace
|
|
671
|
+
})
|
|
672
|
+
};
|
|
673
|
+
var noChildType = isNoChildType(item.typeAnnotation.typeKey);
|
|
674
|
+
if (!noChildType) {
|
|
675
|
+
nextFindTypeChild(item.typeAnnotation.typeKey, newItem, null, item);
|
|
676
|
+
}
|
|
677
|
+
var completionProperty = new __1.CompletionProperty(newItem);
|
|
678
|
+
completionProperty.icon = 'frontendVariable';
|
|
679
|
+
return completionProperty;
|
|
680
|
+
});
|
|
681
|
+
return result;
|
|
682
|
+
}
|
|
683
|
+
exports.formatFrontEndVariables = formatFrontEndVariables;
|