@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.
Files changed (84) hide show
  1. package/out/bak/translator.js +1 -1
  2. package/out/bak/translator.js.map +1 -1
  3. package/out/concepts/LogicItem__.js.map +1 -1
  4. package/out/concepts/Logic__.js +4 -4
  5. package/out/concepts/Logic__.js.map +1 -1
  6. package/out/concepts/MatchExpression__.d.ts +97 -0
  7. package/out/concepts/MatchExpression__.js +281 -0
  8. package/out/concepts/MatchExpression__.js.map +1 -0
  9. package/out/concepts/Match__.js +1 -1
  10. package/out/concepts/Match__.js.map +1 -1
  11. package/out/concepts/MemberExpression__.js.map +1 -1
  12. package/out/concepts/OqlQueryComponent__.js.map +1 -1
  13. package/out/concepts/Param__.js +2 -2
  14. package/out/concepts/Param__.js.map +1 -1
  15. package/out/concepts/Return__.js +1 -1
  16. package/out/concepts/Return__.js.map +1 -1
  17. package/out/concepts/StringInterpolation__.d.ts +16 -16
  18. package/out/concepts/StringInterpolation__.js +12 -12
  19. package/out/concepts/StringInterpolation__.js.map +1 -1
  20. package/out/concepts/ValidationRule__.js.map +1 -1
  21. package/out/concepts/Variable__.js +1 -1
  22. package/out/concepts/Variable__.js.map +1 -1
  23. package/out/concepts/View__.js +2 -2
  24. package/out/concepts/View__.js.map +1 -1
  25. package/out/server/naslServer.d.ts +2 -1
  26. package/out/server/naslServer.js +84 -38
  27. package/out/server/naslServer.js.map +1 -1
  28. package/out/templator/genQueryComponent.d.ts +2 -2
  29. package/out/templator/genQueryComponent.js +4 -1
  30. package/out/templator/genQueryComponent.js.map +1 -1
  31. package/out/templator/sql-parser/index.d.ts +1 -0
  32. package/out/templator/sql-parser/index.js +228 -0
  33. package/out/templator/sql-parser/index.js.map +1 -0
  34. package/out/templator/sql-parser/parser.js +26664 -0
  35. package/out/templator/sql-parser/parser.js.map +1 -0
  36. package/package.json +3 -4
  37. package/src/automate/engine/dist/index.dev.js +517 -0
  38. package/src/bak/translator.js +1 -1
  39. package/src/common/dist/BaseNode.js +1101 -0
  40. package/src/concepts/CallInterface__.ts +9 -9
  41. package/src/concepts/Destination__.ts +9 -9
  42. package/src/concepts/ExternalDestination__.ts +5 -5
  43. package/src/concepts/LogicItem__.ts +4 -0
  44. package/src/concepts/Logic__.ts +42 -5
  45. package/src/concepts/Match__.ts +21 -1
  46. package/src/concepts/MemberExpression__.ts +11 -0
  47. package/src/concepts/OqlQueryComponent__.ts +7 -0
  48. package/src/concepts/Param__.ts +3 -2
  49. package/src/concepts/Return__.ts +5 -1
  50. package/src/concepts/StringInterpolation__.ts +26 -26
  51. package/src/concepts/UnaryExpression__.ts +4 -4
  52. package/src/concepts/ValidationRule__.ts +1 -1
  53. package/src/concepts/Variable__.ts +1 -1
  54. package/src/concepts/ViewElement__.ts +1 -1
  55. package/src/concepts/View__.ts +2 -2
  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 +473 -0
  60. package/src/concepts/dist/CallInterface__.js +533 -0
  61. package/src/concepts/dist/CallLogic__.js +864 -0
  62. package/src/concepts/dist/ForEachStatement__.js +426 -0
  63. package/src/concepts/dist/MatchCase__.js +587 -0
  64. package/src/concepts/dist/MemberExpression__.js +348 -0
  65. package/src/concepts/dist/Param__.js +537 -0
  66. package/src/concepts/dist/Return__.js +493 -0
  67. package/src/generator/dist/genBundleFiles.js +414 -0
  68. package/src/server/dist/formatTsUtils.js +683 -0
  69. package/src/server/dist/naslServer.js +3396 -0
  70. package/src/server/naslServer.ts +84 -39
  71. package/src/service/storage/dist/init.js +541 -0
  72. package/src/templator/genQueryComponent.ts +8 -3
  73. package/ts-worker/dist/webpack.config.dev.js +104 -0
  74. package/ts-worker/lib/cancellationToken.js +67 -0
  75. package/ts-worker/lib/dist/tsserver.dev.js +22953 -0
  76. package/ts-worker/lib/harness.js +1 -1
  77. package/ts-worker/sources/lib/dist/tsserver.dev.js +22912 -0
  78. package/ts-worker/src/start.js +1 -1
  79. package/ts-worker/webpack.config.js +3 -1
  80. package/dist/bundle.js +0 -3962
  81. package/dist/bundle.js.LICENSE.txt +0 -16
  82. package/out/generator/release.d.ts +0 -1
  83. package/out/generator/release.js +0 -51
  84. package/out/generator/release.js.map +0 -1
