@lcap/nasl 2.22.0-beta.0 → 2.22.0-beta.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 (276) hide show
  1. package/out/automate/engine/operators.d.ts +9 -0
  2. package/out/automate/engine/viewCache.d.ts +1 -0
  3. package/out/automate/template/myProcess.d.ts +1 -0
  4. package/out/common/BaseNode.d.ts +1 -0
  5. package/out/common/BaseNode.js +7 -1
  6. package/out/common/BaseNode.js.map +1 -1
  7. package/out/common/Command.d.ts +1 -1
  8. package/out/common/EventEmitter.d.ts +1 -1
  9. package/out/concepts/Abort__.js.map +1 -1
  10. package/out/concepts/Anchor__.js.map +1 -1
  11. package/out/concepts/AnonymousFunction__.js.map +1 -1
  12. package/out/concepts/App__.d.ts +22 -0
  13. package/out/concepts/App__.js +78 -12
  14. package/out/concepts/App__.js.map +1 -1
  15. package/out/concepts/Argument__.js.map +1 -1
  16. package/out/concepts/Assignee__.js.map +1 -1
  17. package/out/concepts/AssignmentLine__.js.map +1 -1
  18. package/out/concepts/Assignment__.js.map +1 -1
  19. package/out/concepts/Attribute__.js.map +1 -1
  20. package/out/concepts/BatchAssignment__.js.map +1 -1
  21. package/out/concepts/BinaryExpression__.js.map +1 -1
  22. package/out/concepts/BindAttribute__.js.map +1 -1
  23. package/out/concepts/BindDirective__.js.map +1 -1
  24. package/out/concepts/BindEvent__.js.map +1 -1
  25. package/out/concepts/BindStyle__.js.map +1 -1
  26. package/out/concepts/BooleanLiteral__.js.map +1 -1
  27. package/out/concepts/CallFunction__.js.map +1 -1
  28. package/out/concepts/CallInterface__.js +9 -1
  29. package/out/concepts/CallInterface__.js.map +1 -1
  30. package/out/concepts/CallLogic__.js +2 -1
  31. package/out/concepts/CallLogic__.js.map +1 -1
  32. package/out/concepts/CallQueryComponent__.d.ts +2 -0
  33. package/out/concepts/CallQueryComponent__.js +76 -24
  34. package/out/concepts/CallQueryComponent__.js.map +1 -1
  35. package/out/concepts/Comment__.js.map +1 -1
  36. package/out/concepts/CompletionProperty__.js.map +1 -1
  37. package/out/concepts/ConfigGroup__.js.map +1 -1
  38. package/out/concepts/ConfigPropertyValue__.js.map +1 -1
  39. package/out/concepts/ConfigProperty__.d.ts +4 -0
  40. package/out/concepts/ConfigProperty__.js +18 -1
  41. package/out/concepts/ConfigProperty__.js.map +1 -1
  42. package/out/concepts/Configuration__.js.map +1 -1
  43. package/out/concepts/Constant__.js.map +1 -1
  44. package/out/concepts/DataElement__.js.map +1 -1
  45. package/out/concepts/DataSource__.js.map +1 -1
  46. package/out/concepts/DatabaseTypeAnnotation__.js.map +1 -1
  47. package/out/concepts/Destination__.js +2 -2
  48. package/out/concepts/Destination__.js.map +1 -1
  49. package/out/concepts/End__.js.map +1 -1
  50. package/out/concepts/EntityIndex__.d.ts +1 -1
  51. package/out/concepts/EntityIndex__.js.map +1 -1
  52. package/out/concepts/EntityProperty__.d.ts +7 -2
  53. package/out/concepts/EntityProperty__.js +100 -1
  54. package/out/concepts/EntityProperty__.js.map +1 -1
  55. package/out/concepts/Entity__.d.ts +2 -1
  56. package/out/concepts/Entity__.js +30 -1
  57. package/out/concepts/Entity__.js.map +1 -1
  58. package/out/concepts/EnumItem__.js.map +1 -1
  59. package/out/concepts/Enum__.js.map +1 -1
  60. package/out/concepts/Event__.js.map +1 -1
  61. package/out/concepts/ExternalDestination__.js.map +1 -1
  62. package/out/concepts/ForEachStatement__.js.map +1 -1
  63. package/out/concepts/FrontendLibrary__.js.map +1 -1
  64. package/out/concepts/Frontend__.js.map +1 -1
  65. package/out/concepts/Function__.js.map +1 -1
  66. package/out/concepts/Identifier__.js +7 -0
  67. package/out/concepts/Identifier__.js.map +1 -1
  68. package/out/concepts/IfStatement__.js +2 -2
  69. package/out/concepts/IfStatement__.js.map +1 -1
  70. package/out/concepts/Integration__.d.ts +53 -0
  71. package/out/concepts/Integration__.js +143 -0
  72. package/out/concepts/Integration__.js.map +1 -0
  73. package/out/concepts/InterfaceParam__.js.map +1 -1
  74. package/out/concepts/Interface__.js.map +1 -1
  75. package/out/concepts/JSBlock__.js.map +1 -1
  76. package/out/concepts/JavaLogic__.d.ts +42 -0
  77. package/out/concepts/JavaLogic__.js +122 -0
  78. package/out/concepts/JavaLogic__.js.map +1 -0
  79. package/out/concepts/LogicItem__.d.ts +1 -1
  80. package/out/concepts/LogicItem__.js.map +1 -1
  81. package/out/concepts/Logic__.js +12 -7
  82. package/out/concepts/Logic__.js.map +1 -1
  83. package/out/concepts/MatchCase__.js.map +1 -1
  84. package/out/concepts/Match__.js +11 -6
  85. package/out/concepts/Match__.js.map +1 -1
  86. package/out/concepts/MemberExpression__.js +1 -1
  87. package/out/concepts/MemberExpression__.js.map +1 -1
  88. package/out/concepts/MicroApp__.d.ts +51 -0
  89. package/out/concepts/MicroApp__.js +113 -0
  90. package/out/concepts/MicroApp__.js.map +1 -0
  91. package/out/concepts/Module__.d.ts +20 -9
  92. package/out/concepts/Module__.js +72 -14
  93. package/out/concepts/Module__.js.map +1 -1
  94. package/out/concepts/Namespace__.js.map +1 -1
  95. package/out/concepts/NewComposite__.d.ts +1 -1
  96. package/out/concepts/NewComposite__.js +25 -11
  97. package/out/concepts/NewComposite__.js.map +1 -1
  98. package/out/concepts/NewList__.js.map +1 -1
  99. package/out/concepts/NewMap__.js.map +1 -1
  100. package/out/concepts/New__.js.map +1 -1
  101. package/out/concepts/NullLiteral__.js.map +1 -1
  102. package/out/concepts/NumericLiteral__.js.map +1 -1
  103. package/out/concepts/OqlQueryComponent__.js +1 -1
  104. package/out/concepts/OqlQueryComponent__.js.map +1 -1
  105. package/out/concepts/Param__.d.ts +1 -0
  106. package/out/concepts/Param__.js +5 -0
  107. package/out/concepts/Param__.js.map +1 -1
  108. package/out/concepts/Point__.js.map +1 -1
  109. package/out/concepts/ProcessComponent__.js.map +1 -1
  110. package/out/concepts/ProcessElement__.js.map +1 -1
  111. package/out/concepts/ProcessOutcome__.js.map +1 -1
  112. package/out/concepts/ProcessOutcomes__.js.map +1 -1
  113. package/out/concepts/Process__.js.map +1 -1
  114. package/out/concepts/QueryAggregateExpression__.js.map +1 -1
  115. package/out/concepts/QueryFieldExpression__.js.map +1 -1
  116. package/out/concepts/QueryFromExpression__.js.map +1 -1
  117. package/out/concepts/QueryGroupByExpression__.js.map +1 -1
  118. package/out/concepts/QueryJoinExpression__.js.map +1 -1
  119. package/out/concepts/QueryLimitExpression__.js.map +1 -1
  120. package/out/concepts/QueryOrderByExpression__.js.map +1 -1
  121. package/out/concepts/QuerySelectExpression__.d.ts +104 -16
  122. package/out/concepts/QuerySelectExpression__.js +99 -9
  123. package/out/concepts/QuerySelectExpression__.js.map +1 -1
  124. package/out/concepts/Rect__.js.map +1 -1
  125. package/out/concepts/Return__.js.map +1 -1
  126. package/out/concepts/Role__.js.map +1 -1
  127. package/out/concepts/SelectMembers__.js.map +1 -1
  128. package/out/concepts/Slot__.js.map +1 -1
  129. package/out/concepts/SqlQueryComponent__.js.map +1 -1
  130. package/out/concepts/Start__.js.map +1 -1
  131. package/out/concepts/StringInterpolation__.js.map +1 -1
  132. package/out/concepts/StringLiteral__.js.map +1 -1
  133. package/out/concepts/StructureProperty__.js.map +1 -1
  134. package/out/concepts/Structure__.js.map +1 -1
  135. package/out/concepts/SwitchCase__.js +2 -2
  136. package/out/concepts/SwitchCase__.js.map +1 -1
  137. package/out/concepts/SwitchStatement__.js.map +1 -1
  138. package/out/concepts/Theme__.js.map +1 -1
  139. package/out/concepts/Transactional__.js.map +1 -1
  140. package/out/concepts/TypeAnnotation__.js +8 -3
  141. package/out/concepts/TypeAnnotation__.js.map +1 -1
  142. package/out/concepts/TypeParam__.js.map +1 -1
  143. package/out/concepts/UnaryExpression__.js.map +1 -1
  144. package/out/concepts/Unparsed__.js.map +1 -1
  145. package/out/concepts/UseComponent__.js.map +1 -1
  146. package/out/concepts/ValidationRule__.js.map +1 -1
  147. package/out/concepts/Variable__.js.map +1 -1
  148. package/out/concepts/ViewBlock__.js.map +1 -1
  149. package/out/concepts/ViewComponent__.js.map +1 -1
  150. package/out/concepts/ViewElement__.js +26 -6
  151. package/out/concepts/ViewElement__.js.map +1 -1
  152. package/out/concepts/View__.d.ts +1 -1
  153. package/out/concepts/View__.js +3 -1
  154. package/out/concepts/View__.js.map +1 -1
  155. package/out/concepts/WhileStatement__.js.map +1 -1
  156. package/out/concepts/basics/stdlib/nasl.ui.js +15 -0
  157. package/out/concepts/basics/stdlib/nasl.ui.js.map +1 -1
  158. package/out/concepts/basics/stdlib/nasl.util.js +94 -0
  159. package/out/concepts/basics/stdlib/nasl.util.js.map +1 -1
  160. package/out/concepts/index__.d.ts +3 -0
  161. package/out/concepts/index__.js +3 -0
  162. package/out/concepts/index__.js.map +1 -1
  163. package/out/config.d.ts +1 -1
  164. package/out/decorators/index.d.ts +2 -2
  165. package/out/generator/genBundleFiles.js +20 -3
  166. package/out/generator/genBundleFiles.js.map +1 -1
  167. package/out/generator/genReleaseBody.js +2 -2
  168. package/out/generator/genReleaseBody.js.map +1 -1
  169. package/out/generator/icestark.d.ts +2 -0
  170. package/out/generator/icestark.js +48 -0
  171. package/out/generator/icestark.js.map +1 -0
  172. package/out/generator/microApp.d.ts +2 -0
  173. package/out/generator/microApp.js +35 -0
  174. package/out/generator/microApp.js.map +1 -0
  175. package/out/generator/permission.d.ts +1 -1
  176. package/out/generator/permission.js +0 -13
  177. package/out/generator/permission.js.map +1 -1
  178. package/out/generator/qiankun.d.ts +2 -0
  179. package/out/generator/qiankun.js +52 -0
  180. package/out/generator/qiankun.js.map +1 -0
  181. package/out/index.d.ts +1 -0
  182. package/out/index.js +1 -0
  183. package/out/index.js.map +1 -1
  184. package/out/manager/stepRecorder.d.ts +20 -0
  185. package/out/manager/stepRecorder.js +110 -0
  186. package/out/manager/stepRecorder.js.map +1 -0
  187. package/out/sentry/index.d.ts +5 -4
  188. package/out/sentry/index.js +9 -2
  189. package/out/sentry/index.js.map +1 -1
  190. package/out/server/formatTsUtils.d.ts +1 -1
  191. package/out/server/formatTsUtils.js +40 -14
  192. package/out/server/formatTsUtils.js.map +1 -1
  193. package/out/server/getLogics.js +38 -6
  194. package/out/server/getLogics.js.map +1 -1
  195. package/out/server/getMemberIdentifier.js +5 -4
  196. package/out/server/getMemberIdentifier.js.map +1 -1
  197. package/out/server/getProcesses.d.ts +3 -3
  198. package/out/server/getScope.d.ts +1 -1
  199. package/out/server/naslServer.d.ts +7 -3
  200. package/out/server/naslServer.js +270 -102
  201. package/out/server/naslServer.js.map +1 -1
  202. package/out/server/translator.js +25 -7
  203. package/out/server/translator.js.map +1 -1
  204. package/out/service/storage/init.d.ts +3 -3
  205. package/out/service/storage/init.js +6 -0
  206. package/out/service/storage/init.js.map +1 -1
  207. package/out/templator/genCreateBlock.js +6 -1
  208. package/out/templator/genCreateBlock.js.map +1 -1
  209. package/out/templator/genQueryComponent.js +20 -6
  210. package/out/templator/genQueryComponent.js.map +1 -1
  211. package/out/templator/genUpdateBlock.js +7 -1
  212. package/out/templator/genUpdateBlock.js.map +1 -1
  213. package/out/templator/utils.d.ts +16 -0
  214. package/out/templator/utils.js +2 -0
  215. package/out/templator/utils.js.map +1 -1
  216. package/out/translator/index.d.ts +1 -1
  217. package/out/translator/lsp.d.ts +3 -3
  218. package/out/utils/index.d.ts +4 -4
  219. package/package.json +1 -1
  220. package/sandbox/stdlib/nasl.ui.ts +16 -11
  221. package/sandbox/stdlib/nasl.util.ts +4 -0
  222. package/sandbox/stdlib/nasl.validation.ts +2 -2
  223. package/src/automate/upgrader/2.17.js +1 -1
  224. package/src/common/BaseNode.ts +10 -2
  225. package/src/concepts/App__.ts +90 -46
  226. package/src/concepts/CallInterface__.ts +9 -1
  227. package/src/concepts/CallLogic__.ts +2 -1
  228. package/src/concepts/CallQueryComponent__.ts +73 -82
  229. package/src/concepts/ConfigProperty__.ts +18 -1
  230. package/src/concepts/Destination__.ts +2 -20
  231. package/src/concepts/EntityProperty__.ts +102 -8
  232. package/src/concepts/Entity__.ts +31 -8
  233. package/src/concepts/Identifier__.ts +9 -2
  234. package/src/concepts/IfStatement__.ts +2 -2
  235. package/src/concepts/Integration__.ts +162 -0
  236. package/src/concepts/JavaLogic__.ts +129 -0
  237. package/src/concepts/LogicItem__.ts +1 -1
  238. package/src/concepts/Logic__.ts +12 -45
  239. package/src/concepts/Match__.ts +10 -5
  240. package/src/concepts/MemberExpression__.ts +1 -1
  241. package/src/concepts/MicroApp__.ts +118 -0
  242. package/src/concepts/Module__.ts +106 -79
  243. package/src/concepts/NewComposite__.ts +23 -11
  244. package/src/concepts/OqlQueryComponent__.ts +1 -1
  245. package/src/concepts/Param__.ts +3 -0
  246. package/src/concepts/QueryFieldExpression__.ts +0 -7
  247. package/src/concepts/QuerySelectExpression__.ts +206 -30
  248. package/src/concepts/SwitchCase__.ts +2 -2
  249. package/src/concepts/TypeAnnotation__.ts +8 -42
  250. package/src/concepts/ViewElement__.ts +24 -6
  251. package/src/concepts/View__.ts +3 -24
  252. package/src/concepts/basics/stdlib/nasl.ui.ts +15 -0
  253. package/src/concepts/basics/stdlib/nasl.util.ts +94 -0
  254. package/src/concepts/index__.ts +3 -0
  255. package/src/generator/genBundleFiles.ts +22 -4
  256. package/src/generator/genReleaseBody.ts +2 -2
  257. package/src/generator/icestark.ts +45 -0
  258. package/src/generator/microApp.ts +32 -0
  259. package/src/generator/permission.ts +1 -15
  260. package/src/generator/qiankun.ts +49 -0
  261. package/src/index.ts +1 -0
  262. package/src/manager/stepRecorder.ts +112 -0
  263. package/src/sentry/index.ts +8 -2
  264. package/src/server/formatTsUtils.ts +42 -14
  265. package/src/server/getLogics.ts +41 -6
  266. package/src/server/getMemberIdentifier.ts +5 -4
  267. package/src/server/naslServer.ts +270 -101
  268. package/src/server/translator.ts +25 -7
  269. package/src/service/storage/init.ts +7 -0
  270. package/src/templator/genCreateBlock.ts +6 -1
  271. package/src/templator/genQueryComponent.ts +22 -8
  272. package/src/templator/genUpdateBlock.ts +7 -1
  273. package/src/templator/utils.ts +2 -0
  274. package/ts-worker/src/index.js +1 -4
  275. package/src/manager/history.ts +0 -0
  276. package/src/manager/problem.ts +0 -0
