@lcap/nasl 2.18.0-beta.5 → 2.18.0-beta.7

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 (88) hide show
  1. package/out/common/BaseNode.js +1 -0
  2. package/out/common/BaseNode.js.map +1 -1
  3. package/out/concepts/BatchAssignment__.js +63 -46
  4. package/out/concepts/BatchAssignment__.js.map +1 -1
  5. package/out/concepts/CallLogic__.d.ts +2 -1
  6. package/out/concepts/CallLogic__.js +26 -11
  7. package/out/concepts/CallLogic__.js.map +1 -1
  8. package/out/concepts/Destination__.d.ts +2 -1
  9. package/out/concepts/Destination__.js +90 -22
  10. package/out/concepts/Destination__.js.map +1 -1
  11. package/out/concepts/Logic__.js +6 -7
  12. package/out/concepts/Logic__.js.map +1 -1
  13. package/out/concepts/MatchExpression__.d.ts +97 -0
  14. package/out/concepts/MatchExpression__.js +281 -0
  15. package/out/concepts/MatchExpression__.js.map +1 -0
  16. package/out/concepts/ViewElement__.js +1 -1
  17. package/out/concepts/ViewElement__.js.map +1 -1
  18. package/out/concepts/View__.js +4 -0
  19. package/out/concepts/View__.js.map +1 -1
  20. package/out/generator/genBundleFiles.js +32 -182
  21. package/out/generator/genBundleFiles.js.map +1 -1
  22. package/out/generator/genMetaData.d.ts +1 -10
  23. package/out/generator/genMetaData.js +189 -50
  24. package/out/generator/genMetaData.js.map +1 -1
  25. package/out/generator/genReleaseBody.js +11 -2
  26. package/out/generator/genReleaseBody.js.map +1 -1
  27. package/out/server/extendBaseNode.js +4 -18
  28. package/out/server/extendBaseNode.js.map +1 -1
  29. package/out/server/formatTsUtils.d.ts +1 -2
  30. package/out/server/formatTsUtils.js +30 -47
  31. package/out/server/formatTsUtils.js.map +1 -1
  32. package/out/server/getProcesses.js +1 -1
  33. package/out/server/getProcesses.js.map +1 -1
  34. package/out/server/naslServer.js +8 -7
  35. package/out/server/naslServer.js.map +1 -1
  36. package/out/server/translator.js +19 -4
  37. package/out/server/translator.js.map +1 -1
  38. package/out/templator/sql-parser/index.d.ts +1 -0
  39. package/out/templator/sql-parser/index.js +228 -0
  40. package/out/templator/sql-parser/index.js.map +1 -0
  41. package/out/templator/sql-parser/parser.js +26664 -0
  42. package/out/templator/sql-parser/parser.js.map +1 -0
  43. package/package.json +2 -2
  44. package/sandbox/stdlib/dist/nasl.logging.js +0 -0
  45. package/sandbox/stdlib/nasl.util.ts +1 -1
  46. package/src/automate/engine/dist/index.dev.js +517 -0
  47. package/src/common/BaseNode.ts +1 -0
  48. package/src/common/dist/BaseNode.js +1101 -0
  49. package/src/concepts/BatchAssignment__.ts +66 -50
  50. package/src/concepts/CallLogic__.ts +26 -11
  51. package/src/concepts/Destination__.ts +92 -22
  52. package/src/concepts/Logic__.ts +6 -7
  53. package/src/concepts/ViewElement__.ts +8 -29
  54. package/src/concepts/View__.ts +4 -0
  55. package/src/concepts/basics/stdlib/dist/nasl.util.js +1503 -0
  56. package/src/concepts/basics/stdlib/dist/reference2TypeAnnotationList.js +24 -0
  57. package/src/concepts/dist/Anchor__.js +179 -0
  58. package/src/concepts/dist/Assignment__.js +301 -0
  59. package/src/concepts/dist/CallFunction__.js +513 -0
  60. package/src/concepts/dist/CallInterface__.js +533 -0
  61. package/src/concepts/dist/CallLogic__.js +892 -0
  62. package/src/concepts/dist/ForEachStatement__.js +426 -0
  63. package/src/concepts/dist/MatchCase__.js +587 -0
  64. package/src/concepts/dist/Match__.js +631 -0
  65. package/src/concepts/dist/MemberExpression__.js +348 -0
  66. package/src/concepts/dist/Param__.js +538 -0
  67. package/src/concepts/dist/Return__.js +494 -0
  68. package/src/concepts/dist/Variable__.js +537 -0
  69. package/src/concepts/dist/ViewElement__.js +1680 -0
  70. package/src/generator/dist/genBundleFiles.js +261 -0
  71. package/src/generator/dist/genMetaData.js +249 -0
  72. package/src/generator/genBundleFiles.ts +34 -219
  73. package/src/generator/genMetaData.ts +182 -77
  74. package/src/generator/genReleaseBody.ts +10 -3
  75. package/src/server/dist/formatTsUtils.js +683 -0
  76. package/src/server/dist/naslServer.js +3474 -0
  77. package/src/server/extendBaseNode.ts +4 -19
  78. package/src/server/formatTsUtils.ts +30 -46
  79. package/src/server/getProcesses.ts +1 -1
  80. package/src/server/naslServer.ts +8 -7
  81. package/src/server/translator.ts +18 -4
  82. package/src/service/storage/dist/init.js +572 -0
  83. package/ts-worker/dist/webpack.config.dev.js +108 -0
  84. package/dist/bundle.js +0 -3962
  85. package/dist/bundle.js.LICENSE.txt +0 -16
  86. package/out/generator/release.d.ts +0 -1
  87. package/out/generator/release.js +0 -51
  88. package/out/generator/release.js.map +0 -1