@@ -614,6 +614,48 @@ export class NaslServer {
614
614
  }
615
615
  return '';
616
616
  }
617
+ async getDataSchemaStructureOrTypeAnnotation(node: ViewElement) {
618
+ if (!(node instanceof ViewElement)) return;
619
+
620
+ const { currentSource, fileNode } = this.getCurrentSource(node);
621
+ const quickInfo = await this._getTypeQuickinfo({
622
+ file: (fileNode as FileNode).getEmbeddedFilePath(),
623
+ line: lsp2tspNumber(currentSource.range.start.line),
624
+ offset: lsp2tspNumber(currentSource.range.start.character) + `new nasl.ui.`.length,
625
+ });
626
+ if (quickInfo.responseRequired) {
627
+ const displayString = quickInfo?.response?.displayString || '';
628
+ const flag = displayString.includes('<') && displayString.includes('>');
629
+ if(!flag) return;
630
+
631
+ const types = /\<([^()]+)\>/g.exec(displayString);
632
+ let typeStr = types && types[1];
633
+ const app = node.app;
634
+ if (typeStr.includes('__name: "AStructure_')) {
635
+ const properties: StructureProperty[] = [];
636
+ typeStr
637
+ .replace(/([^:\s]+):\s+([^;]+);/g, ($1, name, typeKey) => {
638
+ if(name === '__name') return;
639
+
640
+ typeKey = `app.${typeKey}`;
641
+ const keys = typeKey.split('.');
642
+ const typeName = keys.pop();
643
+ const typeNamespace = keys.join('.');
644
+ properties.push(StructureProperty.from({
645
+ name,
646
+ typeAnnotation: TypeAnnotation.from({
647
+ typeKind: 'reference',
648
+ typeName,
649
+ typeNamespace,
650
+ })
651
+ }))
652
+ return '';
653
+ });
654
+ return TypeAnnotation.createTypeAnonymousStructure(properties);
655
+ } else if(typeStr.startsWith('structures'))
656
+ return app.findNodeByCompleteName(`app.${typeStr}`);
657
+ }
658
+ }
617
659
 