@@ -72,6 +72,7 @@ import {
72
72
  LogicItem,
73
73
  JSBlock,
74
74
  NewComposite,
75
+ Integration,
75
76
  } from '../concepts';
76
77
  import { lsp2tspNumber, SourceMap, SourceMapItem } from '../translator';
77
78
  import axios from '../service/storage';
@@ -88,6 +89,8 @@ import { EventEmitter } from '../common/EventEmitter';
88
89
 
89
90
  import { traverse } from '../utils';
90
91
 
92
+ import { Decimal } from 'decimal.js';
93
+
91
94
  const EmbeddedTSFileLineMap: { [name: string]: number } = {
92
95
  Entity: 3,
93
96
  };
@@ -255,12 +258,12 @@ export class NaslServer {
255
258
  const changeNode = changeEvent.target;
256
259
  const { fileNode } = this.getCurrentSource(changeNode);
257
260
  if (changeNode !== fileNode || !changeEvent.field) {
258
- const findIndex = this.changeStackList.findIndex((changeStackItem: EventPayload) => {
261
+ const findLastIndex = this.changeStackList.findLastIndex((changeStackItem: EventPayload) => {
259
262
  const target = changeStackItem.target;
260
263
  const { fileNode: targetFileNode } = this.getCurrentSource(target);
261
264
  return targetFileNode === fileNode;
262
265
  });
263
- if (findIndex === this.changeStackList.length - 1) {
266
+ if (findLastIndex === this.changeStackList.length - 1) {
264
267
  this.changeStackList.pop();
265
268
  }
266
269
  }
@@ -305,6 +308,10 @@ export class NaslServer {
305
308
  }
306
309
 
307
310
  contentToFile(module: Module | App, results: Array<ReturnType<Structure['toEmbeddedTSFile']>>) {
311
+ // 禁用的依赖库不生成代码 区分 undefined 和 false
312
+ if (module instanceof Module && module.type === 'extension' && module.enable === false) {
313
+ return;
314
+ }
308
315
  module.structures.forEach((structure) => {
309
316
  try {
310
317
  const result = structure.toEmbeddedTSFile();
@@ -622,6 +629,9 @@ export class NaslServer {
622
629
  * fileNode
623
630
  */
624
631
  const { currentSource, fileNode } = this.getCurrentSource(callFunction);
632
+ if (!currentSource) {
633
+ return [];
634
+ }
625
635
  try {
626
636
  const quickInfo = await this._getTypeQuickinfo({
627
637
  file: (fileNode as FileNode).getEmbeddedFilePath(),
@@ -658,8 +668,8 @@ export class NaslServer {
658
668
  }
659
669
 
660
670
  /**
661
- * 获取表单的dataschema类型
662
- * @param node 当前表单节点
671
+ * 获取表格的dataschema类型
672
+ * @param node 当前表格节点
663
673
  * @param allType 是不是需要全部类型 默认不要
664
674
  * @returns 全部类型的str 或者 最后一个.后的内容
665
675
  */
@@ -667,7 +677,9 @@ export class NaslServer {
667
677
  if (!(node instanceof ViewElement))
668
678
  return;
669
679
  const { currentSource, fileNode } = this.getCurrentSource(node);
670
-
680
+ if (!currentSource) {
681
+ return;
682
+ }
671
683
  const quickInfo = await this._getTypeQuickinfo({
672
684
  file: (fileNode as FileNode).getEmbeddedFilePath(),
673
685
  line: lsp2tspNumber(currentSource.range.start.line),
@@ -725,6 +737,9 @@ export class NaslServer {
725
737
  return;
726
738
 
727
739
  const { currentSource, fileNode } = this.getCurrentSource(node);
740
+ if (!currentSource) {
741
+ return;
742
+ }
728
743
  const quickInfo = await this._getTypeQuickinfo({
729
744
  file: (fileNode as FileNode).getEmbeddedFilePath(),
730
745
  line: lsp2tspNumber(currentSource.range.start.line),
@@ -926,11 +941,6 @@ export class NaslServer {
926
941
  if (diagnostic.severity === 'warning') {
927
942
  record.suggestionDiagnostics.push(diagnostic);
928
943
  return null;
929
- } else if (currentNode.concept === 'DataSource' && diagnostic.originalDiagnostic?.text === 'DataSource connection error') {
930
- // 数据源警告类型降级
931
- diagnostic.severity = 'warning';
932
- record.suggestionDiagnostics.push(diagnostic);
933
- return null;
934
944
  } else if (currentNode.concept === 'OqlQueryComponent') {
935
945
  // OQL别名错误降级为警告
936
946
  if (diagnostic.originalDiagnostic && diagnostic.originalDiagnostic?.text.includes('__OQL_ALIAS_WARNING__')) {
@@ -996,6 +1006,12 @@ export class NaslServer {
996
1006
  } else if ((diag.text).includes(` is declared but its value is never read.`)) {
997
1007
  // 局部变量和输入变量未使用的警告
998
1008
  if ((node.concept === 'View' || node.concept === 'Logic') && node.parentNode.concept !== 'Module') {
1009
+ /**
1010
+ * javalogic不用提示
1011
+ */
1012
+ if (node.concept === 'Logic' && this._isJavalogic(node as Logic)) {
1013
+ return;
1014
+ }
999
1015
  const minRange = this._findMinRange(diag as unknown as tsProtocol.DiagnosticWithFileName, node as FileNode);
1000
1016
  if (minRange) {
1001
1017
  /**
@@ -1029,6 +1045,18 @@ export class NaslServer {
1029
1045
  return records;
1030
1046
  }
1031
1047
 
1048
+ /**
1049
+ * 判断是否是Javalogic
1050
+ */
1051
+ _isJavalogic(node: Logic) {
1052
+ const body = node.body || [];
1053
+
1054
+ if (body && body.length && body[0].concept === 'JavaLogic') {
1055
+ return true;
1056
+ }
1057
+ return false;
1058
+ }
1059
+
1032
1060
  /**
1033
1061
  * 额外的建议诊断
1034
1062
  * @param fileNode 文件级别的节点
@@ -1038,7 +1066,8 @@ export class NaslServer {
1038
1066
  const diagnostics: Diagnostic[] = [];
1039
1067
  if (fileNode instanceof Logic || fileNode instanceof View) {
1040
1068
  fileNode?.sourceMap.forEach((value, node) => {
1041
- if (node instanceof Match) {
1069
+ // 表达式模式才需要校验返回值类型
1070
+ if (node instanceof Match && node.isExpression) {
1042
1071
  const { cases, expression } = node || {};
1043
1072
  const typeAnnotationMap: any = {};
1044
1073
  // 最多数的类型
@@ -1530,14 +1559,14 @@ export class NaslServer {
1530
1559
  if (!propertyValue.value && fileNode.name !== 'defaultDS') {
1531
1560
  const diagnostic = {
1532
1561
  node: fileNode,
1533
- severity: 'warning',
1562
+ severity: 'error',
1534
1563
  message: `数据源配置:数据源${property.name}${propertyValue.env === 'dev' ? '开发环境' : '生产环境'}未配置数据信息`,
1535
1564
  // 保留原来的内容方便查询一些问题
1536
1565
  originalDiagnostic: {
1537
1566
  fileName: '',
1538
1567
  start: <any>null,
1539
1568
  end: <any>null,
1540
- category: 'warning',
1569
+ category: 'error',
1541
1570
  text: `Data Source is not config`,
1542
1571
  },
1543
1572
  };
@@ -1588,107 +1617,218 @@ export class NaslServer {
1588
1617
  const { origin, properties } = entity || {};
1589
1618
  if (dbType && !['excel', 'table'].includes(origin) && Array.isArray(properties) && properties.length) {
1590
1619
  properties.forEach((property) => {
1591
- const { typeAnnotation, databaseTypeAnnotation, rules } = property || {};
1592
- if (property && databaseTypeAnnotation) {
1593
- const { typeName: databaseTypeName } = databaseTypeAnnotation;
1620
+ if (property) {
1621
+ const { typeAnnotation, databaseTypeAnnotation, rules } = property;
1594
1622
  const { typeName } = typeAnnotation || {};
1595
- const dataBaseTypeMap = property.dataBaseTypeMap || {};
1596
- const dataBaseTyp = dataBaseTypeMap[databaseTypeName];
1597
- const diagnostic: any = {
1623
+ const rulesMap: any = {};
1624
+ if (Array.isArray(rules)) {
1625
+ rules.forEach((rule) => {
1626
+ const match = rule.match(/^([^()]+)\(([\d\-.]+)\)$/);
1627
+ if (match) {
1628
+ const [, key, value] = match;
1629
+ rulesMap[key] = value;
1630
+ }
1631
+ });
1632
+ }
1633
+ const diagnostic = {
1598
1634
  node: property,
1599
1635
  severity: 'error',
1600
1636
  message: '',
1601
- errorPos: {},
1602
1637
  };
1638
+ const dataBaseTyp = property.currentDataBaseType;
1603
1639
  typeAnnotation.tsErrorDetail = null;
1604
- databaseTypeAnnotation.tsErrorDetail = null;
1605
- if (!dataBaseTyp) {
1606
- diagnostic.message = `平台目前暂不支持${dbType}数据库的${databaseTypeName}存储类型`;
1607
- diagnostic.errorPos.typeName = `平台目前暂不支持${dbType}数据库的${databaseTypeName}存储类型`;
1608
- databaseTypeAnnotation.tsErrorDetail = diagnostic;
1640
+ if (!dataBaseTyp && databaseTypeAnnotation) {
1641
+ const { typeName: databaseTypeName } = databaseTypeAnnotation;
1642
+ const errorMsg = `平台目前暂不支持${dbType}数据库的${databaseTypeName}存储类型`;
1643
+ diagnostic.message = errorMsg;
1644
+ const tsErrorDetail: any = {
1645
+ severity: 'error',
1646
+ errorPos: {
1647
+ typeName: errorMsg,
1648
+ },
1649
+ };
1650
+ databaseTypeAnnotation.tsErrorDetail = tsErrorDetail;
1609
1651
  } else {
1610
- const { options } = dataBaseTyp;
1652
+ const { options } = dataBaseTyp || {};
1611
1653
  if (options) {
1612
- for (const key in options) {
1613
- const option = options[key];
1614
- const { comment, require, min, max } = option || {};
1615
- const databaseTypeArg = (databaseTypeAnnotation.arguments as any)?.[key];
1616
- // 如果必填的值没有填,报错
1617
- if (require && !databaseTypeArg && key !== 'scale') {
1618
- diagnostic.message = `${comment}不能为空`;
1619
- diagnostic.errorPos[key] = `${comment}不能为空`;
1620
- } else if (min && +min > +databaseTypeArg) {
1621
- diagnostic.message = `${comment}不能小于最小值${min}`;
1622
- diagnostic.errorPos[key] = `${comment}不能小于最小值${min}`;
1623
- } else if (max && +max < +databaseTypeArg) {
1624
- diagnostic.message = `${comment}不能大于最大值${max}`;
1625
- diagnostic.errorPos[key] = `${comment}不能大于最大值${max}`;
1626
- }
1627
- if (diagnostic.message) {
1628
- databaseTypeAnnotation.tsErrorDetail = diagnostic;
1629
- }
1630
- }
1631
- const rulesMap: any = {};
1632
- if (Array.isArray(rules)) {
1633
- rules.forEach((rule) => {
1634
- const match = rule.match(/^([^()]+)\(([\d\-.]+)\)$/);
1635
- if (match) {
1636
- const [, key, value] = match;
1637
- rulesMap[key] = value;
1654
+ if (databaseTypeAnnotation) {
1655
+ databaseTypeAnnotation.tsErrorDetail = null;
1656
+ const databaseTypeAnnotationErrorDetail: any = {
1657
+ severity: 'error',
1658
+ errorPos: {},
1659
+ };
1660
+ for (const key in options) {
1661
+ const option = options[key];
1662
+ const { comment, require, min, max } = option || {};
1663
+ const databaseTypeArg = (databaseTypeAnnotation.arguments as any)?.[key];
1664
+ // 如果必填的值没有填,报错
1665
+ if (require && !databaseTypeArg && key !== 'scale') {
1666
+ diagnostic.message = `${comment}不能为空`;
1667
+ databaseTypeAnnotationErrorDetail.errorPos[key] = `${comment}不能为空`;
1668
+ } else if (min && +min > +databaseTypeArg) {
1669
+ diagnostic.message = `${comment}不能小于最小值${min}`;
1670
+ databaseTypeAnnotationErrorDetail.errorPos[key] = `${comment}不能小于最小值${min}`;
1671
+ } else if (max && +max < +databaseTypeArg) {
1672
+ diagnostic.message = `${comment}不能大于最大值${max}`;
1673
+ databaseTypeAnnotationErrorDetail.errorPos[key] = `${comment}不能大于最大值${max}`;
1638
1674
  }
1639
- });
1675
+ if (Object.keys(databaseTypeAnnotationErrorDetail.errorPos).length) {
1676
+ databaseTypeAnnotation.tsErrorDetail = databaseTypeAnnotationErrorDetail;
1677
+ }
1678
+ }
1640
1679
  }
1680
+ const typeAnnotationErrorDetail: any = {
1681
+ severity: 'warning',
1682
+ errorPos: {},
1683
+ };
1684
+ const precisionOption = options?.precision;
1685
+ const { default: defaultVal } = precisionOption || {};
1686
+ const precision = databaseTypeAnnotation ? (databaseTypeAnnotation.arguments as any)?.precision : defaultVal;
1687
+ const ruleScale = (typeAnnotation?.ruleMap as any)?.scale;
1688
+ const scale = ruleScale !== undefined ? ruleScale + '' : '';
1689
+ let ensureScale = true;
1641
1690
  switch (typeName) {
1691
+ case 'String': {
1692
+ const defaultVal = options.length?.default;
1693
+ const length = databaseTypeAnnotation ? (databaseTypeAnnotation.arguments as any)?.length : defaultVal;
1694
+ if (length) {
1695
+ [
1696
+ {
1697
+ key: 'minLength',
1698
+ text: '小',
1699
+ },
1700
+ {
1701
+ key: 'maxLength',
1702
+ text: '大',
1703
+ },
1704
+ ].forEach(({ key, text }) => {
1705
+ const curLength = rulesMap[key];
1706
+ if (+curLength > +length) {
1707
+ const errorMsg = `最${text}长度超出存储长度`;
1708
+ const diag: any = {
1709
+ node: property,
1710
+ severity: 'warning',
1711
+ message: errorMsg,
1712
+ };
1713
+ diagnostics.push(diag);
1714
+ typeAnnotationErrorDetail.errorPos[key] = errorMsg;
1715
+ }
1716
+ });
1717
+ }
1718
+ }
1642
1719
  case 'Long': {
1643
1720
  const { min: ruleMin, max: ruleMax } = dataBaseTyp;
1644
1721
  const minVal = rulesMap.min;
1645
1722
  const maxVal = rulesMap.max;
1646
- const tsErrorDetail: any = {
1647
- errorPos: {},
1648
- };
1649
- if (ruleMin && minVal && +ruleMin > +minVal) { // 最小值超出存储上限
1650
- const diag: any = {
1651
- node: property,
1652
- severity: 'warning',
1653
- message: `最小值超出存储下限${ruleMin}`,
1654
- };
1655
- tsErrorDetail.severity = 'warning';
1656
- tsErrorDetail.errorPos.min = '最小值超出存储下限';
1657
- diagnostics.push(diag);
1658
- }
1659
- if (ruleMax && maxVal && +ruleMax < +maxVal) { // 最大值超出存储上限
1660
- const diag = {
1661
- node: property,
1662
- severity: 'warning',
1663
- message: `最大值超出存储上限${ruleMax}`,
1664
- };
1665
- tsErrorDetail.severity = 'warning';
1666
- tsErrorDetail.errorPos.max = '最大值超出存储上限';
1667
- diagnostics.push(diag);
1668
- }
1669
- typeAnnotation.tsErrorDetail = tsErrorDetail;
1723
+ // 最大最小值都要校验存储上下限
1724
+ [
1725
+ {
1726
+ key: 'min',
1727
+ name: '最小值',
1728
+ value: minVal,
1729
+ },
1730
+ {
1731
+ key: 'max',
1732
+ name: '最大值',
1733
+ value: maxVal,
1734
+ },
1735
+ ].forEach(({ key, name, value }) => {
1736
+ if (ruleMin && value && new Decimal(ruleMin).greaterThan(new Decimal(value))) { // 超出存储下限
1737
+ const diag: any = {
1738
+ node: property,
1739
+ severity: 'warning',
1740
+ message: `${name}超出存储下限${ruleMin}`,
1741
+ };
1742
+ diagnostics.push(diag);
1743
+ typeAnnotationErrorDetail.errorPos[key] = `${name}超出存储下限`;
1744
+ }
1745
+ if (ruleMax && value && new Decimal(ruleMax).lessThan(new Decimal(value))) { // 超出存储上限
1746
+ const diag = {
1747
+ node: property,
1748
+ severity: 'warning',
1749
+ message: `${name}超出存储上限${ruleMax}`,
1750
+ };
1751
+ diagnostics.push(diag);
1752
+ typeAnnotationErrorDetail.errorPos[key] = `${name}超出存储上限`;
1753
+ }
1754
+ });
1670
1755
  break;
1671
1756
  }
1672
1757
  case 'Decimal': {
1673
- const precisionOption = options?.precision;
1674
- const { default: defaultVal } = precisionOption || {};
1675
- const precision = databaseTypeAnnotation ? (databaseTypeAnnotation.arguments as any)?.precision : defaultVal;
1676
- const scale = (typeAnnotation?.ruleMap as any)?.scale + '';
1677
- if (+precision < +scale) {
1678
- const diag: any = {
1679
- node: property,
1680
- severity: 'error',
1681
- message: '',
1682
- errorPos: {},
1683
- };
1684
- diag.message = `小数位数必须小于或等于精度${precision}`;
1685
- diag.errorPos.scale = `小数位数必须小于或等于精度${precision}`;
1686
- typeAnnotation.tsErrorDetail = diag;
1687
- diagnostics.push(diag);
1758
+ if (precisionOption) {
1759
+ if (+precision < +scale) {
1760
+ const diag: any = {
1761
+ node: property,
1762
+ severity: 'error',
1763
+ message: '',
1764
+ };
1765
+ const errorMsg = `小数位数必须小于或等于精度${precision}`;
1766
+ diag.message = errorMsg;
1767
+ diagnostics.push(diag);
1768
+ ensureScale = false;
1769
+ typeAnnotationErrorDetail.errorPos.scale = errorMsg;
1770
+ }
1688
1771
  }
1689
1772
  break;
1690
1773
  }
1691
1774
  }
1775
+ const minVal = rulesMap.min;
1776
+ const maxVal = rulesMap.max;
1777
+ // 最 大/小 值不能 大/于 由精度和小数位数 确定的范围
1778
+ if (precisionOption && ensureScale) {
1779
+ const memoryStr = '9'.repeat(+precision);
1780
+ // 储存整数部分
1781
+ const memoryIntAbsStr = memoryStr.slice(0, +precision - +(scale || '0')) || '0';
1782
+ // 储存小数部分
1783
+ const memoryScaleStr = memoryStr.slice(0, +(scale || '0'));
1784
+ // 储存绝对值
1785
+ const memoryAbsVal = memoryIntAbsStr + (memoryScaleStr ? '.' + memoryScaleStr : '');
1786
+ const decimalMemoryAbsVal = new Decimal(memoryAbsVal);
1787
+ [
1788
+ {
1789
+ key: 'min',
1790
+ text: '小',
1791
+ val: minVal,
1792
+ },
1793
+ {
1794
+ key: 'max',
1795
+ text: '大',
1796
+ val: maxVal,
1797
+ },
1798
+ ].forEach(({ key, text, val }) => {
1799
+ if (val) {
1800
+ const decimalVal = new Decimal(val);
1801
+ // 是否是负数
1802
+ const isNegative = decimalVal.isNegative();
1803
+ // 填入的值的绝对值是否大于存储绝对值
1804
+ if (decimalMemoryAbsVal.lessThan(decimalVal.abs())) {
1805
+ const errorMsg = `最${text}值不得${isNegative ? '小' : '大'}于${isNegative ? '-' : ''}${memoryAbsVal}`;
1806
+ const diag: any = {
1807
+ node: property,
1808
+ severity: 'warning',
1809
+ message: errorMsg,
1810
+ };
1811
+ diagnostics.push(diag);
1812
+ typeAnnotationErrorDetail.errorPos[key] = errorMsg;
1813
+ }
1814
+ }
1815
+ });
1816
+ }
1817
+ if (['Long', 'Decimal'].includes(typeName) && !typeAnnotationErrorDetail.errorPos.min) {
1818
+ if (minVal && maxVal && new Decimal(maxVal).lessThan(minVal)) {
1819
+ const errorMsg = '最小值不得大于最大值';
1820
+ const diag: any = {
1821
+ node: property,
1822
+ severity: 'warning',
1823
+ message: errorMsg,
1824
+ };
1825
+ diagnostics.push(diag);
1826
+ typeAnnotationErrorDetail.errorPos.min = errorMsg;
1827
+ }
1828
+ }
1829
+ if (Object.keys(typeAnnotationErrorDetail.errorPos).length) {
1830
+ typeAnnotation.tsErrorDetail = typeAnnotationErrorDetail;
1831
+ }
1692
1832
  }
1693
1833
  }
1694
1834
  if (diagnostic.message) {
@@ -2065,8 +2205,13 @@ export class NaslServer {
2065
2205
  */
2066
2206
  _resolveDiagnostic(diagnostic: tsProtocol.DiagnosticWithFileName, fileNode: FileNode, record: DiagnosticRecord): Diagnostic {
2067
2207
  // 拓展模块中的翻译先过滤掉,因为有错用户也不能修改
2068
- if ((fileNode as any).module && !(fileNode instanceof ConfigProperty))
2208
+ if ((fileNode as any).module && !(fileNode instanceof ConfigProperty)) {
2069
2209
  return;
2210
+ }
2211
+ // 过滤掉java依赖库的报错
2212
+ // if ('compilerInfoMap' in fileNode && (fileNode as any).compilerInfoMap?.java) {
2213
+ // return;
2214
+ // }
2070
2215
 
2071
2216
  const minRange = this._findMinRange(diagnostic, fileNode);
2072
2217
  const tsErrorDetail = {
@@ -2120,8 +2265,23 @@ export class NaslServer {
2120
2265
  } else {
2121
2266
  // 没有节点 或者 行差比较小比已有的小就可以
2122
2267
  // 一般出现在一大块上,多半是if for 等等没有参数
2123
- if (!minRange || item.range.end.line - item.range.start.line < minRange.item.range.end.line - minRange.item.range.start.line) {
2268
+ if (!minRange) {
2124
2269
  minRange = { node, item };
2270
+ } else if (lsp2tspNumber(item.range.start.line) === diagnostic.start.line && diagnostic.start.offset >= lsp2tspNumber(item.range.start.character)) {
2271
+ // 如果当前遍历的内容的行和列都 小于之前的, 而且是有效的
2272
+ // 如果两个内容位置行数是一样的,就比较下找到内容的位置信息
2273
+ // 找到的内容的开始位置, 要大于申明内容开始的位置,要不就不包含在内了
2274
+ if (diagnostic.start.offset - item.range.start.character <= diagnostic.start.offset - minRange.item.range.start.character) {
2275
+ minRange = { node, item };
2276
+ } else {
2277
+ if (diagnostic.start.offset < lsp2tspNumber(minRange.item.range.start.character)) {
2278
+ minRange = { node, item };
2279
+ }
2280
+ }
2281
+ } else if (item.range.end.line - item.range.start.line <= minRange.item.range.end.line - minRange.item.range.start.line) {
2282
+ if (minRange.item.range.start.line !== diagnostic.start.line) {
2283
+ minRange = { node, item };
2284
+ }
2125
2285
  }
2126
2286
  }
2127
2287
  }
@@ -2323,10 +2483,14 @@ export class NaslServer {
2323
2483
  const prefix = '__ProcessIdentification__';
2324
2484
  const positions = [];
2325
2485
  let pos = code.indexOf(prefix);
2486
+ pos = code.indexOf(node.name, pos + prefix.length);
2487
+ // pos === -1:两种情况:
2488
+ // 1、找到最后一个节点了,继续找找不下去了。
2489
+ // 2、创建、删除节点的时候也会找不到(本身这两种操作就不应该进到这个方法)
2326
2490
  while (pos !== -1) {
2327
- pos = code.indexOf(node.name, pos + prefix.length);
2328
2491
  positions.push(pos);
2329
2492
  pos = code.indexOf(prefix, pos + prefix.length);
2493
+ pos = pos === -1 ? pos : code.indexOf(node.name, pos + prefix.length);
2330
2494
  }
2331
2495
  positions.shift();
2332
2496
  // 拿到标识下定义的参数名字
@@ -2373,12 +2537,16 @@ export class NaslServer {
2373
2537
  let pos = code.indexOf(prefix);
2374
2538
  // 需要再次定位到processelement对象上,避免process上存在同名参数
2375
2539
  pos = code.indexOf(node.parentNode.name, pos + prefix.length);
2540
+ pos = pos === -1 ? pos : code.indexOf(node.name, pos + prefix.length);
2541
+ // pos === -1:两种情况:
2542
+ // 1、找到最后一个节点了,继续找找不下去了。
2543
+ // 2、创建、删除节点的时候也会找不到(本身这两种操作就不应该进到这个方法)
2376
2544
  while (pos !== -1) {
2377
- pos = code.indexOf(node.name, pos + prefix.length);
2378
2545
  positions.push(pos);
2379
2546
  pos = code.indexOf(prefix, pos + prefix.length);
2380
2547
  // 需要再次定位到processelement对象上,避免process上存在同名参数
2381
- pos = code.indexOf(node.parentNode.name, pos + node.parentNode.name.length);
2548
+ pos = pos === -1 ? pos : code.indexOf(node.parentNode.name, pos + node.parentNode.name.length);
2549
+ pos = pos === -1 ? pos : code.indexOf(node.name, pos + prefix.length);
2382
2550
  }
2383
2551
  // 拿到标识下定义的参数名字
2384
2552
  const promises = positions.map((item) => this.references({
@@ -3498,6 +3666,7 @@ export class NaslServer {
3498
3666
  });
3499
3667
  }
3500
3668
  });
3669
+ console.time('全量标注');
3501
3670
  const typesMap = await this.getQuickInfoNodesTypeMap(nodes, true);
3502
3671
  // console.log(typesMap, 'typesMap')
3503
3672
  console.timeEnd('全量标注');
@@ -3558,7 +3727,7 @@ export class NaslServer {
3558
3727
  }
3559
3728
  }
3560
3729
  // 旧版本数据查询需要确认是匿名数据结构的 ListTotal 类型
3561
- if (node instanceof CallQueryComponent && node.ideVersion !== '2.11') {
3730
+ if (node instanceof CallQueryComponent && !node.isAutoInfer()) {
3562
3731
  const jsonNode = jsoner.queryNodeByPath(json, node.getNodePath(false));
3563
3732
  jsonNode.typeAnnotation = {
3564
3733
  concept: 'TypeAnnotation',
@@ -3629,7 +3798,7 @@ export class NaslServer {
3629
3798
  jsonNode.typeAnnotation = (value as TypeAnnotation).toJSON();
3630
3799
  }
3631
3800
  }
3632
- if (node instanceof NewComposite && node.typeAnnotation.typeKind === 'anonymousStructure') {
3801
+ if (node instanceof NewComposite && node.typeAnnotation?.typeKind === 'anonymousStructure') {
3633
3802
  const jsonNode = jsoner.queryNodeByPath(json, node.getNodePath(false));
3634
3803
  jsonNode.typeAnnotation = (value as TypeAnnotation).toJSON();
3635
3804
  }
@@ -4045,7 +4214,7 @@ export class NaslServer {
4045
4214
  // 当前操作的文件节点
4046
4215
  const { fileNode } = this.getCurrentSource(targetNode);
4047
4216
  // 如果是导入模块就,就引入对应模块,先不处理module和Configuration,下面的内容会自动创建
4048
- if (!fileNode || fileNode instanceof Module || fileNode instanceof Configuration) {
4217
+ if (!fileNode || fileNode instanceof Module || fileNode instanceof Configuration || fileNode instanceof Integration) {
4049
4218
  // module单独处理
4050
4219
  if (fileNode instanceof Module) {
4051
4220
  await this.incidentalAction(action, fileNode, targetNode);
@@ -4097,7 +4266,7 @@ export class NaslServer {
4097
4266
  if (this.changeStackList.length) {
4098
4267
  this.changeFileNext();
4099
4268
  } else {
4100
- console.log(Array.from(this.filesToCheck));
4269
+ console.info(Array.from(this.filesToCheck));
4101
4270
  await this.getDiagnosticRecordsAndPushAll(Array.from(this.filesToCheck));
4102
4271
  this.filesToCheck.clear();
4103
4272
  }