@lcap/nasl 2.13.0 → 2.13.1

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.
Files changed (40) hide show
  1. package/out/concepts/CompletionProperty__.d.ts +0 -1
  2. package/out/concepts/CompletionProperty__.js +0 -1
  3. package/out/concepts/CompletionProperty__.js.map +1 -1
  4. package/out/concepts/TypeAnnotation__.js +3 -14
  5. package/out/concepts/TypeAnnotation__.js.map +1 -1
  6. package/out/concepts/basics/stdlib/nasl.collection.js +12 -0
  7. package/out/concepts/basics/stdlib/nasl.collection.js.map +1 -1
  8. package/out/concepts/basics/stdlib/nasl.util.js +187 -5
  9. package/out/concepts/basics/stdlib/nasl.util.js.map +1 -1
  10. package/out/concepts/basics/stdlib/reference2TypeAnnotationList.js +1 -1
  11. package/out/concepts/basics/stdlib/reference2TypeAnnotationList.js.map +1 -1
  12. package/out/enums/KEYWORDS.d.ts +1 -0
  13. package/out/enums/KEYWORDS.js +16 -1
  14. package/out/enums/KEYWORDS.js.map +1 -1
  15. package/out/generator/genBundleFiles.js +25 -1
  16. package/out/generator/genBundleFiles.js.map +1 -1
  17. package/out/server/getLogics.js +18 -17
  18. package/out/server/getLogics.js.map +1 -1
  19. package/out/server/getMemberIdentifier.d.ts +9 -0
  20. package/out/server/getMemberIdentifier.js +98 -34
  21. package/out/server/getMemberIdentifier.js.map +1 -1
  22. package/out/server/getProcesses.js +9 -18
  23. package/out/server/getProcesses.js.map +1 -1
  24. package/out/server/naslServer.js +5 -2
  25. package/out/server/naslServer.js.map +1 -1
  26. package/out/templator/genQueryComponent.js +8 -8
  27. package/out/templator/genQueryComponent.js.map +1 -1
  28. package/package.json +1 -1
  29. package/src/concepts/CompletionProperty__.ts +0 -1
  30. package/src/concepts/TypeAnnotation__.ts +3 -30
  31. package/src/concepts/basics/stdlib/nasl.collection.ts +12 -0
  32. package/src/concepts/basics/stdlib/nasl.util.ts +187 -5
  33. package/src/concepts/basics/stdlib/reference2TypeAnnotationList.ts +1 -1
  34. package/src/enums/KEYWORDS.ts +16 -0
  35. package/src/generator/genBundleFiles.ts +24 -1
  36. package/src/server/getLogics.ts +18 -17
  37. package/src/server/getMemberIdentifier.ts +92 -32
  38. package/src/server/getProcesses.ts +10 -19
  39. package/src/server/naslServer.ts +5 -2
  40. package/src/templator/genQueryComponent.ts +8 -8
@@ -1,5 +1,6 @@
1
- import { BaseNode, CompletionProperty, App, Identifier, MemberExpression, Enum, NullLiteral, BooleanLiteral, Param, BindAttribute, LogicItem, TypeAnnotation } from '..';
1
+ import { BaseNode, CompletionProperty, App, Identifier, MemberExpression, Enum, NullLiteral, BooleanLiteral, Param, BindAttribute, LogicItem, TypeAnnotation, StructureProperty, Entity, Structure, EntityProperty } from '..';
2
2
  import naslServer from './naslServer';
3
+ import { getNaslNodeByNodeCallee } from '../automate/engine/utils';
3
4
 
