@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
@@ -538,6 +538,49 @@ class NaslServer {
538
538
  }
539
539
  return '';
540
540
  }
541
+ async getDataSchemaStructureOrTypeAnnotation(node) {
542
+ if (!(node instanceof concepts_1.ViewElement))
543
+ return;
544
+ const { currentSource, fileNode } = this.getCurrentSource(node);
545
+ const quickInfo = await this._getTypeQuickinfo({
546
+ file: fileNode.getEmbeddedFilePath(),
547
+ line: (0, translator_1.lsp2tspNumber)(currentSource.range.start.line),
548
+ offset: (0, translator_1.lsp2tspNumber)(currentSource.range.start.character) + `new nasl.ui.`.length,
549
+ });
550
+ if (quickInfo.responseRequired) {
551
+ const displayString = quickInfo?.response?.displayString || '';
552
+ const flag = displayString.includes('<') && displayString.includes('>');
553
+ if (!flag)
554
+ return;
555
+ const types = /\<([^()]+)\>/g.exec(displayString);
556
+ let typeStr = types && types[1];
557
+ const app = node.app;
558
+ if (typeStr.includes('__name: "AStructure_')) {
559
+ const properties = [];
560
+ typeStr
561
+ .replace(/([^:\s]+):\s+([^;]+);/g, ($1, name, typeKey) => {
562
+ if (name === '__name')
563
+ return;
564
+ typeKey = `app.${typeKey}`;
565
+ const keys = typeKey.split('.');
566
+ const typeName = keys.pop();
567
+ const typeNamespace = keys.join('.');
568
+ properties.push(concepts_1.StructureProperty.from({
569
+ name,
570
+ typeAnnotation: concepts_1.TypeAnnotation.from({
571
+ typeKind: 'reference',
572
+ typeName,
573
+ typeNamespace,
574
+ })
575
+ }));
576
+ return '';
577
+ });
578
+ return concepts_1.TypeAnnotation.createTypeAnonymousStructure(properties);
579
+ }
580
+ else if (typeStr.startsWith('structures'))
581
+ return app.findNodeByCompleteName(`app.${typeStr}`);
582
+ }
583
+ }
541
584
  /**
542
585
  * ts的 quickInfo方法,查询指定位置的详情
543
586
  * @param args 文件信息数组
@@ -904,41 +947,37 @@ class NaslServer {
904
947
  const jsCode = nodeIn.toJS();
905
948
  if (!jsCode.includes(`${node.name} = `))
906
949
  return;
907
- // 逻辑内局部变量、输出参数、输入参数过滤
908
- if (nodeIn.logic?.variables.find((lVar) => jsCode.includes(`${lVar.name} = `))
909
- || nodeIn.logic?.returns.find((lRet) => jsCode.includes(`${lRet.name} = `))
910
- || nodeIn.logic?.params.find((lPar) => jsCode.includes(`${lPar.name} = `))
911
- || nodeIn.logic?.virtualParams.find((vParam) => jsCode.includes(`${vParam.name} = `)))
912
- return;
913
- if (node instanceof concepts_1.Variable
914
- && node.parentNode instanceof concepts_1.View
915
- && (nodeIn.logic?.params.find((param) => jsCode.includes(param.name))
916
- || nodeIn.logic?.virtualParams.find((vParam) => jsCode.includes(vParam.name))
917
- || nodeIn.logic?.variables.find((variable) => jsCode.includes(variable.name)))) {
950
+ // 页面局部变量
951
+ if (node instanceof concepts_1.Variable && node.parentNode instanceof concepts_1.View) {
952
+ // 跟页面局部变量无关的赋值过滤
953
+ if (!jsCode.includes(`this.${node.name} = `))
954
+ return;
918
955
  // 直接赋值 logic 内局部变量、输入参数直接提示系统无法推断类型
919
- if (!nodeIn.tsErrorDetail) {
920
- const diagnostic = {
921
- node: nodeIn,
922
- severity: 'error',
923
- message: `页面${nodeTypeName} ${node.name} 赋值页面逻辑内局部变量或输入参数时,系统无法推导类型。`,
924
- };
925
- nodeIn.tsErrorDetail = diagnostic;
926
- diagnostics.push(diagnostic);
956
+ if (nodeIn.logic?.params.find((param) => jsCode.includes(param.name))
957
+ || nodeIn.logic?.virtualParams.find((vParam) => jsCode.includes(vParam.name))
958
+ || nodeIn.logic?.variables.find((variable) => jsCode.includes(variable.name))) {
959
+ if (!nodeIn.tsErrorDetail) {
960
+ const diagnostic = {
961
+ node: nodeIn,
962
+ severity: 'error',
963
+ message: `页面${nodeTypeName} ${node.name} 赋值页面逻辑内局部变量或输入参数时,系统无法推导类型。`,
964
+ };
965
+ nodeIn.tsErrorDetail = diagnostic;
966
+ diagnostics.push(diagnostic);
967
+ }
968
+ msg = '系统无法推断类型。';
927
969
  }
928
- msg = '系统无法推断类型。';
929
970
  }
930
- else {
931
- if (!nodeIn.tsErrorDetail) {
932
- const diagnostic = {
933
- node: nodeIn,
934
- severity: 'error',
935
- message: `${nodeIn.label}左边 ${node.name} 未设置类型,右边必须为有返回值的内容。`,
936
- };
937
- nodeIn.tsErrorDetail = diagnostic;
938
- diagnostics.push(diagnostic);
939
- }
940
- msg = '必须赋值有返回值的内容。';
971
+ if (!nodeIn.tsErrorDetail) {
972
+ const diagnostic = {
973
+ node: nodeIn,
974
+ severity: 'error',
975
+ message: `${nodeIn.label}左边 ${node.name} 未设置类型,右边必须为有返回值的内容。`,
976
+ };
977
+ nodeIn.tsErrorDetail = diagnostic;
978
+ diagnostics.push(diagnostic);
941
979
  }
980
+ msg = '必须赋值有返回值的内容。';
942
981
  }
943
982
  });
944
983
  if (!msg)
@@ -2218,7 +2257,6 @@ class NaslServer {
2218
2257
  const nodeTypeAnnotation = this.getCurrentNodeKnownTypeAnnotation(node);
2219
2258
  if (nodeTypeAnnotation) {
2220
2259
  types.set(node, nodeTypeAnnotation);
2221
- node.__TypeAnnotation = nodeTypeAnnotation;
2222
2260
  return;
2223
2261
  }
2224
2262
  // 要通过自己或者依赖关系拿的,二次遍历
@@ -2233,7 +2271,7 @@ class NaslServer {
2233
2271
  'Return',
2234
2272
  'Variable',
2235
2273
  ].includes(node.concept) && node.typeAnnotation) {
2236
- node.__TypeAnnotation = node.typeAnnotation;
2274
+ types.set(node, node.typeAnnotation);
2237
2275
  return;
2238
2276
  }
2239
2277
  if (![
@@ -2300,7 +2338,9 @@ class NaslServer {
2300
2338
  }
2301
2339
  args.push(fileDetail);
2302
2340
  });
2341
+ console.time('请求');
2303
2342
  const resultMap = (await this.getNaslNodeTypeFull(args)).response;
2343
+ console.timeEnd('请求');
2304
2344
  // console.log(resultMap);
2305
2345
  // const result = (await this.getNaslNodeQuickInfoFull(args)).response;
2306
2346
  // console.log(result);
@@ -2314,22 +2354,19 @@ class NaslServer {
2314
2354
  const nodeTypeAnnotation = (0, formatTsUtils_1.type2TypeAnnotation)(item?.[0]?.nodeType);
2315
2355
  // console.log(newQuickInfoNodes[index].node, nodeTypeAnnotation, nodeTypeAnnotation?.typeKey);
2316
2356
  types.set(newQuickInfoNodes[index].node, nodeTypeAnnotation);
2317
- newQuickInfoNodes[index].node.__TypeAnnotation = nodeTypeAnnotation;
2318
- newQuickInfoNodes[index].node.__nodeType = item?.[0]?.nodeType;
2357
+ newQuickInfoNodes[index].node.__nodeType = Object.freeze(item?.[0]?.nodeType);
2319
2358
  // console.log('方案1:', displayString1);
2320
2359
  });
2321
2360
  getFromOthers.forEach((type, node) => {
2322
2361
  if (node instanceof concepts_1.Assignment) {
2323
2362
  if (!types.get(node.left)) {
2324
2363
  types.set(node.left, types.get(node.right));
2325
- node.left.__TypeAnnotation = types.get(node.right);
2326
2364
  }
2327
2365
  }
2328
2366
  else if (node instanceof concepts_1.Argument) {
2329
2367
  // 如果Argument,但是没可以用的类型,就用原来logic的参数类型
2330
2368
  const argType = this.getArgumentTypeAnnotation(node, newQuickInfoNodes, types);
2331
2369
  types.set(node, argType);
2332
- node.__TypeAnnotation = argType.typeAnnotation;
2333
2370
  }
2334
2371
  else if (node instanceof concepts_1.MatchCase) {
2335
2372
  // matchCase的类型
@@ -2338,7 +2375,6 @@ class NaslServer {
2338
2375
  const last = node.body[node.body.length - 1];
2339
2376
  if (last.__TypeAnnotation) {
2340
2377
  types.set(node, last.__TypeAnnotation);
2341
- node.__TypeAnnotation = last.__TypeAnnotation;
2342
2378
  }
2343
2379
  }
2344
2380
  }
@@ -2346,6 +2382,14 @@ class NaslServer {
2346
2382
  // 重置类型状态
2347
2383
  types.forEach((value, node) => {
2348
2384
  node.__isCorrectTypeAnnotation = true;
2385
+ if (value) {
2386
+ if (value instanceof concepts_1.TypeAnnotation) {
2387
+ node.__TypeAnnotation = Object.freeze(value);
2388
+ }
2389
+ else if (value.typeAnnotation) {
2390
+ node.__TypeAnnotation = Object.freeze(value.typeAnnotation);
2391
+ }
2392
+ }
2349
2393
  });
2350
2394
  // newQuickInfoNodes.forEach((itemDetail, index) => {
2351
2395
  // const { node, filePath } = itemDetail;
@@ -2443,6 +2487,7 @@ class NaslServer {
2443
2487
  }
2444
2488
  // 增量标注
2445
2489
  async IncrementalAnnotationJSON(records) {
2490
+ console.time('增量标注');
2446
2491
  const nodes = [];
2447
2492
  records.forEach((record) => {
2448
2493
  const fileNode = this.file2NodeMap.get(record.filePath);
@@ -2461,6 +2506,7 @@ class NaslServer {
2461
2506
  }
2462
2507
  });
2463
2508
  await this.getQuickInfoNodesTypeMap(nodes);
2509
+ console.timeEnd('增量标注');
2464
2510
  }
2465
2511
  annotationToJson(typesMap, json) {
2466
2512
  typesMap.forEach((value, node) => {