@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
@@ -50,6 +50,7 @@ const naslStdlibMap_1 = __importDefault(require("./naslStdlibMap"));
50
50
  const jsoner = __importStar(require("../service/storage/jsoner"));
51
51
  const EventEmitter_1 = require("../common/EventEmitter");
52
52
  const utils_1 = require("../utils");
53
+ const decimal_js_1 = require("decimal.js");
53
54
  const EmbeddedTSFileLineMap = {
54
55
  Entity: 3,
55
56
  };
@@ -172,12 +173,12 @@ class NaslServer {
172
173
  const changeNode = changeEvent.target;
173
174
  const { fileNode } = this.getCurrentSource(changeNode);
174
175
  if (changeNode !== fileNode || !changeEvent.field) {
175
- const findIndex = this.changeStackList.findIndex((changeStackItem) => {
176
+ const findLastIndex = this.changeStackList.findLastIndex((changeStackItem) => {
176
177
  const target = changeStackItem.target;
177
178
  const { fileNode: targetFileNode } = this.getCurrentSource(target);
178
179
  return targetFileNode === fileNode;
179
180
  });
180
- if (findIndex === this.changeStackList.length - 1) {
181
+ if (findLastIndex === this.changeStackList.length - 1) {
181
182
  this.changeStackList.pop();
182
183
  }
183
184
  }
@@ -218,6 +219,10 @@ class NaslServer {
218
219
  await this.getDiagnosticRecordsAndPushAll();
219
220
  }
220
221
  contentToFile(module, results) {
222
+ // 禁用的依赖库不生成代码 区分 undefined 和 false
223
+ if (module instanceof concepts_1.Module && module.type === 'extension' && module.enable === false) {
224
+ return;
225
+ }
221
226
  module.structures.forEach((structure) => {
222
227
  try {
223
228
  const result = structure.toEmbeddedTSFile();
@@ -532,6 +537,9 @@ class NaslServer {
532
537
  * fileNode
533
538
  */
534
539
  const { currentSource, fileNode } = this.getCurrentSource(callFunction);
540
+ if (!currentSource) {
541
+ return [];
542
+ }
535
543
  try {
536
544
  const quickInfo = await this._getTypeQuickinfo({
537
545
  file: fileNode.getEmbeddedFilePath(),
@@ -571,8 +579,8 @@ class NaslServer {
571
579
  }
572
580
  }
573
581
  /**
574
- * 获取表单的dataschema类型
575
- * @param node 当前表单节点
582
+ * 获取表格的dataschema类型
583
+ * @param node 当前表格节点
576
584
  * @param allType 是不是需要全部类型 默认不要
577
585
  * @returns 全部类型的str 或者 最后一个.后的内容
578
586
  */
@@ -580,6 +588,9 @@ class NaslServer {
580
588
  if (!(node instanceof concepts_1.ViewElement))
581
589
  return;
582
590
  const { currentSource, fileNode } = this.getCurrentSource(node);
591
+ if (!currentSource) {
592
+ return;
593
+ }
583
594
  const quickInfo = await this._getTypeQuickinfo({
584
595
  file: fileNode.getEmbeddedFilePath(),
585
596
  line: (0, translator_1.lsp2tspNumber)(currentSource.range.start.line),
@@ -638,6 +649,9 @@ class NaslServer {
638
649
  if (!(node instanceof concepts_1.ViewElement))
639
650
  return;
640
651
  const { currentSource, fileNode } = this.getCurrentSource(node);
652
+ if (!currentSource) {
653
+ return;
654
+ }
641
655
  const quickInfo = await this._getTypeQuickinfo({
642
656
  file: fileNode.getEmbeddedFilePath(),
643
657
  line: (0, translator_1.lsp2tspNumber)(currentSource.range.start.line),
@@ -823,12 +837,6 @@ class NaslServer {
823
837
  record.suggestionDiagnostics.push(diagnostic);
824
838
  return null;
825
839
  }
826
- else if (currentNode.concept === 'DataSource' && diagnostic.originalDiagnostic?.text === 'DataSource connection error') {
827
- // 数据源警告类型降级
828
- diagnostic.severity = 'warning';
829
- record.suggestionDiagnostics.push(diagnostic);
830
- return null;
831
- }
832
840
  else if (currentNode.concept === 'OqlQueryComponent') {
833
841
  // OQL别名错误降级为警告
834
842
  if (diagnostic.originalDiagnostic && diagnostic.originalDiagnostic?.text.includes('__OQL_ALIAS_WARNING__')) {
@@ -894,6 +902,12 @@ class NaslServer {
894
902
  else if ((diag.text).includes(` is declared but its value is never read.`)) {
895
903
  // 局部变量和输入变量未使用的警告
896
904
  if ((node.concept === 'View' || node.concept === 'Logic') && node.parentNode.concept !== 'Module') {
905
+ /**
906
+ * javalogic不用提示
907
+ */
908
+ if (node.concept === 'Logic' && this._isJavalogic(node)) {
909
+ return;
910
+ }
897
911
  const minRange = this._findMinRange(diag, node);
898
912
  if (minRange) {
899
913
  /**
@@ -926,6 +940,16 @@ class NaslServer {
926
940
  });
927
941
  return records;
928
942
  }
943
+ /**
944
+ * 判断是否是Javalogic
945
+ */
946
+ _isJavalogic(node) {
947
+ const body = node.body || [];
948
+ if (body && body.length && body[0].concept === 'JavaLogic') {
949
+ return true;
950
+ }
951
+ return false;
952
+ }
929
953
  /**
930
954
  * 额外的建议诊断
931
955
  * @param fileNode 文件级别的节点
@@ -935,7 +959,8 @@ class NaslServer {
935
959
  const diagnostics = [];
936
960
  if (fileNode instanceof concepts_1.Logic || fileNode instanceof concepts_1.View) {
937
961
  fileNode?.sourceMap.forEach((value, node) => {
938
- if (node instanceof concepts_1.Match) {
962
+ // 表达式模式才需要校验返回值类型
963
+ if (node instanceof concepts_1.Match && node.isExpression) {
939
964
  const { cases, expression } = node || {};
940
965
  const typeAnnotationMap = {};
941
966
  // 最多数的类型
@@ -1437,14 +1462,14 @@ class NaslServer {
1437
1462
  if (!propertyValue.value && fileNode.name !== 'defaultDS') {
1438
1463
  const diagnostic = {
1439
1464
  node: fileNode,
1440
- severity: 'warning',
1465
+ severity: 'error',
1441
1466
  message: `数据源配置:数据源${property.name}${propertyValue.env === 'dev' ? '开发环境' : '生产环境'}未配置数据信息`,
1442
1467
  // 保留原来的内容方便查询一些问题
1443
1468
  originalDiagnostic: {
1444
1469
  fileName: '',
1445
1470
  start: null,
1446
1471
  end: null,
1447
- category: 'warning',
1472
+ category: 'error',
1448
1473
  text: `Data Source is not config`,
1449
1474
  },
1450
1475
  };
@@ -1499,110 +1524,221 @@ class NaslServer {
1499
1524
  const { origin, properties } = entity || {};
1500
1525
  if (dbType && !['excel', 'table'].includes(origin) && Array.isArray(properties) && properties.length) {
1501
1526
  properties.forEach((property) => {
1502
- const { typeAnnotation, databaseTypeAnnotation, rules } = property || {};
1503
- if (property && databaseTypeAnnotation) {
1504
- const { typeName: databaseTypeName } = databaseTypeAnnotation;
1527
+ if (property) {
1528
+ const { typeAnnotation, databaseTypeAnnotation, rules } = property;
1505
1529
  const { typeName } = typeAnnotation || {};
1506
- const dataBaseTypeMap = property.dataBaseTypeMap || {};
1507
- const dataBaseTyp = dataBaseTypeMap[databaseTypeName];
1530
+ const rulesMap = {};
1531
+ if (Array.isArray(rules)) {
1532
+ rules.forEach((rule) => {
1533
+ const match = rule.match(/^([^()]+)\(([\d\-.]+)\)$/);
1534
+ if (match) {
1535
+ const [, key, value] = match;
1536
+ rulesMap[key] = value;
1537
+ }
1538
+ });
1539
+ }
1508
1540
  const diagnostic = {
1509
1541
  node: property,
1510
1542
  severity: 'error',
1511
1543
  message: '',
1512
- errorPos: {},
1513
1544
  };
1545
+ const dataBaseTyp = property.currentDataBaseType;
1514
1546
  typeAnnotation.tsErrorDetail = null;
1515
- databaseTypeAnnotation.tsErrorDetail = null;
1516
- if (!dataBaseTyp) {
1517
- diagnostic.message = `平台目前暂不支持${dbType}数据库的${databaseTypeName}存储类型`;
1518
- diagnostic.errorPos.typeName = `平台目前暂不支持${dbType}数据库的${databaseTypeName}存储类型`;
1519
- databaseTypeAnnotation.tsErrorDetail = diagnostic;
1547
+ if (!dataBaseTyp && databaseTypeAnnotation) {
1548
+ const { typeName: databaseTypeName } = databaseTypeAnnotation;
1549
+ const errorMsg = `平台目前暂不支持${dbType}数据库的${databaseTypeName}存储类型`;
1550
+ diagnostic.message = errorMsg;
1551
+ const tsErrorDetail = {
1552
+ severity: 'error',
1553
+ errorPos: {
1554
+ typeName: errorMsg,
1555
+ },
1556
+ };
1557
+ databaseTypeAnnotation.tsErrorDetail = tsErrorDetail;
1520
1558
  }
1521
1559
  else {
1522
- const { options } = dataBaseTyp;
1560
+ const { options } = dataBaseTyp || {};
1523
1561
  if (options) {
1524
- for (const key in options) {
1525
- const option = options[key];
1526
- const { comment, require, min, max } = option || {};
1527
- const databaseTypeArg = databaseTypeAnnotation.arguments?.[key];
1528
- // 如果必填的值没有填,报错
1529
- if (require && !databaseTypeArg && key !== 'scale') {
1530
- diagnostic.message = `${comment}不能为空`;
1531
- diagnostic.errorPos[key] = `${comment}不能为空`;
1532
- }
1533
- else if (min && +min > +databaseTypeArg) {
1534
- diagnostic.message = `${comment}不能小于最小值${min}`;
1535
- diagnostic.errorPos[key] = `${comment}不能小于最小值${min}`;
1536
- }
1537
- else if (max && +max < +databaseTypeArg) {
1538
- diagnostic.message = `${comment}不能大于最大值${max}`;
1539
- diagnostic.errorPos[key] = `${comment}不能大于最大值${max}`;
1540
- }
1541
- if (diagnostic.message) {
1542
- databaseTypeAnnotation.tsErrorDetail = diagnostic;
1543
- }
1544
- }
1545
- const rulesMap = {};
1546
- if (Array.isArray(rules)) {
1547
- rules.forEach((rule) => {
1548
- const match = rule.match(/^([^()]+)\(([\d\-.]+)\)$/);
1549
- if (match) {
1550
- const [, key, value] = match;
1551
- rulesMap[key] = value;
1562
+ if (databaseTypeAnnotation) {
1563
+ databaseTypeAnnotation.tsErrorDetail = null;
1564
+ const databaseTypeAnnotationErrorDetail = {
1565
+ severity: 'error',
1566
+ errorPos: {},
1567
+ };
1568
+ for (const key in options) {
1569
+ const option = options[key];
1570
+ const { comment, require, min, max } = option || {};
1571
+ const databaseTypeArg = databaseTypeAnnotation.arguments?.[key];
1572
+ // 如果必填的值没有填,报错
1573
+ if (require && !databaseTypeArg && key !== 'scale') {
1574
+ diagnostic.message = `${comment}不能为空`;
1575
+ databaseTypeAnnotationErrorDetail.errorPos[key] = `${comment}不能为空`;
1552
1576
  }
1553
- });
1577
+ else if (min && +min > +databaseTypeArg) {
1578
+ diagnostic.message = `${comment}不能小于最小值${min}`;
1579
+ databaseTypeAnnotationErrorDetail.errorPos[key] = `${comment}不能小于最小值${min}`;
1580
+ }
1581
+ else if (max && +max < +databaseTypeArg) {
1582
+ diagnostic.message = `${comment}不能大于最大值${max}`;
1583
+ databaseTypeAnnotationErrorDetail.errorPos[key] = `${comment}不能大于最大值${max}`;
1584
+ }
1585
+ if (Object.keys(databaseTypeAnnotationErrorDetail.errorPos).length) {
1586
+ databaseTypeAnnotation.tsErrorDetail = databaseTypeAnnotationErrorDetail;
1587
+ }
1588
+ }
1554
1589
  }
1590
+ const typeAnnotationErrorDetail = {
1591
+ severity: 'warning',
1592
+ errorPos: {},
1593
+ };
1594
+ const precisionOption = options?.precision;
1595
+ const { default: defaultVal } = precisionOption || {};
1596
+ const precision = databaseTypeAnnotation ? databaseTypeAnnotation.arguments?.precision : defaultVal;
1597
+ const ruleScale = typeAnnotation?.ruleMap?.scale;
1598
+ const scale = ruleScale !== undefined ? ruleScale + '' : '';
1599
+ let ensureScale = true;
1555
1600
  switch (typeName) {
1601
+ case 'String': {
1602
+ const defaultVal = options.length?.default;
1603
+ const length = databaseTypeAnnotation ? databaseTypeAnnotation.arguments?.length : defaultVal;
1604
+ if (length) {
1605
+ [
1606
+ {
1607
+ key: 'minLength',
1608
+ text: '小',
1609
+ },
1610
+ {
1611
+ key: 'maxLength',
1612
+ text: '大',
1613
+ },
1614
+ ].forEach(({ key, text }) => {
1615
+ const curLength = rulesMap[key];
1616
+ if (+curLength > +length) {
1617
+ const errorMsg = `最${text}长度超出存储长度`;
1618
+ const diag = {
1619
+ node: property,
1620
+ severity: 'warning',
1621
+ message: errorMsg,
1622
+ };
1623
+ diagnostics.push(diag);
1624
+ typeAnnotationErrorDetail.errorPos[key] = errorMsg;
1625
+ }
1626
+ });
1627
+ }
1628
+ }
1556
1629
  case 'Long': {
1557
1630
  const { min: ruleMin, max: ruleMax } = dataBaseTyp;
1558
1631
  const minVal = rulesMap.min;
1559
1632
  const maxVal = rulesMap.max;
1560
- const tsErrorDetail = {
1561
- errorPos: {},
1562
- };
1563
- if (ruleMin && minVal && +ruleMin > +minVal) { // 最小值超出存储上限
1564
- const diag = {
1565
- node: property,
1566
- severity: 'warning',
1567
- message: `最小值超出存储下限${ruleMin}`,
1568
- };
1569
- tsErrorDetail.severity = 'warning';
1570
- tsErrorDetail.errorPos.min = '最小值超出存储下限';
1571
- diagnostics.push(diag);
1572
- }
1573
- if (ruleMax && maxVal && +ruleMax < +maxVal) { // 最大值超出存储上限
1574
- const diag = {
1575
- node: property,
1576
- severity: 'warning',
1577
- message: `最大值超出存储上限${ruleMax}`,
1578
- };
1579
- tsErrorDetail.severity = 'warning';
1580
- tsErrorDetail.errorPos.max = '最大值超出存储上限';
1581
- diagnostics.push(diag);
1582
- }
1583
- typeAnnotation.tsErrorDetail = tsErrorDetail;
1633
+ // 最大最小值都要校验存储上下限
1634
+ [
1635
+ {
1636
+ key: 'min',
1637
+ name: '最小值',
1638
+ value: minVal,
1639
+ },
1640
+ {
1641
+ key: 'max',
1642
+ name: '最大值',
1643
+ value: maxVal,
1644
+ },
1645
+ ].forEach(({ key, name, value }) => {
1646
+ if (ruleMin && value && new decimal_js_1.Decimal(ruleMin).greaterThan(new decimal_js_1.Decimal(value))) { // 超出存储下限
1647
+ const diag = {
1648
+ node: property,
1649
+ severity: 'warning',
1650
+ message: `${name}超出存储下限${ruleMin}`,
1651
+ };
1652
+ diagnostics.push(diag);
1653
+ typeAnnotationErrorDetail.errorPos[key] = `${name}超出存储下限`;
1654
+ }
1655
+ if (ruleMax && value && new decimal_js_1.Decimal(ruleMax).lessThan(new decimal_js_1.Decimal(value))) { // 超出存储上限
1656
+ const diag = {
1657
+ node: property,
1658
+ severity: 'warning',
1659
+ message: `${name}超出存储上限${ruleMax}`,
1660
+ };
1661
+ diagnostics.push(diag);
1662
+ typeAnnotationErrorDetail.errorPos[key] = `${name}超出存储上限`;
1663
+ }
1664
+ });
1584
1665
  break;
1585
1666
  }
1586
1667
  case 'Decimal': {
1587
- const precisionOption = options?.precision;
1588
- const { default: defaultVal } = precisionOption || {};
1589
- const precision = databaseTypeAnnotation ? databaseTypeAnnotation.arguments?.precision : defaultVal;
1590
- const scale = typeAnnotation?.ruleMap?.scale + '';
1591
- if (+precision < +scale) {
1592
- const diag = {
1593
- node: property,
1594
- severity: 'error',
1595
- message: '',
1596
- errorPos: {},
1597
- };
1598
- diag.message = `小数位数必须小于或等于精度${precision}`;
1599
- diag.errorPos.scale = `小数位数必须小于或等于精度${precision}`;
1600
- typeAnnotation.tsErrorDetail = diag;
1601
- diagnostics.push(diag);
1668
+ if (precisionOption) {
1669
+ if (+precision < +scale) {
1670
+ const diag = {
1671
+ node: property,
1672
+ severity: 'error',
1673
+ message: '',
1674
+ };
1675
+ const errorMsg = `小数位数必须小于或等于精度${precision}`;
1676
+ diag.message = errorMsg;
1677
+ diagnostics.push(diag);
1678
+ ensureScale = false;
1679
+ typeAnnotationErrorDetail.errorPos.scale = errorMsg;
1680
+ }
1602
1681
  }
1603
1682
  break;
1604
1683
  }
1605
1684
  }
1685
+ const minVal = rulesMap.min;
1686
+ const maxVal = rulesMap.max;
1687
+ // 最 大/小 值不能 大/于 由精度和小数位数 确定的范围
1688
+ if (precisionOption && ensureScale) {
1689
+ const memoryStr = '9'.repeat(+precision);
1690
+ // 储存整数部分
1691
+ const memoryIntAbsStr = memoryStr.slice(0, +precision - +(scale || '0')) || '0';
1692
+ // 储存小数部分
1693
+ const memoryScaleStr = memoryStr.slice(0, +(scale || '0'));
1694
+ // 储存绝对值
1695
+ const memoryAbsVal = memoryIntAbsStr + (memoryScaleStr ? '.' + memoryScaleStr : '');
1696
+ const decimalMemoryAbsVal = new decimal_js_1.Decimal(memoryAbsVal);
1697
+ [
1698
+ {
1699
+ key: 'min',
1700
+ text: '小',
1701
+ val: minVal,
1702
+ },
1703
+ {
1704
+ key: 'max',
1705
+ text: '大',
1706
+ val: maxVal,
1707
+ },
1708
+ ].forEach(({ key, text, val }) => {
1709
+ if (val) {
1710
+ const decimalVal = new decimal_js_1.Decimal(val);
1711
+ // 是否是负数
1712
+ const isNegative = decimalVal.isNegative();
1713
+ // 填入的值的绝对值是否大于存储绝对值
1714
+ if (decimalMemoryAbsVal.lessThan(decimalVal.abs())) {
1715
+ const errorMsg = `最${text}值不得${isNegative ? '小' : '大'}于${isNegative ? '-' : ''}${memoryAbsVal}`;
1716
+ const diag = {
1717
+ node: property,
1718
+ severity: 'warning',
1719
+ message: errorMsg,
1720
+ };
1721
+ diagnostics.push(diag);
1722
+ typeAnnotationErrorDetail.errorPos[key] = errorMsg;
1723
+ }
1724
+ }
1725
+ });
1726
+ }
1727
+ if (['Long', 'Decimal'].includes(typeName) && !typeAnnotationErrorDetail.errorPos.min) {
1728
+ if (minVal && maxVal && new decimal_js_1.Decimal(maxVal).lessThan(minVal)) {
1729
+ const errorMsg = '最小值不得大于最大值';
1730
+ const diag = {
1731
+ node: property,
1732
+ severity: 'warning',
1733
+ message: errorMsg,
1734
+ };
1735
+ diagnostics.push(diag);
1736
+ typeAnnotationErrorDetail.errorPos.min = errorMsg;
1737
+ }
1738
+ }
1739
+ if (Object.keys(typeAnnotationErrorDetail.errorPos).length) {
1740
+ typeAnnotation.tsErrorDetail = typeAnnotationErrorDetail;
1741
+ }
1606
1742
  }
1607
1743
  }
1608
1744
  if (diagnostic.message) {
@@ -1988,8 +2124,13 @@ class NaslServer {
1988
2124
  */
1989
2125
  _resolveDiagnostic(diagnostic, fileNode, record) {
1990
2126
  // 拓展模块中的翻译先过滤掉,因为有错用户也不能修改
1991
- if (fileNode.module && !(fileNode instanceof concepts_1.ConfigProperty))
2127
+ if (fileNode.module && !(fileNode instanceof concepts_1.ConfigProperty)) {
1992
2128
  return;
2129
+ }
2130
+ // 过滤掉java依赖库的报错
2131
+ // if ('compilerInfoMap' in fileNode && (fileNode as any).compilerInfoMap?.java) {
2132
+ // return;
2133
+ // }
1993
2134
  const minRange = this._findMinRange(diagnostic, fileNode);
1994
2135
  const tsErrorDetail = {
1995
2136
  severity: diagnostic.category === 'error' ? 'error' : 'warning',
@@ -2041,9 +2182,27 @@ class NaslServer {
2041
2182
  else {
2042
2183
  // 没有节点 或者 行差比较小比已有的小就可以
2043
2184
  // 一般出现在一大块上,多半是if for 等等没有参数
2044
- if (!minRange || item.range.end.line - item.range.start.line < minRange.item.range.end.line - minRange.item.range.start.line) {
2185
+ if (!minRange) {
2045
2186
  minRange = { node, item };
2046
2187
  }
2188
+ else if ((0, translator_1.lsp2tspNumber)(item.range.start.line) === diagnostic.start.line && diagnostic.start.offset >= (0, translator_1.lsp2tspNumber)(item.range.start.character)) {
2189
+ // 如果当前遍历的内容的行和列都 小于之前的, 而且是有效的
2190
+ // 如果两个内容位置行数是一样的,就比较下找到内容的位置信息
2191
+ // 找到的内容的开始位置, 要大于申明内容开始的位置,要不就不包含在内了
2192
+ if (diagnostic.start.offset - item.range.start.character <= diagnostic.start.offset - minRange.item.range.start.character) {
2193
+ minRange = { node, item };
2194
+ }
2195
+ else {
2196
+ if (diagnostic.start.offset < (0, translator_1.lsp2tspNumber)(minRange.item.range.start.character)) {
2197
+ minRange = { node, item };
2198
+ }
2199
+ }
2200
+ }
2201
+ else if (item.range.end.line - item.range.start.line <= minRange.item.range.end.line - minRange.item.range.start.line) {
2202
+ if (minRange.item.range.start.line !== diagnostic.start.line) {
2203
+ minRange = { node, item };
2204
+ }
2205
+ }
2047
2206
  }
2048
2207
  }
2049
2208
  }
@@ -2240,10 +2399,14 @@ class NaslServer {
2240
2399
  const prefix = '__ProcessIdentification__';
2241
2400
  const positions = [];
2242
2401
  let pos = code.indexOf(prefix);
2402
+ pos = code.indexOf(node.name, pos + prefix.length);
2403
+ // pos === -1:两种情况:
2404
+ // 1、找到最后一个节点了,继续找找不下去了。
2405
+ // 2、创建、删除节点的时候也会找不到(本身这两种操作就不应该进到这个方法)
2243
2406
  while (pos !== -1) {
2244
- pos = code.indexOf(node.name, pos + prefix.length);
2245
2407
  positions.push(pos);
2246
2408
  pos = code.indexOf(prefix, pos + prefix.length);
2409
+ pos = pos === -1 ? pos : code.indexOf(node.name, pos + prefix.length);
2247
2410
  }
2248
2411
  positions.shift();
2249
2412
  // 拿到标识下定义的参数名字
@@ -2290,12 +2453,16 @@ class NaslServer {
2290
2453
  let pos = code.indexOf(prefix);
2291
2454
  // 需要再次定位到processelement对象上,避免process上存在同名参数
2292
2455
  pos = code.indexOf(node.parentNode.name, pos + prefix.length);
2456
+ pos = pos === -1 ? pos : code.indexOf(node.name, pos + prefix.length);
2457
+ // pos === -1:两种情况:
2458
+ // 1、找到最后一个节点了,继续找找不下去了。
2459
+ // 2、创建、删除节点的时候也会找不到(本身这两种操作就不应该进到这个方法)
2293
2460
  while (pos !== -1) {
2294
- pos = code.indexOf(node.name, pos + prefix.length);
2295
2461
  positions.push(pos);
2296
2462
  pos = code.indexOf(prefix, pos + prefix.length);
2297
2463
  // 需要再次定位到processelement对象上,避免process上存在同名参数
2298
- pos = code.indexOf(node.parentNode.name, pos + node.parentNode.name.length);
2464
+ pos = pos === -1 ? pos : code.indexOf(node.parentNode.name, pos + node.parentNode.name.length);
2465
+ pos = pos === -1 ? pos : code.indexOf(node.name, pos + prefix.length);
2299
2466
  }
2300
2467
  // 拿到标识下定义的参数名字
2301
2468
  const promises = positions.map((item) => this.references({
@@ -3402,6 +3569,7 @@ class NaslServer {
3402
3569
  });
3403
3570
  }
3404
3571
  });
3572
+ console.time('全量标注');
3405
3573
  const typesMap = await this.getQuickInfoNodesTypeMap(nodes, true);
3406
3574
  // console.log(typesMap, 'typesMap')
3407
3575
  console.timeEnd('全量标注');
@@ -3454,7 +3622,7 @@ class NaslServer {
3454
3622
  }
3455
3623
  }
3456
3624
  // 旧版本数据查询需要确认是匿名数据结构的 ListTotal 类型
3457
- if (node instanceof concepts_1.CallQueryComponent && node.ideVersion !== '2.11') {
3625
+ if (node instanceof concepts_1.CallQueryComponent && !node.isAutoInfer()) {
3458
3626
  const jsonNode = jsoner.queryNodeByPath(json, node.getNodePath(false));
3459
3627
  jsonNode.typeAnnotation = {
3460
3628
  concept: 'TypeAnnotation',
@@ -3525,7 +3693,7 @@ class NaslServer {
3525
3693
  jsonNode.typeAnnotation = value.toJSON();
3526
3694
  }
3527
3695
  }
3528
- if (node instanceof concepts_1.NewComposite && node.typeAnnotation.typeKind === 'anonymousStructure') {
3696
+ if (node instanceof concepts_1.NewComposite && node.typeAnnotation?.typeKind === 'anonymousStructure') {
3529
3697
  const jsonNode = jsoner.queryNodeByPath(json, node.getNodePath(false));
3530
3698
  jsonNode.typeAnnotation = value.toJSON();
3531
3699
  }
@@ -3929,7 +4097,7 @@ class NaslServer {
3929
4097
  // 当前操作的文件节点
3930
4098
  const { fileNode } = this.getCurrentSource(targetNode);
3931
4099
  // 如果是导入模块就,就引入对应模块,先不处理module和Configuration,下面的内容会自动创建
3932
- if (!fileNode || fileNode instanceof concepts_1.Module || fileNode instanceof concepts_1.Configuration) {
4100
+ if (!fileNode || fileNode instanceof concepts_1.Module || fileNode instanceof concepts_1.Configuration || fileNode instanceof concepts_1.Integration) {
3933
4101
  // module单独处理
3934
4102
  if (fileNode instanceof concepts_1.Module) {
3935
4103
  await this.incidentalAction(action, fileNode, targetNode);
@@ -3980,7 +4148,7 @@ class NaslServer {
3980
4148
  this.changeFileNext();
3981
4149
  }
3982
4150
  else {
3983
- console.log(Array.from(this.filesToCheck));
4151
+ console.info(Array.from(this.filesToCheck));
3984
4152
  await this.getDiagnosticRecordsAndPushAll(Array.from(this.filesToCheck));
3985
4153
  this.filesToCheck.clear();
3986
4154
  }