4
5
  interface variableItem {
5
6
  text: string;
@@ -115,6 +116,8 @@ export function getPlatformType(tsType: string): string {
115
116
  const namespacePrefix = ['app', 'extensions', 'apis', 'components', 'nasl'];
116
117
  if (tsType === 'String') {
117
118
  return 'nasl.core.String';
119
+ } else if (tsType === 'Boolean') {
120
+ return 'nasl.core.Boolean';
118
121
  }
119
122
 
120
123
  const strTypes = tsType.split('.');
@@ -165,29 +168,97 @@ function sortFirstVariableData(result: CompletionProperty[], node: BaseNode) {
165
168
  newResult.push(...result);
166
169
  return newResult;
167
170
  }
171
+ export function isNoChildType(type: String) {
172
+ return type?.startsWith('nasl.core') || type?.startsWith('app.enums');
173
+ }
174
+ function findNode(typeKey: string, node: BaseNode) {
175
+ let newType: Structure | Entity;
176
+ if (typeKey.startsWith('nasl.') && typeKey.includes('<')) {
177
+ const findGenericsIndex = typeKey.indexOf('<');
178
+ typeKey = typeKey.substring(0, findGenericsIndex);
179
+ const typeIndex = typeKey.lastIndexOf('.');
180
+ newType = getNaslNodeByNodeCallee(typeKey.substring(0, typeIndex), typeKey.substring(typeIndex + 1, typeKey.length));
181
+ } else if (typeKey.startsWith('nasl.')) {
182
+ const typeIndex = typeKey.lastIndexOf('.');
183
+ newType = getNaslNodeByNodeCallee(typeKey.substring(0, typeIndex), typeKey.substring(typeIndex + 1, typeKey.length));
184
+ } else {
185
+ newType = (node as Identifier)?.app?.findNodeByCompleteName(typeKey);
186
+ }
187
+ return newType;
188
+ }
189
+
190
+ /**
191
+ * 获取下一级的节点进行递归
192
+ * @param typeKey 当前节点的类型,主要为了取出内部的 T中的实际类型
193
+ * @param item 当前节点的内容
194
+ * @param parent 父级节点的内容
195
+ * @param node 获取变量框的位置
196
+ */
197
+ export function nextFindTypeChild(typeKey: string, item: any, parent: any, node: BaseNode) {
198
+ // 有一个当前树分支的全部节点的node map,用作防止数据无限递归,只保留3层
199
+ const nodeMap = parent ? parent.nodeMap : new Map();
200
+ item.nodeMap = nodeMap;
201
+ const newType = findNode(typeKey, node);
202
+ if (newType?.properties && newType.properties.length) {
203
+ // 处理泛型的内容要取到值
204
+ const StructureJson = newType.toJSON();
205
+ const newStructure = new Structure(StructureJson);
206
+ newStructure.properties.forEach((item: StructureProperty | EntityProperty) => {
207
+ const itemType = item?.typeAnnotation?.typeKey;
208
+ if (itemType === 'T' && /\<([^()]+)\>/g.exec(typeKey)) {
209
+ const newTypes = /\<([^()]+)\>/g.exec(typeKey);
210
+ // 找到当前原来的类型
211
+ const contentType = getPlatformType(newTypes[1]);
212
+ const typeNamespace = contentType.substring(0, contentType.lastIndexOf('.'));
213
+ const typeName = contentType.substring(contentType.lastIndexOf('.') + 1, contentType.length);
214
+ item.typeAnnotation = new TypeAnnotation({
215
+ typeKind: 'reference',
216
+ typeNamespace,
217
+ typeName,
218
+ });
219
+ }
220
+ });
221
+ const index = nodeMap.get(newType) || 0;
222
+ if (index) {
223
+ nodeMap.set(newType, index + 1);
224
+ } else {
225
+ nodeMap.set(newType, 1);
226
+ }
227
+ // 最多保留3层
228
+ if (index < 3) {
229
+ item.children = formatVariableData(newStructure.properties, node, item);
230
+ }
231
+ }
232
+ }
168
233
  // 格式化变量数据
169
234
  export function formatVariableData(data: unknown | variableItem[], node: BaseNode, parent?: any) {
170
235
  if (Array.isArray(data)) {
171
236
  let result = data.map((item) => {
172
- // value需要拼接生成
173
- item.value = parent ? `${parent.value}.${item.text}` : item.text;
174
- item.name = item.text;
237
+ item.children = [];
175
238
  // 当前结构的typeAnnotation
176
239
  let typeAnnotation;
177
- let type;
240
+ // 当前的类型如 app.entitys.entity1 nasl.core.String
241
+ let typeKey: string;
178
242
 
179
243
  if (item.completionDetail) {
180
- let type = formatTs2TypeString(item.completionDetail.displayParts as Array<{ text: string; kind: string }>);
181
- typeAnnotation = getCompletionDetailType(type);
182
- type = getPlatformType(type);
244
+ // 当前节点的完整类型,主要是在有T的内容使用 nasl.list<Enum1> 内部匹配内容给里面子集的T赋值类型
245
+ const currentType: string = formatTs2TypeString(item.completionDetail.displayParts as Array<{ text: string; kind: string }>);
246
+ typeAnnotation = getCompletionDetailType(currentType);
247
+ typeKey = getPlatformType(currentType);
248
+ } else if (item instanceof StructureProperty) {
249
+ typeKey = item?.typeAnnotation?.typeKey;
183
250
  }
184
251
  // 如果没有父节点就是Identifier
185
252
  if (!parent) {
253
+ // value需要拼接生成
254
+ item.value = parent ? `${parent.value}.${item.text}` : item.text;
255
+ item.name = item.text;
186
256
  const identifier = new Identifier({ name: item.name });
187
257
  // 携带上当前的类型
188
258
  identifier.typeAnnotation = typeAnnotation;
189
259
  item.expression = identifier;
190
260
  } else {
261
+ item.value = `${parent.value}.${item.name}`;
191
262
  const memberExpression = new MemberExpression({
192
263
  object: parent.expression,
193
264
  property: new Identifier({ name: item.name }),
@@ -196,19 +267,18 @@ export function formatVariableData(data: unknown | variableItem[], node: BaseNod
196
267
  memberExpression.typeAnnotation = typeAnnotation;
197
268
  item.expression = memberExpression;
198
269
  }
199
- if (item.children) {
200
- item.children = formatVariableData(item.children, node, item);
270
+ // 如果有类型而且类型不是没有子集的类型,就把他当前的类型拿到
271
+ if (typeKey && !isNoChildType(typeKey)) {
272
+ nextFindTypeChild(typeKey, item, parent, node);
201
273
  }
274
+ const completionProperty = new CompletionProperty(item);
202
275
  if (!parent) {
203
- const completionProperty = new CompletionProperty(item);
204
276
  // 变量 param return 在这里添加图标
205
277
  completionProperty.icon = getNodeiconFromLogic(completionProperty, node);
206
- return completionProperty;
207
278
  } else {
208
- const completionProperty = new CompletionProperty(item);
209
279
  completionProperty.icon = 'refProperty';
210
- return completionProperty;
211
280
  }
281
+ return completionProperty;
212
282
  });
213
283
 
214
284
  /**
@@ -409,7 +479,7 @@ function getCurrentLogic(node: BaseNode,
409
479
  completionProperty.icon = 'logic';
410
480
  return completionProperty;
411
481
  });
412
- result.push({ name: '逻辑', children: logicVariable, expanded: true, icon: 'category' });
482
+ result.push({ name: '逻辑', children: logicVariable, expanded: false, icon: 'category' });
413
483
  }
414
484
  }
415
485
 
@@ -436,10 +506,10 @@ export async function getMemberIdentifier(node: BaseNode) {
436
506
 
437
507
  // 这个可能需要自己算一下
438
508
  const result = [
439
- { name: '字面量', children: literals, expanded: true, icon: 'category' },
440
- { name: '枚举', children: newEnums, expanded: true, icon: 'category' },
441
- { name: '变量', children: completionData, expanded: true, icon: 'category' },
442
- { name: '公共变量', children: globalVariable, expanded: true, icon: 'category' },
509
+ { name: '字面量', children: literals, expanded: false, icon: 'category' },
510
+ { name: '枚举', children: newEnums, expanded: false, icon: 'category' },
511
+ { name: '变量', children: completionData, expanded: false, icon: 'category' },
512
+ { name: '公共变量', children: globalVariable, expanded: false, icon: 'category' },
443
513
  // { name: '流程变量', children: [] },
444
514
  ];
445
515
  getCurrentLogic(node, result);
@@ -463,19 +533,9 @@ export function getEnumsIdentifier(node: BaseNode): CompletionProperty[] {
463
533
  // 获取变量
464
534
  export async function getVariableIdentifier(node: BaseNode): Promise<CompletionProperty[]> {
465
535
  let completionData: CompletionProperty[] = [new CompletionProperty({})];
466
- if (node instanceof Identifier || node instanceof MemberExpression) {
467
- const value = (node as Identifier | MemberExpression).getValue();
468
- if (value) {
469
- const completion = (await naslServer.getValueSelectCompletion(node, value)) as variableItem[];
470
- completionData = formatVariableData(completion, node);
471
- } else {
472
- const nextCompletion = await naslServer.getFieldKeySelectCompletion(node, '');
473
- completionData = formatVariableData(nextCompletion, node);
474
- }
475
- } else {
476
- const nextCompletion = await naslServer.getFieldKeySelectCompletion(node, '');
477
- completionData = formatVariableData(nextCompletion, node);
478
- }
536
+ // 只获取第一层内容
537
+ const nextCompletion = await naslServer.getFieldKeySelectCompletion(node, '');
538
+ completionData = formatVariableData(nextCompletion, node);
479
539
  return completionData;
480
540
  }
481
541
 
@@ -1,6 +1,7 @@
1
1
  import Constant from '@nasl/concepts/Constant__';
2
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
+ import { isNoChildType, nextFindTypeChild } from './getMemberIdentifier';
4
5
  function alphaUpper(name: string) {
5
6
  if (!name) {
6
7
  return '';
@@ -250,20 +251,20 @@ export function genCompletionProperty(prefix: string[] = []):(v: Variable | Para
250
251
  if (t.length) {
251
252
  prevalue = `${t.join('.')}.`;
252
253
  }
253
- const hasChild = ['reference', 'generic'].includes(v.typeAnnotation.typeKind);
254
- const cp = new CompletionProperty({
254
+ const noChildType = isNoChildType(v.typeAnnotation.typeKey);
255
+ const item = {
255
256
  expression: m || p,
256
- noFurther: !hasChild,
257
257
  name: v.name,
258
258
  value: prevalue + v.name,
259
+ };
259
260
 
260
- });
261
- console.log(cp.value);
262
- cp.icon = v.concept;
263
-
264
- if (hasChild) {
265
- cp.children = [new CompletionProperty()];
261
+ if (!noChildType) {
262
+ nextFindTypeChild(v.typeAnnotation.typeKey, item, null, v);
266
263
  }
264
+
265
+ const cp = new CompletionProperty(item);
266
+ console.log(cp.value, v);
267
+ cp.icon = v.concept;
267
268
  return cp;
268
269
  };
269
270
  }
@@ -307,7 +308,6 @@ export function getProcessVariableSuggestions(node: Logic, abandonConstant: bool
307
308
  const cp = new CompletionProperty({
308
309
  name: us.name,
309
310
  value: us.name,
310
- noFurther: true,
311
311
  children: [
312
312
  ...us.returns.map(genCompletionProperty([process.name, us.name])),
313
313
  ...(abandonConstant ? [] : us.constants.map(genCompletionProperty([process.name, us.name]))),
@@ -321,7 +321,6 @@ export function getProcessVariableSuggestions(node: Logic, abandonConstant: bool
321
321
  const processVariables = new CompletionProperty({
322
322
  name: process.name,
323
323
  value: process.name,
324
- noFurther: true,
325
324
  children: [
326
325
  ...process.params.map(genCompletionProperty([process.name])),
327
326
  ...process.returns.map(genCompletionProperty([process.name])),
@@ -335,7 +334,6 @@ export function getProcessVariableSuggestions(node: Logic, abandonConstant: bool
335
334
  name: processElem.name,
336
335
  value: processElem.name,
337
336
  icon: processElem.type,
338
- noFurther: true,
339
337
  children: processElem.variables.map(genCompletionProperty([process.name, processElem.name])),
340
338
  });
341
339
  scopeVariable.isProcess = true;
@@ -348,7 +346,6 @@ export function getProcessVariableSuggestions(node: Logic, abandonConstant: bool
348
346
  name: processElem.name,
349
347
  value: processElem.name,
350
348
  icon: processElem.type,
351
- noFurther: true,
352
349
  children: processElem.constants.map(genCompletionProperty([process.name, processElem.name])),
353
350
  });
354
351
  scopeVariable.isProcess = true;
@@ -360,7 +357,6 @@ export function getProcessVariableSuggestions(node: Logic, abandonConstant: bool
360
357
  name: processElem.name,
361
358
  value: processElem.name,
362
359
  icon: processElem.type,
363
- noFurther: true,
364
360
  children: [
365
361
  ...processElem.variables.map(genCompletionProperty([process.name, processElem.name])),
366
362
  ...processElem.returns.map(genCompletionProperty([process.name, processElem.name])),
@@ -457,7 +453,6 @@ export function getProcessVariableSuggestionsAll(node: ProcessElement) {
457
453
  const cp = new CompletionProperty({
458
454
  name: us.name,
459
455
  value: us.name,
460
- noFurther: true,
461
456
  children: [
462
457
  ...us.returns.map(node => deduceTypeAnnotation(app, node, node.typeAnnotation, [process.name, us.name], [])),
463
458
  ...us.constants.map(node => deduceTypeAnnotation(app, node, node.typeAnnotation, [process.name, us.name], [])),
@@ -472,7 +467,6 @@ export function getProcessVariableSuggestionsAll(node: ProcessElement) {
472
467
  const processVariables = new CompletionProperty({
473
468
  name: process.name,
474
469
  value: process.name,
475
- noFurther: true,
476
470
  children: [
477
471
  ...process.params.map(node => deduceTypeAnnotation(app, node, node.typeAnnotation, [process.name], [])),
478
472
  ...process.returns.map(node => deduceTypeAnnotation(app, node, node.typeAnnotation, [process.name], [])),
@@ -487,7 +481,6 @@ export function getProcessVariableSuggestionsAll(node: ProcessElement) {
487
481
  name: processElem.name,
488
482
  value: processElem.name,
489
483
  icon: processElem.type,
490
- noFurther: true,
491
484
  children: processElem.variables.map(node => deduceTypeAnnotation(app, node, node.typeAnnotation, [process.name, processElem.name], [])),
492
485
  });
493
486
  scopeVariable.expanded = true;
@@ -501,7 +494,6 @@ export function getProcessVariableSuggestionsAll(node: ProcessElement) {
501
494
  name: processElem.name,
502
495
  value: processElem.name,
503
496
  icon: processElem.type,
504
- noFurther: true,
505
497
  children: processElem.constants.map(node => deduceTypeAnnotation(app, node, node.typeAnnotation, [process.name, processElem.name], [])),
506
498
  });
507
499
  scopeVariable.expanded = true;
@@ -514,7 +506,6 @@ export function getProcessVariableSuggestionsAll(node: ProcessElement) {
514
506
  name: processElem.name,
515
507
  value: processElem.name,
516
508
  icon: processElem.type,
517
- noFurther: true,
518
509
  children: [
519
510
  ...processElem.variables.map(node => deduceTypeAnnotation(app, node, node.typeAnnotation, [process.name, processElem.name], [])),
520
511
  ...processElem.returns.map(node => deduceTypeAnnotation(app, node, node.typeAnnotation, [process.name, processElem.name], [])),
@@ -1262,7 +1262,10 @@ const naslServer = {
1262
1262
  }
1263
1263
  // params修改 查找View不需要修改
1264
1264
  // 逻辑改名,触发了在定义里面的,element定义,的值,直接掠过
1265
- if (minRange.node instanceof View && (node instanceof Logic || node instanceof Param)) {
1265
+ /**
1266
+ 修改枚举名 引发查找到view ,以为viewElement有一个类型,但是渲染了两次,就过滤掉找到view的 内容
1267
+ */
1268
+ if (minRange.node instanceof View && (node instanceof Logic || node instanceof Param || node instanceof Enum)) {
1266
1269
  /**
1267
1270
  * 这里过滤一下,一些查找引用,重复的内容,直接屏蔽掉,防止操作重复
1268
1271
  * 因为在生成的时候 ,可能弄了一些副作用的引用
@@ -1492,7 +1495,7 @@ const naslServer = {
1492
1495
  * @returns 当前节点,最后输出所有节点
1493
1496
  */
1494
1497
  _recursionCreateResult(root: QuoteNode, map: Map<QuoteNode, Array<QuoteNode>>) {
1495
- const children = map.get(root).map((item: QuoteNode) => naslServer._recursionCreateResult(item, map));
1498
+ const children = (map.get(root) || []).map((item: QuoteNode) => naslServer._recursionCreateResult(item, map));
1496
1499
  if (children && children.length) {
1497
1500
  root.children = children;
1498
1501
  }
@@ -251,14 +251,6 @@ export async function joinEntity(callQueryComponent: CallQueryComponent, entity:
251
251
  propertyName: joinInfo.rightProperty.name,
252
252
  }),
253
253
  }));
254
- const structureProperty = StructureProperty.from(NaslNode.StructureProperty({
255
- name: utils.firstLowerCase(entity.name),
256
- typeAnnotation: NaslTypeAnnotation.Reference({
257
- typeNamespace: entity.getNamespace(),
258
- typeName: entity.name,
259
- }),
260
- }), recordStructure, 'properties');
261
- recordStructure.addProperty(structureProperty);
262
254
  } else {
263
255
  queryJoinExpression.onExpressions.push(NaslLogicItem.BinaryExpression({
264
256
  operator: '==',
@@ -274,6 +266,14 @@ export async function joinEntity(callQueryComponent: CallQueryComponent, entity:
274
266
  }),
275
267
  }));
276
268
  }
269
+ const structureProperty = StructureProperty.from(NaslNode.StructureProperty({
270
+ name: utils.firstLowerCase(entity.name),
271
+ typeAnnotation: NaslTypeAnnotation.Reference({
272
+ typeNamespace: entity.getNamespace(),
273
+ typeName: entity.name,
274
+ }),
275
+ }), recordStructure, 'properties');
276
+ recordStructure.addProperty(structureProperty);
277
277
  const newJoinPartLogicItem = QueryJoinExpression.from(queryJoinExpression, callQueryComponent, 'joinParts');
278
278
  from.addJoinPart(newJoinPartLogicItem);
279
279
  callQueryComponent.saveStructure();