@@ -161,19 +161,6 @@ BaseNode.prototype.prepareDelete = async function prepareDelete() {
161
161
  refsList = refsList.filter((item) =>
162
162
  // 因为ui组件本身会多渲染一次,就先过滤一个
163
163
  !(item.lineText.includes(': nasl.ui.')));
164
- // 删除参数单独处理
165
- if (node instanceof Param) {
166
- const methodRefs: tsProtocol.ReferencesResponseItem[] = [];
167
- refsList.forEach((item) => {
168
- // 入参查找引用,查到logic 和自己,内容完全一样,就保留一个
169
- const find = methodRefs.find((findItem) => item.lineText === findItem.lineText);
170
- if (!find) {
171
- methodRefs.push(item);
172
- }
173
- });
174
- refsList = methodRefs;
175
- }
176
-
177
164
  // delete的弹框展示
178
165
  const confirmParms = {
179
166
  actionType: 'delete',
@@ -182,7 +169,7 @@ BaseNode.prototype.prepareDelete = async function prepareDelete() {
182
169
  icon: 'warning',
183
170
  };
184
171
  let callback = null;
185
- if (refsList.length <= 1) {
172
+ if (refsList.length <= 1 || (node instanceof Param && node.parentNode instanceof Logic && refsList.length <= 2)) {
186
173
  // 页面组件直接删除然后return
187
174
  if (node instanceof ViewElement) {
188
175
  this.delete();
@@ -235,6 +222,7 @@ BaseNode.prototype.prepareDelete = async function prepareDelete() {
235
222
  App.emit('collect:start', {
236
223
  actionMsg: '删除参数',
237
224
  });
225
+ const Index = node.getIndexOfParent();
238
226
  this.delete();
239
227
  refsList.forEach((record) => {
240
228
  const fileNode = naslServer.file2NodeMap.get(record.file);
@@ -242,11 +230,8 @@ BaseNode.prototype.prepareDelete = async function prepareDelete() {
242
230
  return null;
243
231
  const minRange: MinRange = naslServer._findMinRange(record, fileNode as FileNode);
244
232
  if (minRange) {
245
- if (minRange.node instanceof CallLogic) {
246
- minRange.node.setCalleeArgName(parentNode as Logic);
247
- }
248
- if (minRange.node instanceof Destination) {
249
- minRange.node.setViewArgument(parentNode as View);
233
+ if (minRange.node instanceof CallLogic || minRange.node instanceof Destination) {
234
+ minRange.node.deleteCalleeArg(Index);
250
235
  }
251
236
  }
252
237
  });
@@ -247,13 +247,9 @@ function findNode(typeKey: string, node: BaseNode) {
247
247
  * 获取下一级的节点进行递归
248
248
  * @param typeKey 当前节点的类型,主要为了取出内部的 T中的实际类型
249
249
  * @param item 当前节点的内容
250
- * @param parent 父级节点的内容
251
250
  * @param node 获取变量框的位置
252
251
  */
253
- export function nextFindTypeChild(typeKey: string, item: any, parent: any, node: BaseNode) {
254
- // 有一个当前树分支的全部节点的node map,用作防止数据无限递归,只保留3层
255
- const nodeMap = parent ? parent.nodeMap : new Map();
256
- item.nodeMap = nodeMap;
252
+ export function nextFindTypeChild(typeKey: string, item: any, node: BaseNode) {
257
253
  const newType = findNode(typeKey, node);
258
254
  if ((newType as Structure)?.properties && (newType as Structure).properties.length) {
259
255
  // 处理泛型的内容要取到值
@@ -274,16 +270,7 @@ export function nextFindTypeChild(typeKey: string, item: any, parent: any, node:
274
270
  });
275
271
  }
276
272
  });
277
- const index = nodeMap.get(newType) || 0;
278
- if (index) {
279
- nodeMap.set(newType, index + 1);
280
- } else {
281
- nodeMap.set(newType, 1);
282
- }
283
- // 最多保留3层
284
- if (index < 3) {
285
- item.children = formatVariableData(newStructure.properties, node, item);
286
- }
273
+ item.children = formatVariableData(newStructure.properties, node, item);
287
274
  }
288
275
  }
289
276
 
@@ -359,7 +346,7 @@ function getAStructureScopeType(type: string, parent: any, node: BaseNode) {
359
346
  newItem.concept = 'CompletionProperty';
360
347
  // 如果有类型而且类型不是没有子集的类型,就把他当前的类型拿到
361
348
  if (item.typeKey && !isNoChildType(item.typeKey)) {
362
- newItem.children = nextObjectTypeChild(item.typeKey, newItem, parentItem, node);
349
+ newItem.children = nextObjectTypeChild(item.typeKey, newItem, node);
363
350
  }
364
351
  const completionProperty = new CompletionProperty(newItem);
365
352
  completionProperty.icon = 'refProperty';
@@ -395,9 +382,6 @@ function getAStructureScopeType(type: string, parent: any, node: BaseNode) {
395
382
  function getAStructureObjectStringType(type: string, parent: any, node: BaseNode) {
396
383
  let newType = type.replaceAll(' ', '').replaceAll('\n', '').replace(/__name:"AStructure_\w{8}";/g, '');
397
384
  newType = newType.substring(1, newType.length - 1);
398
- if (!parent.keyMap) {
399
- parent.keyMap = new Map();
400
- }
401
385
  if (/\{([^()]+)\}/.exec(newType)) {
402
386
  newType = newType.replace(/\{([^()]+)\}/, '');
403
387
  }
@@ -437,7 +421,7 @@ function getAStructureObjectStringType(type: string, parent: any, node: BaseNode
437
421
  newItem.concept = 'CompletionProperty';
438
422
  // 如果有类型而且类型不是没有子集的类型,就把他当前的类型拿到
439
423
  if (item.typeKey && !isNoChildType(item.typeKey)) {
440
- newItem.children = nextObjectTypeChild(getPlatformType(item.typeKey), newItem, parentItem, node);
424
+ newItem.children = nextObjectTypeChild(getPlatformType(item.typeKey), newItem, node);
441
425
  }
442
426
  const completionProperty = new CompletionProperty(newItem);
443
427
 
@@ -451,13 +435,7 @@ function getAStructureObjectStringType(type: string, parent: any, node: BaseNode
451
435
  completionProperty.icon = getNodeiconFromLogic(completionProperty, node);
452
436
  return completionProperty;
453
437
  }
454
- function nextObjectTypeChild(typeKey: string, item: any, parent: any, node: BaseNode) {
455
- // 有一个当前树分支的全部节点的node map,用作防止数据无限递归,只保留3层
456
- const nodeMap = parent.nodeMap || new Map();
457
- item.nodeMap = nodeMap; // 有一个当前树分支的全部节点的node map,用作防止数据无限递归,只保留3层
458
-
459
- const keyMap = parent.keyMap;
460
- item.keyMap = keyMap;
438
+ function nextObjectTypeChild(typeKey: string, item: any, node: BaseNode) {
461
439
  const newType = findNode(typeKey, node);
462
440
  if ((newType as Structure)?.properties && (newType as Structure).properties.length) {
463
441
  // 处理泛型的内容要取到值
@@ -478,16 +456,7 @@ function nextObjectTypeChild(typeKey: string, item: any, parent: any, node: Base
478
456
  });
479
457
  }
480
458
  });
481
- const index = nodeMap.get(newType) || 0;
482
- if (index) {
483
- nodeMap.set(newType, index + 1);
484
- } else {
485
- nodeMap.set(newType, 1);
486
- }
487
- // 最多保留3层
488
- if (index < 3) {
489
- return formatVariableData(newStructure.properties, node, item);
490
- }
459
+ return formatVariableData(newStructure.properties, node, item);
491
460
  }
492
461
  }
493
462
 
@@ -533,17 +502,32 @@ export function formatVariableData(data: unknown | variableItem[], node: BaseNod
533
502
  item.name = item.text;
534
503
  const identifier = new Identifier({ name: item.name });
535
504
  item.expression = identifier;
505
+ item.typeKey = typeKey;
536
506
  } else {
537
507
  item.value = `${parent.value}.${item.name}`;
508
+ const object: any = BaseNode.from(parent.expression.toJSON());
538
509
  const memberExpression = new MemberExpression({
539
- object: parent.expression,
510
+ object,
540
511
  property: new Identifier({ name: item.name }),
541
512
  });
542
513
  item.expression = memberExpression;
514
+ item.variableParent = parent;
515
+ item.typeKey = typeKey;
543
516
  }
544
517
  // 如果有类型而且类型不是没有子集的类型,就把他当前的类型拿到
545
518
  if (typeKey && !isNoChildType(typeKey)) {
546
- nextFindTypeChild(typeKey, item, parent, node);
519
+ let currentParent = item;
520
+ let typeKeyIndex = 0;
521
+ while (currentParent.variableParent) {
522
+ currentParent = currentParent.variableParent;
523
+ if (currentParent.typeKey === typeKey) {
524
+ typeKeyIndex++;
525
+ }
526
+ }
527
+ // 向上找到3次一样的就结束
528
+ if (typeKeyIndex < 3) {
529
+ nextFindTypeChild(typeKey, item, node);
530
+ }
547
531
  }
548
532
  // 如果是从实体或者数据结构取的属性,就需要重置一下类型
549
533
  item.concept = 'CompletionProperty';
@@ -633,20 +617,20 @@ function sortFirstVariableData(result: CompletionProperty[], node: BaseNode) {
633
617
  }
634
618
 
635
619
  export function formatFrontEndVariables(frontEndVariables: Array<Variable>) {
636
- const result = frontEndVariables.map((item) => {
637
- const namespace = item.getNamespace();
620
+ const result = frontEndVariables.map((itemNode) => {
621
+ const namespace = itemNode.getNamespace();
638
622
  const newItem: any = {
639
- name: item.name,
640
- value: item.name,
623
+ name: itemNode.name,
624
+ value: itemNode.name,
641
625
  expression: new Identifier({
642
- name: item.name,
626
+ name: itemNode.name,
643
627
  namespace,
644
628
  }),
645
629
  };
646
- const noChildType = isNoChildType(item.typeAnnotation.typeKey);
630
+ const noChildType = isNoChildType(itemNode.typeAnnotation.typeKey);
647
631
 
648
632
  if (!noChildType) {
649
- nextFindTypeChild(item.typeAnnotation.typeKey, newItem, null, item);
633
+ nextFindTypeChild(itemNode.typeAnnotation.typeKey, newItem, itemNode);
650
634
  }
651
635
  const completionProperty = new CompletionProperty(newItem);
652
636
  completionProperty.icon = 'frontendVariable';
@@ -283,7 +283,7 @@ export function genCompletionProperty(prefix: string[] = []):(v: Variable | Para
283
283
  };
284
284
 
285
285
  if (!noChildType) {
286
- nextFindTypeChild(v.typeAnnotation.typeKey, item, null, v);
286
+ nextFindTypeChild(v.typeAnnotation.typeKey, item, v);
287
287
  }
288
288
 
289
289
  const cp = new CompletionProperty(item);
@@ -1035,6 +1035,9 @@ export class NaslServer {
1035
1035
  // 子页面内部逻辑过滤
1036
1036
  if (nodeIn.view !== fileNode)
1037
1037
  return;
1038
+ // 当局部变量、输出参数属于页面内逻辑时,需过滤同页面下不同逻辑下的同名变量
1039
+ if (node.logic && node.logic !== nodeIn.logic)
1040
+ return;
1038
1041
  // 跟变量无关的赋值过滤
1039
1042
  const jsCode = nodeIn.toJS();
1040
1043
  if (!jsCode.includes(`${node.name} = `))
@@ -1983,12 +1986,8 @@ export class NaslServer {
1983
1986
  const minRange: MinRange = this._findMinRange(record, fileNode as FileNode);
1984
1987
  if (minRange) {
1985
1988
  // 如果找到节点是callLogic就去更新
1986
- if (minRange.node instanceof CallLogic && node instanceof Param) {
1987
- minRange.node.setCalleeArgName(parantNode as Logic);
1988
- }
1989
- // 如果节点参数增加页面也要更新
1990
- if (minRange.node instanceof Destination && node instanceof Param) {
1991
- minRange.node.setViewArgument(parantNode as View);
1989
+ if ((minRange.node instanceof CallLogic || minRange.node instanceof Destination) && node instanceof Param) {
1990
+ minRange.node.addCalleeArg(parantNode as any);
1992
1991
  }
1993
1992
  }
1994
1993
  });
@@ -2502,7 +2501,9 @@ export class NaslServer {
2502
2501
  }
2503
2502
  }
2504
2503
  } catch (err) {
2505
- console.log(err);
2504
+ if (globalThis.window) {
2505
+ console.log(err);
2506
+ }
2506
2507
  }
2507
2508
  });
2508
2509
  // newQuickInfoNodes.forEach((itemDetail, index) => {
@@ -86,6 +86,8 @@ function transformType(tsType: string): string {
86
86
  return '无返回值';
87
87
  else if (tsType === '__elements')
88
88
  return '页面元素';
89
+ else if (tsType === '__unknown__')
90
+ return '无效';
89
91
  else if (tsType === 'extensions')
90
92
  return '拓展模块';
91
93
  else if (tsType === 'Promise<void>')
@@ -173,8 +175,13 @@ const TS_RULES: Array<{
173
175
  }> = [
174
176
  {
175
177
  re: /Object literal may only specify known properties, and '(.+?)' does not exist in type/,
176
- result: '当前参数$1,不可用',
177
- transforms: [outOriginalvalue],
178
+ result: '当前参数$1,不可用。',
179
+ transforms: [transformType],
180
+ },
181
+ {
182
+ re: /Object literal may only specify known properties, but '(.+?)' does not exist in type/,
183
+ result: '当前参数$1,不可用。',
184
+ transforms: [transformType],
178
185
  },
179
186
  {
180
187
  re: /Argument of type '(.+?)' is not assignable to parameter of type '(.+?)'/,
@@ -494,8 +501,15 @@ export function naslNodeTranslateMessage(minRange: MinRange, tsErrorDetail: Diag
494
501
  }
495
502
  // 赋值左右侧类型不一致, 把文字换一下
496
503
  if (/Argument of type '(.+?)' is not assignable to parameter of type '(.+?)'/.exec(text) && node.parentNode instanceof Assignment) {
497
- // node = node.getAncestor('CallLogic');
498
- tsErrorDetail.message = tsErrorDetail.message.replace('参数类型不一致!传入类型:', '赋值:类型不一致!右边类型:').replace('接收类型:', '左边类型:');
504
+ // OQL 的返回类型报错需要转换翻译,其内部 SQL 语句的参数类型报错不转换翻译
505
+ if (node instanceof OqlQueryComponent) {
506
+ if ((node.getCurrentSource().currentSource.range.start.line + 1) === tsErrorDetail.originalDiagnostic.start.line) {
507
+ tsErrorDetail.message = tsErrorDetail.message.replace('参数类型不一致!传入类型:', '赋值:类型不一致!右边类型:').replace('接收类型:', '左边类型:');
508
+ }
509
+ } else {
510
+ // node = node.getAncestor('CallLogic');
511
+ tsErrorDetail.message = tsErrorDetail.message.replace('参数类型不一致!传入类型:', '赋值:类型不一致!右边类型:').replace('接收类型:', '左边类型:');
512
+ }
499
513
  }
500
514
  if (node instanceof Argument || node instanceof Anchor) {
501
515
  // if (/Type '(.+?)' is not assignable to type '(.+?)'./.exec(text)) {