618
660
  /**
619
661
  * ts的 quickInfo方法,查询指定位置的详情
@@ -997,40 +1039,37 @@ export class NaslServer {
997
1039
  const jsCode = nodeIn.toJS();
998
1040
  if (!jsCode.includes(`${node.name} = `))
999
1041
  return;
1000
- // 逻辑内局部变量、输出参数、输入参数过滤
1001
- if (nodeIn.logic?.variables.find((lVar) => jsCode.includes(`${lVar.name} = `))
1002
- || nodeIn.logic?.returns.find((lRet) => jsCode.includes(`${lRet.name} = `))
1003
- || nodeIn.logic?.params.find((lPar) => jsCode.includes(`${lPar.name} = `))
1004
- || nodeIn.logic?.virtualParams.find((vParam) => jsCode.includes(`${vParam.name} = `)))
1005
- return;
1006
- if (node instanceof Variable
1007
- && node.parentNode instanceof View
1008
- && (nodeIn.logic?.params.find((param) => jsCode.includes(param.name))
1009
- || nodeIn.logic?.virtualParams.find((vParam) => jsCode.includes(vParam.name))
1010
- || nodeIn.logic?.variables.find((variable) => jsCode.includes(variable.name)))) {
1042
+ // 页面局部变量
1043
+ if (node instanceof Variable && node.parentNode instanceof View) {
1044
+ // 跟页面局部变量无关的赋值过滤
1045
+ if (!jsCode.includes(`this.${node.name} = `))
1046
+ return;
1011
1047
  // 直接赋值 logic 内局部变量、输入参数直接提示系统无法推断类型
1012
- if (!nodeIn.tsErrorDetail) {
1013
- const diagnostic = {
1014
- node: nodeIn,
1015
- severity: 'error',
1016
- message: `页面${nodeTypeName} ${node.name} 赋值页面逻辑内局部变量或输入参数时,系统无法推导类型。`,
1017
- };
1018
- nodeIn.tsErrorDetail = diagnostic;
1019
- diagnostics.push(diagnostic);
1020
- }
1021
- msg = '系统无法推断类型。';
1022
- } else {
1023
- if (!nodeIn.tsErrorDetail) {
1024
- const diagnostic = {
1025
- node: nodeIn,
1026
- severity: 'error',
1027
- message: `${nodeIn.label}左边 ${node.name} 未设置类型,右边必须为有返回值的内容。`,
1028
- };
1029
- nodeIn.tsErrorDetail = diagnostic;
1030
- diagnostics.push(diagnostic);
1048
+ if (nodeIn.logic?.params.find((param) => jsCode.includes(param.name))
1049
+ || nodeIn.logic?.virtualParams.find((vParam) => jsCode.includes(vParam.name))
1050
+ || nodeIn.logic?.variables.find((variable) => jsCode.includes(variable.name))) {
1051
+ if (!nodeIn.tsErrorDetail) {
1052
+ const diagnostic = {
1053
+ node: nodeIn,
1054
+ severity: 'error',
1055
+ message: `页面${nodeTypeName} ${node.name} 赋值页面逻辑内局部变量或输入参数时,系统无法推导类型。`,
1056
+ };
1057
+ nodeIn.tsErrorDetail = diagnostic;
1058
+ diagnostics.push(diagnostic);
1059
+ }
1060
+ msg = '系统无法推断类型。';
1031
1061
  }
1032
- msg = '必须赋值有返回值的内容。';
1033
1062
  }
1063
+ if (!nodeIn.tsErrorDetail) {
1064
+ const diagnostic = {
1065
+ node: nodeIn,
1066
+ severity: 'error',
1067
+ message: `${nodeIn.label}左边 ${node.name} 未设置类型,右边必须为有返回值的内容。`,
1068
+ };
1069
+ nodeIn.tsErrorDetail = diagnostic;
1070
+ diagnostics.push(diagnostic);
1071
+ }
1072
+ msg = '必须赋值有返回值的内容。';
1034
1073
  }
1035
1074
  });
1036
1075
  if (!msg)
@@ -2330,7 +2369,6 @@ export class NaslServer {
2330
2369
  const nodeTypeAnnotation = this.getCurrentNodeKnownTypeAnnotation(node);
2331
2370
  if (nodeTypeAnnotation) {
2332
2371
  types.set(node, nodeTypeAnnotation);
2333
- node.__TypeAnnotation = nodeTypeAnnotation;
2334
2372
  return;
2335
2373
  }
2336
2374
  // 要通过自己或者依赖关系拿的,二次遍历
@@ -2344,8 +2382,8 @@ export class NaslServer {
2344
2382
  if ([
2345
2383
  'Return',
2346
2384
  'Variable',
2347
- ].includes(node.concept) && (node as Return | Variable).typeAnnotation) {
2348
- node.__TypeAnnotation = (node as Return | Variable).typeAnnotation;
2385
+ ].includes(node.concept) && (node as Variable).typeAnnotation) {
2386
+ types.set(node, (node as Variable).typeAnnotation);
2349
2387
  return;
2350
2388
  }
2351
2389
  if (![
@@ -2408,7 +2446,9 @@ export class NaslServer {
2408
2446
  }
2409
2447
  args.push(fileDetail);
2410
2448
  });
2449
+ console.time('请求')
2411
2450
  const resultMap: any = (await this.getNaslNodeTypeFull(args)).response;
2451
+ console.timeEnd('请求')
2412
2452
 
2413
2453
  // console.log(resultMap);
2414
2454
 
@@ -2424,8 +2464,7 @@ export class NaslServer {
2424
2464
  const nodeTypeAnnotation = type2TypeAnnotation(item?.[0]?.nodeType);
2425
2465
  // console.log(newQuickInfoNodes[index].node, nodeTypeAnnotation, nodeTypeAnnotation?.typeKey);
2426
2466
  types.set(newQuickInfoNodes[index].node, nodeTypeAnnotation);
2427
- newQuickInfoNodes[index].node.__TypeAnnotation = nodeTypeAnnotation;
2428
- (newQuickInfoNodes[index].node as any).__nodeType = item?.[0]?.nodeType;
2467
+ (newQuickInfoNodes[index].node as any).__nodeType = Object.freeze(item?.[0]?.nodeType);
2429
2468
 
2430
2469
  // console.log('方案1:', displayString1);
2431
2470
  });
@@ -2433,13 +2472,11 @@ export class NaslServer {
2433
2472
  if (node instanceof Assignment) {
2434
2473
  if (!types.get(node.left)) {
2435
2474
  types.set(node.left, types.get(node.right));
2436
- node.left.__TypeAnnotation = (types.get(node.right) as TypeAnnotation);
2437
2475
  }
2438
2476
  } else if (node instanceof Argument) {
2439
2477
  // 如果Argument,但是没可以用的类型,就用原来logic的参数类型
2440
2478
  const argType = this.getArgumentTypeAnnotation(node, newQuickInfoNodes, (types as any));
2441
2479
  types.set(node, argType);
2442
- node.__TypeAnnotation = argType.typeAnnotation;
2443
2480
  } else if (node instanceof MatchCase) {
2444
2481
  // matchCase的类型
2445
2482
  // 直接从最后一项的返回值取,有就有没有就没有
@@ -2447,7 +2484,6 @@ export class NaslServer {
2447
2484
  const last = node.body[node.body.length - 1];
2448
2485
  if (last.__TypeAnnotation) {
2449
2486
  types.set(node, last.__TypeAnnotation);
2450
- node.__TypeAnnotation = last.__TypeAnnotation;
2451
2487
  }
2452
2488
  }
2453
2489
  }
@@ -2456,6 +2492,13 @@ export class NaslServer {
2456
2492
  // 重置类型状态
2457
2493
  types.forEach((value, node) => {
2458
2494
  node.__isCorrectTypeAnnotation = true;
2495
+ if (value) {
2496
+ if (value instanceof TypeAnnotation) {
2497
+ node.__TypeAnnotation = (Object.freeze(value) as TypeAnnotation);
2498
+ } else if (value.typeAnnotation) {
2499
+ node.__TypeAnnotation = (Object.freeze(value.typeAnnotation) as TypeAnnotation);
2500
+ }
2501
+ }
2459
2502
  });
2460
2503
  // newQuickInfoNodes.forEach((itemDetail, index) => {
2461
2504
  // const { node, filePath } = itemDetail;
@@ -2561,6 +2604,7 @@ export class NaslServer {
2561
2604
 
2562
2605
  // 增量标注
2563
2606
  async IncrementalAnnotationJSON(records: DiagnosticRecord[]) {
2607
+ console.time('增量标注');
2564
2608
  const nodes: QuickInfoNodes = [];
2565
2609
  records.forEach((record) => {
2566
2610
  const fileNode = this.file2NodeMap.get(record.filePath);
@@ -2580,6 +2624,7 @@ export class NaslServer {
2580
2624
  });
2581
2625
 
2582
2626
  await this.getQuickInfoNodesTypeMap(nodes);
2627
+ console.timeEnd('增量标注');
2583
2628
  }
2584
2629
 
2585
2630
  annotationToJson(typesMap: Map<BaseNode, TypeAnnotation | {