@lcap/nasl 3.8.0-beta.3 → 3.8.0-beta.5

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 (320) hide show
  1. package/out/automate/engine/utils.js +1 -2
  2. package/out/automate/engine/utils.js.map +1 -1
  3. package/out/bak/translator.js +1 -1
  4. package/out/bak/translator.js.map +1 -1
  5. package/out/common/BaseNode.js +7 -2
  6. package/out/common/BaseNode.js.map +1 -1
  7. package/out/concepts/App__.js +6 -1
  8. package/out/concepts/App__.js.map +1 -1
  9. package/out/concepts/Argument__.js +11 -5
  10. package/out/concepts/Argument__.js.map +1 -1
  11. package/out/concepts/AuthLogicForCallInterface__.js +3 -0
  12. package/out/concepts/AuthLogicForCallInterface__.js.map +1 -1
  13. package/out/concepts/BinaryExpression__.js +49 -2
  14. package/out/concepts/BinaryExpression__.js.map +1 -1
  15. package/out/concepts/BindAttribute__.d.ts +4 -3
  16. package/out/concepts/BindAttribute__.js +121 -42
  17. package/out/concepts/BindAttribute__.js.map +1 -1
  18. package/out/concepts/BindEvent__.js +5 -42
  19. package/out/concepts/BindEvent__.js.map +1 -1
  20. package/out/concepts/BusinessComponent__.d.ts +1 -0
  21. package/out/concepts/BusinessComponent__.js +16 -0
  22. package/out/concepts/BusinessComponent__.js.map +1 -1
  23. package/out/concepts/BusinessLogic__.js +3 -0
  24. package/out/concepts/BusinessLogic__.js.map +1 -1
  25. package/out/concepts/CallConnector__.js +1 -1
  26. package/out/concepts/CallConnector__.js.map +1 -1
  27. package/out/concepts/CallFunction__.js +1 -1
  28. package/out/concepts/CallFunction__.js.map +1 -1
  29. package/out/concepts/CallLogic__.d.ts +6 -1
  30. package/out/concepts/CallLogic__.js +58 -17
  31. package/out/concepts/CallLogic__.js.map +1 -1
  32. package/out/concepts/Connection__.d.ts +4 -0
  33. package/out/concepts/Connection__.js +15 -0
  34. package/out/concepts/Connection__.js.map +1 -1
  35. package/out/concepts/DatabaseTypeAnnotation__.d.ts +2 -0
  36. package/out/concepts/DatabaseTypeAnnotation__.js +20 -0
  37. package/out/concepts/DatabaseTypeAnnotation__.js.map +1 -1
  38. package/out/concepts/End__.js +5 -1
  39. package/out/concepts/End__.js.map +1 -1
  40. package/out/concepts/EntityProperty__.js +2 -0
  41. package/out/concepts/EntityProperty__.js.map +1 -1
  42. package/out/concepts/Entity__.d.ts +1 -0
  43. package/out/concepts/Entity__.js +24 -1
  44. package/out/concepts/Entity__.js.map +1 -1
  45. package/out/concepts/EnumItem__.d.ts +12 -0
  46. package/out/concepts/EnumItem__.js +49 -5
  47. package/out/concepts/EnumItem__.js.map +1 -1
  48. package/out/concepts/Enum__.js +4 -1
  49. package/out/concepts/Enum__.js.map +1 -1
  50. package/out/concepts/ForEachStatement__.js +1 -1
  51. package/out/concepts/ForEachStatement__.js.map +1 -1
  52. package/out/concepts/FrontendLibrary__.d.ts +46 -46
  53. package/out/concepts/FrontendLibrary__.js +34 -36
  54. package/out/concepts/FrontendLibrary__.js.map +1 -1
  55. package/out/concepts/I18nInfo__.d.ts +1 -0
  56. package/out/concepts/I18nInfo__.js +7 -0
  57. package/out/concepts/I18nInfo__.js.map +1 -1
  58. package/out/concepts/IfStatement__.js +2 -2
  59. package/out/concepts/IfStatement__.js.map +1 -1
  60. package/out/concepts/Interface__.js +4 -1
  61. package/out/concepts/Interface__.js.map +1 -1
  62. package/out/concepts/Logic__.d.ts +2 -3
  63. package/out/concepts/Logic__.js +33 -8
  64. package/out/concepts/Logic__.js.map +1 -1
  65. package/out/concepts/MatchCase__.d.ts +2 -2
  66. package/out/concepts/MatchCase__.js +7 -7
  67. package/out/concepts/MatchCase__.js.map +1 -1
  68. package/out/concepts/NewComposite__.js +2 -1
  69. package/out/concepts/NewComposite__.js.map +1 -1
  70. package/out/concepts/NewList__.js +2 -1
  71. package/out/concepts/NewList__.js.map +1 -1
  72. package/out/concepts/NewMap__.js +2 -1
  73. package/out/concepts/NewMap__.js.map +1 -1
  74. package/out/concepts/OqlQueryComponent__.js +3 -11
  75. package/out/concepts/OqlQueryComponent__.js.map +1 -1
  76. package/out/concepts/OverriddenLogic__.js +7 -0
  77. package/out/concepts/OverriddenLogic__.js.map +1 -1
  78. package/out/concepts/Param__.js +2 -1
  79. package/out/concepts/Param__.js.map +1 -1
  80. package/out/concepts/ProcessElementV2__.d.ts +4 -5
  81. package/out/concepts/ProcessElementV2__.js +12 -17
  82. package/out/concepts/ProcessElementV2__.js.map +1 -1
  83. package/out/concepts/ProcessElement__.d.ts +3 -4
  84. package/out/concepts/ProcessElement__.js +44 -46
  85. package/out/concepts/ProcessElement__.js.map +1 -1
  86. package/out/concepts/ProcessV2__.d.ts +5 -0
  87. package/out/concepts/ProcessV2__.js +30 -2
  88. package/out/concepts/ProcessV2__.js.map +1 -1
  89. package/out/concepts/Process__.d.ts +5 -0
  90. package/out/concepts/Process__.js +28 -0
  91. package/out/concepts/Process__.js.map +1 -1
  92. package/out/concepts/QueryFromExpression__.js +2 -2
  93. package/out/concepts/QueryFromExpression__.js.map +1 -1
  94. package/out/concepts/QueryJoinExpression__.js +2 -2
  95. package/out/concepts/QueryJoinExpression__.js.map +1 -1
  96. package/out/concepts/Return__.d.ts +1 -1
  97. package/out/concepts/Return__.js +2 -1
  98. package/out/concepts/Return__.js.map +1 -1
  99. package/out/concepts/StaticString__.d.ts +4 -0
  100. package/out/concepts/StaticString__.js +11 -0
  101. package/out/concepts/StaticString__.js.map +1 -1
  102. package/out/concepts/StructureProperty__.js +5 -2
  103. package/out/concepts/StructureProperty__.js.map +1 -1
  104. package/out/concepts/Structure__.js +9 -3
  105. package/out/concepts/Structure__.js.map +1 -1
  106. package/out/concepts/SubLogic__.d.ts +1 -3
  107. package/out/concepts/SubLogic__.js +14 -8
  108. package/out/concepts/SubLogic__.js.map +1 -1
  109. package/out/concepts/Transactional__.d.ts +1 -0
  110. package/out/concepts/Transactional__.js +7 -0
  111. package/out/concepts/Transactional__.js.map +1 -1
  112. package/out/concepts/TypeParam__.d.ts +4 -0
  113. package/out/concepts/TypeParam__.js +3 -0
  114. package/out/concepts/TypeParam__.js.map +1 -1
  115. package/out/concepts/ValidationRule__.d.ts +1 -6
  116. package/out/concepts/ValidationRule__.js +9 -6
  117. package/out/concepts/ValidationRule__.js.map +1 -1
  118. package/out/concepts/Variable__.d.ts +1 -1
  119. package/out/concepts/Variable__.js +7 -2
  120. package/out/concepts/Variable__.js.map +1 -1
  121. package/out/concepts/ViewElement__.d.ts +2 -0
  122. package/out/concepts/ViewElement__.js +130 -47
  123. package/out/concepts/ViewElement__.js.map +1 -1
  124. package/out/concepts/View__.d.ts +8 -0
  125. package/out/concepts/View__.js +123 -7
  126. package/out/concepts/View__.js.map +1 -1
  127. package/out/concepts/basics/stdlib/nasl.processV2.js +2 -2
  128. package/out/concepts/basics/stdlib/nasl.processV2.js.map +1 -1
  129. package/out/concepts/basics/stdlib/nasl.ui.js +1 -1
  130. package/out/concepts/basics/stdlib/nasl.ui.js.map +1 -1
  131. package/out/concepts/basics/stdlib/nasl.validation.js +110 -4
  132. package/out/concepts/basics/stdlib/nasl.validation.js.map +1 -1
  133. package/out/generator/genBundleFiles.d.ts +2 -0
  134. package/out/generator/genBundleFiles.js +51 -37
  135. package/out/generator/genBundleFiles.js.map +1 -1
  136. package/out/generator/genMetaData.js +20 -26
  137. package/out/generator/genMetaData.js.map +1 -1
  138. package/out/generator/release-body/body.js +8 -6
  139. package/out/generator/release-body/body.js.map +1 -1
  140. package/out/generator/release-body/index.d.ts +1 -0
  141. package/out/generator/release-body/index.js +1 -0
  142. package/out/generator/release-body/index.js.map +1 -1
  143. package/out/generator/release-body/utils.js +1 -1
  144. package/out/generator/release-body/utils.js.map +1 -1
  145. package/out/natural/genNaturalTS.d.ts +56 -24
  146. package/out/natural/genNaturalTS.js +182 -112
  147. package/out/natural/genNaturalTS.js.map +1 -1
  148. package/out/natural/getContext/getUILib.js +4 -2
  149. package/out/natural/getContext/getUILib.js.map +1 -1
  150. package/out/natural/getContext/index.d.ts +34 -25
  151. package/out/natural/getContext/index.js +304 -157
  152. package/out/natural/getContext/index.js.map +1 -1
  153. package/out/natural/index.d.ts +1 -0
  154. package/out/natural/index.js +1 -0
  155. package/out/natural/index.js.map +1 -1
  156. package/out/natural/tools.d.ts +11 -0
  157. package/out/natural/tools.js +155 -0
  158. package/out/natural/tools.js.map +1 -0
  159. package/out/natural/transformTS2UI.js +84 -22
  160. package/out/natural/transformTS2UI.js.map +1 -1
  161. package/out/natural/transformTSCode.js +83 -22
  162. package/out/natural/transformTSCode.js.map +1 -1
  163. package/out/server/formatTsUtils.js +17 -1
  164. package/out/server/formatTsUtils.js.map +1 -1
  165. package/out/server/getLogics.js +1 -4
  166. package/out/server/getLogics.js.map +1 -1
  167. package/out/server/naslServer.js +285 -32
  168. package/out/server/naslServer.js.map +1 -1
  169. package/out/server/translator.js +5 -1
  170. package/out/server/translator.js.map +1 -1
  171. package/out/templator/genCreateBlock.js +5 -18
  172. package/out/templator/genCreateBlock.js.map +1 -1
  173. package/out/templator/genCurdMultipleKeyBlock.js +11 -32
  174. package/out/templator/genCurdMultipleKeyBlock.js.map +1 -1
  175. package/out/templator/genGetBlock.js +1 -2
  176. package/out/templator/genGetBlock.js.map +1 -1
  177. package/out/templator/genListViewBlock.js +6 -4
  178. package/out/templator/genListViewBlock.js.map +1 -1
  179. package/out/templator/genSelectBlock.js +82 -59
  180. package/out/templator/genSelectBlock.js.map +1 -1
  181. package/out/templator/genTableBlock.js +4 -4
  182. package/out/templator/genTableBlock.js.map +1 -1
  183. package/out/templator/genUpdateBlock.js +2 -15
  184. package/out/templator/genUpdateBlock.js.map +1 -1
  185. package/out/templator/utils.d.ts +1 -1
  186. package/out/templator/utils.js +1 -1
  187. package/out/templator/utils.js.map +1 -1
  188. package/out/translator/types.d.ts +4 -0
  189. package/out/translator/utils.d.ts +1 -0
  190. package/out/translator/utils.js +6 -1
  191. package/out/translator/utils.js.map +1 -1
  192. package/out/utils/env.d.ts +4 -0
  193. package/out/utils/env.js +6 -3
  194. package/out/utils/env.js.map +1 -1
  195. package/out/utils/index.d.ts +19 -0
  196. package/out/utils/index.js +61 -1
  197. package/out/utils/index.js.map +1 -1
  198. package/out/utils/language-cache/constant.d.ts +18 -0
  199. package/out/utils/language-cache/constant.js +35 -0
  200. package/out/utils/language-cache/constant.js.map +1 -0
  201. package/out/utils/language-cache/index.d.ts +2 -0
  202. package/out/utils/language-cache/index.js +19 -0
  203. package/out/utils/language-cache/index.js.map +1 -0
  204. package/out/utils/language-cache/nasl.d.ts +10 -0
  205. package/out/utils/language-cache/nasl.js +98 -0
  206. package/out/utils/language-cache/nasl.js.map +1 -0
  207. package/out/utils/language-cache/types.d.ts +44 -0
  208. package/out/utils/language-cache/types.js +4 -0
  209. package/out/utils/language-cache/types.js.map +1 -0
  210. package/out/utils/time-slicing/controller.js.map +1 -1
  211. package/out/utils/types.d.ts +17 -0
  212. package/package.json +3 -2
  213. package/sandbox/stdlib/nasl.core.ts +15 -11
  214. package/sandbox/stdlib/nasl.oql.ts +5 -1
  215. package/sandbox/stdlib/nasl.processV2.ts +5 -4
  216. package/sandbox/stdlib/nasl.ui.components.pc.ts +225 -225
  217. package/sandbox/stdlib/nasl.ui.ts +10 -0
  218. package/sandbox/stdlib/nasl.util.ts +11 -0
  219. package/sandbox/stdlib/nasl.validation.ts +3 -2
  220. package/sandbox-natural/stdlib/nasl.ui.pre.d.ts +1 -1
  221. package/sandbox-natural/stdlib/nasl.ui.ts +2 -2
  222. package/sandbox-natural/stdlib/nasl.util.ts +2 -2
  223. package/src/automate/engine/utils.js +1 -2
  224. package/src/bak/translator.js +1 -1
  225. package/src/common/BaseNode.ts +7 -3
  226. package/src/concepts/App__.ts +9 -1
  227. package/src/concepts/Argument__.ts +10 -5
  228. package/src/concepts/AuthLogicForCallInterface__.ts +3 -0
  229. package/src/concepts/BinaryExpression__.ts +46 -2
  230. package/src/concepts/BindAttribute__.ts +144 -46
  231. package/src/concepts/BindEvent__.ts +8 -47
  232. package/src/concepts/BusinessComponent__.ts +17 -0
  233. package/src/concepts/BusinessLogic__.ts +3 -0
  234. package/src/concepts/CallConnector__.ts +1 -1
  235. package/src/concepts/CallFunction__.ts +1 -1
  236. package/src/concepts/CallLogic__.ts +63 -17
  237. package/src/concepts/Connection__.ts +16 -0
  238. package/src/concepts/DatabaseTypeAnnotation__.ts +11 -0
  239. package/src/concepts/End__.ts +5 -1
  240. package/src/concepts/EntityProperty__.ts +5 -0
  241. package/src/concepts/Entity__.ts +29 -1
  242. package/src/concepts/EnumItem__.ts +64 -1
  243. package/src/concepts/Enum__.ts +6 -1
  244. package/src/concepts/ForEachStatement__.ts +1 -1
  245. package/src/concepts/FrontendLibrary__.ts +78 -80
  246. package/src/concepts/I18nInfo__.ts +5 -0
  247. package/src/concepts/IfStatement__.ts +2 -2
  248. package/src/concepts/Interface__.ts +6 -1
  249. package/src/concepts/Logic__.ts +39 -10
  250. package/src/concepts/MatchCase__.ts +8 -9
  251. package/src/concepts/NewComposite__.ts +2 -1
  252. package/src/concepts/NewList__.ts +2 -1
  253. package/src/concepts/NewMap__.ts +2 -1
  254. package/src/concepts/OqlQueryComponent__.ts +3 -11
  255. package/src/concepts/OverriddenLogic__.ts +7 -0
  256. package/src/concepts/Param__.ts +1 -0
  257. package/src/concepts/ProcessElementV2__.ts +14 -16
  258. package/src/concepts/ProcessElement__.ts +16 -16
  259. package/src/concepts/ProcessV2__.ts +39 -3
  260. package/src/concepts/Process__.ts +36 -0
  261. package/src/concepts/QueryFromExpression__.ts +2 -2
  262. package/src/concepts/QueryJoinExpression__.ts +2 -2
  263. package/src/concepts/Return__.ts +2 -1
  264. package/src/concepts/StaticString__.ts +12 -0
  265. package/src/concepts/StructureProperty__.ts +7 -2
  266. package/src/concepts/Structure__.ts +11 -3
  267. package/src/concepts/SubLogic__.ts +15 -9
  268. package/src/concepts/Transactional__.ts +5 -0
  269. package/src/concepts/TypeParam__.ts +6 -0
  270. package/src/concepts/ValidationRule__.ts +7 -6
  271. package/src/concepts/Variable__.ts +7 -2
  272. package/src/concepts/ViewElement__.ts +130 -47
  273. package/src/concepts/View__.ts +157 -8
  274. package/src/concepts/basics/stdlib/nasl.processV2.ts +2 -2
  275. package/src/concepts/basics/stdlib/nasl.ui.ts +1 -1
  276. package/src/concepts/basics/stdlib/nasl.validation.ts +111 -4
  277. package/src/generator/genBundleFiles.ts +53 -39
  278. package/src/generator/genMetaData.ts +21 -26
  279. package/src/generator/release-body/body.ts +9 -6
  280. package/src/generator/release-body/index.ts +1 -0
  281. package/src/generator/release-body/utils.ts +4 -2
  282. package/src/natural/genNaturalTS.ts +327 -141
  283. package/src/natural/getContext/getUILib.ts +4 -2
  284. package/src/natural/getContext/index.ts +348 -171
  285. package/src/natural/index.ts +1 -0
  286. package/src/natural/tools.ts +130 -0
  287. package/src/natural/transformTS2UI.ts +84 -22
  288. package/src/natural/transformTSCode.ts +83 -22
  289. package/src/server/formatTsUtils.ts +21 -1
  290. package/src/server/getLogics.ts +1 -4
  291. package/src/server/naslServer.ts +302 -33
  292. package/src/server/translator.ts +5 -1
  293. package/src/templator/genCreateBlock.ts +5 -18
  294. package/src/templator/genCurdMultipleKeyBlock.ts +14 -32
  295. package/src/templator/genGetBlock.ts +2 -4
  296. package/src/templator/genListViewBlock.ts +6 -4
  297. package/src/templator/genSelectBlock.ts +88 -61
  298. package/src/templator/genTableBlock.ts +4 -4
  299. package/src/templator/genUpdateBlock.ts +2 -15
  300. package/src/templator/utils.ts +1 -1
  301. package/src/translator/types.ts +4 -0
  302. package/src/translator/utils.ts +6 -0
  303. package/src/utils/env.ts +5 -4
  304. package/src/utils/index.ts +50 -1
  305. package/src/utils/language-cache/constant.ts +37 -0
  306. package/src/utils/language-cache/index.ts +2 -0
  307. package/src/utils/language-cache/nasl.ts +83 -0
  308. package/src/utils/language-cache/types.ts +48 -0
  309. package/src/utils/time-slicing/controller.ts +0 -1
  310. package/src/utils/types.ts +20 -0
  311. package/test/concepts/call-logic/__snapshots__/getQuickInfoOffset.spec.ts.snap +13 -13
  312. package/test/concepts/call-logic/__snapshots__/toEmbeddedTS.spec.ts.snap +12 -12
  313. package/test/concepts/validation-rule/__snapshots__/toEmbeddedTS.spec.ts.snap +1 -2
  314. package/test/concepts/view-element/__snapshots__/toEmbeddedTS.spec.ts.snap +221 -217
  315. package/ts-worker/bundle.js +1 -1
  316. package/ts-worker/src/index.js +0 -1
  317. package/out/utils/delay/index.d.ts +0 -0
  318. package/out/utils/delay/index.js +0 -1
  319. package/out/utils/delay/index.js.map +0 -1
  320. package/src/utils/delay/index.ts +0 -0
@@ -2,3 +2,4 @@ export * from './genNaturalTS';
2
2
  export * from './transformTSCode';
3
3
  export * from './transformTS2UI';
4
4
  export * from './getContext/getUILib';
5
+ export * from './tools';
@@ -0,0 +1,130 @@
1
+ import { App, BaseNode } from "src/concepts";
2
+ import * as utils from '../utils';
3
+
4
+ // 获取当前逻辑的类型
5
+ export const getLogicType = (activeLogic: any) => {
6
+ const { parentNode } = activeLogic || {};
7
+ let logicType = 'global_logic';
8
+ if (parentNode?.concept === 'View') {
9
+ logicType = 'view_logic';
10
+ } else if (parentNode?.concept === 'BindEvent') {
11
+ logicType = 'event_logic';
12
+ }
13
+ if (activeLogic?.concept === 'BusinessLogic') {
14
+ logicType = 'business_Logic';
15
+ }
16
+ return logicType;
17
+ };
18
+
19
+ // 获取所有未使用的 module
20
+ export const getUsedModule = (json: BaseNode) => {
21
+ const useModule = [] as any;
22
+ const conceptMap = ['CallInterface', 'CallConnector', 'CallLogic'];
23
+ utils.traverse(({ node }: { node: any; }) => {
24
+ if (conceptMap.includes(node.concept)) {
25
+ if (/(apis\.|connector\.|extensions\.)/.test(node.calleeNamespace)) {
26
+ const symbol = node.calleeNamespace.match(/(\w+)(?=\.)|(\w+$)/g)[1];
27
+ const item = {
28
+ symbol,
29
+ key: symbol,
30
+ node,
31
+ } as any;
32
+ useModule.push(item);
33
+ }
34
+ }
35
+ if (node.concept === 'ViewElement') {
36
+ const symbol = utils.kebab2Camel(node.tag);
37
+ const item = {
38
+ symbol,
39
+ key: symbol,
40
+ node,
41
+ } as any;
42
+ useModule.push(item);
43
+ }
44
+ }, { node: json }, { mode: 'anyObject' });
45
+ return useModule;
46
+ };
47
+
48
+
49
+ /**
50
+ * 根据生成的 NASL JSON,获取未导入的模块
51
+ * @param json: 当前生成的 NASL JSON
52
+ * @param app: 当前应用
53
+ * @param material: 召回的所有 Module
54
+ * @returns 需要导入的所有 Module 信息,包含 category、symbol、version
55
+ */
56
+ export const getUnImportedModulesForLogic = (json: BaseNode, app: App, material: any) => {
57
+ const useModule = getUsedModule(json);
58
+ const needImportModule = {
59
+ interfaces: new Map(),
60
+ connectors: new Map(),
61
+ library: new Map(),
62
+ extensionMaterials: new Map(),
63
+ needImportConnector: false
64
+ } as any;
65
+
66
+ useModule.forEach((item: any) => {
67
+ if (item.node.concept === 'CallInterface') {
68
+ // 从app.interfaceDependencies中找到对应的接口
69
+ const interfaceNode = app.interfaceDependencies.find((node: any) => node.name === item.symbol);
70
+ if (!interfaceNode) {
71
+ item.category = 'interface';
72
+ const key = `${item.symbol}-${item?.node?.calleeName}`;
73
+ item.key = key;
74
+ needImportModule.interfaces.set(key, item);
75
+ }
76
+ } else if (item.node.concept === 'CallConnector') {
77
+ item.category = 'connector';
78
+ const connectorNode = app.connectorDependencies.find((node: any) => node.name === item.symbol);
79
+
80
+ // 如果 连接器 不存在,则需要导入并初始化连接
81
+ if (!connectorNode) {
82
+ item.operator = 'importAndInit';
83
+ item.version = material?.connectors.find((node: any) => node.name === item.symbol).version;
84
+ needImportModule.needImportConnector = true;
85
+ } else {
86
+ item.version = connectorNode.version;
87
+ // 查找连接
88
+ const connection = app.connections.find((conn: any) => conn.connector.name === item.symbol);
89
+ // 如果 连接器 已存在,且连接已经被初始化过,需要修改生成 logic 中的名字,utils.traverse 修改
90
+ // 如果 连接器 已存在,且连接未被初始化过,则需要初始化连接
91
+ if (connection) {
92
+ item.operator = 'rename';
93
+ item.rename = { newName: connection.name, oldName: item.node.calleeConnectionName };
94
+ } else {
95
+ item.operator = 'init';
96
+ }
97
+ }
98
+
99
+ needImportModule.connectors.set(item.symbol, item);
100
+ } else if (item.node.concept === 'CallLogic') {
101
+ // 从app.logicDependencies中找到对应的逻辑
102
+ item.category = 'library';
103
+ const logicNode = app.dependencies.find((node: any) => node.name === item.symbol);
104
+ if (!logicNode) {
105
+ item.version = material?.dependencies.find((node: any) => node.name === item.symbol).version;
106
+ needImportModule.library.set(item.symbol, item);
107
+ }
108
+ } else if (item.node.concept === 'ViewElement') {
109
+ const name = utils.kebab2Camel(item.node.tag);
110
+ const module = material?.extensionMaterials.find((node: any) => utils.kebab2Camel(node.name) === name);
111
+ const imported = app.dependencies.find((node: any) => node.name === module?.libraryName);
112
+ if (module && module.libraryName && !imported) {
113
+ const { libraryName } = module;
114
+ item.category = 'library';
115
+ item.key = `${libraryName}-${name}`;
116
+ item.symbol = libraryName;
117
+ item.version = material?.dependencies.find((node: any) => node.name === libraryName).version;
118
+ needImportModule.extensionMaterials.set(name, item);
119
+ }
120
+ }
121
+ });
122
+
123
+ needImportModule.interfaces = Array.from(needImportModule.interfaces.values());
124
+ needImportModule.connectors = Array.from(needImportModule.connectors.values());
125
+ needImportModule.library = Array.from(needImportModule.library.values());
126
+ needImportModule.extensionMaterials = Array.from(needImportModule.extensionMaterials.values());
127
+
128
+ return needImportModule;
129
+ };
130
+
@@ -19,6 +19,13 @@ function flatMemberExpression(node: babelTypes.Node): Array<babelTypes.Node> {
19
19
  return [...flatMemberExpression(node.object), node.property];
20
20
  return [node];
21
21
  }
22
+
23
+ function flatMembers(node: naslTypes.MemberExpression): Array<naslTypes.MemberExpression> {
24
+ if (node.concept === 'MemberExpression')
25
+ return [...flatMembers(((node as any)?.object)), node];
26
+ return [];
27
+ }
28
+
22
29
  function flatMatchPatternsExpression(node: any): Array<babelTypes.Node> {
23
30
  if (node.concept === 'BinaryExpression') {
24
31
  if (node.operator === '||') {
@@ -65,6 +72,13 @@ function transformTypeAnnotation(node: babelTypes.TSType): naslTypes.TypeAnnotat
65
72
  typeNamespace: (node as any).typeNamespace,
66
73
  });
67
74
  }
75
+
76
+ if (['ValidateResult', 'ValidateEvent'].includes(typeName)) {
77
+ return naslTypes.TypeAnnotation.createReference(typeName, {
78
+ typeNamespace: 'nasl.ui'
79
+ });
80
+ }
81
+
68
82
  if (typeName === 'Any' || typeName === 'any') {
69
83
  return undefined;
70
84
  }
@@ -89,7 +103,7 @@ function transformTypeAnnotation(node: babelTypes.TSType): naslTypes.TypeAnnotat
89
103
  if (node?.typeName?.type === 'TSQualifiedName') {
90
104
  const allTypeName = generate(node?.typeName?.left as any)?.code;
91
105
  // 实体、枚举、结构体
92
- if (/^app.dataSources|.enums|.structures/.test(allTypeName)) {
106
+ if (/^app.dataSources|.enums|.structures|nasl.ui/.test(allTypeName)) {
93
107
  const curTypeName = (node?.typeName as any)?.right?.name;
94
108
  return naslTypes.TypeAnnotation.createReference(curTypeName, {
95
109
  typeNamespace: allTypeName,
@@ -127,6 +141,8 @@ function transformTypeAnnotation(node: babelTypes.TSType): naslTypes.TypeAnnotat
127
141
  // 处理参数
128
142
  function transformParam(node: babelTypes.Identifier): naslTypes.Param {
129
143
  const typeAnnotation = (node.typeAnnotation as babelTypes.TSTypeAnnotation)?.typeAnnotation;
144
+ const exclude = ['event'];
145
+ if (exclude.includes(node.name)) return null;
130
146
  return new naslTypes.Param({
131
147
  name: node.name,
132
148
  typeAnnotation: typeAnnotation ? transformTypeAnnotation(typeAnnotation) : null,
@@ -219,14 +235,29 @@ function handleNewExpression(calleeName: String, node: any, type?: string) {
219
235
  const assignmentLines: any = [];
220
236
  node?.arguments?.[0]?.properties.forEach((arg: any, index: number) => {
221
237
  properties.push(transformNode2Expression(arg.key));
222
- rights.push(new naslTypes.SelectMembers({
223
- expression: transformNode2Expression(arg.value)
224
- }));
225
- if (arg?.value) {
226
- assignmentLines.push(new naslTypes.AssignmentLine({
227
- leftIndex: [0, index],
228
- rightIndex: [index],
238
+ if (arg.value.type === 'MemberExpression') {
239
+ const expression = flatMemberExpression(arg.value);
240
+ const members = flatMembers(transformNode2Expression(arg.value) as any);
241
+ rights.push(new naslTypes.SelectMembers({
242
+ expression: transformNode2Expression(expression[0]),
243
+ members,
229
244
  }));
245
+ if (arg?.value) {
246
+ assignmentLines.push(new naslTypes.AssignmentLine({
247
+ leftIndex: [0, index],
248
+ rightIndex: [index, index],
249
+ }));
250
+ }
251
+ } else {
252
+ rights.push(new naslTypes.SelectMembers({
253
+ expression: transformNode2Expression(arg.value)
254
+ }));
255
+ if (arg?.value) {
256
+ assignmentLines.push(new naslTypes.AssignmentLine({
257
+ leftIndex: [0, index],
258
+ rightIndex: [index],
259
+ }));
260
+ }
230
261
  }
231
262
  });
232
263
  const parameters = node?.typeParameters?.params?.[0] || {};
@@ -261,14 +292,29 @@ function handleNewExpression(calleeName: String, node: any, type?: string) {
261
292
  const assignmentLines: any = [];
262
293
  node?.arguments?.[0]?.properties.forEach((arg: any, index: number) => {
263
294
  properties.push(transformNode2Expression(arg.key));
264
- rights.push(new naslTypes.SelectMembers({
265
- expression: transformNode2Expression(arg.value)
266
- }));
267
- if (arg?.value) {
268
- assignmentLines.push(new naslTypes.AssignmentLine({
269
- leftIndex: [0, index],
270
- rightIndex: [index],
295
+ if (arg.value.type === 'MemberExpression') {
296
+ const expression = flatMemberExpression(arg.value);
297
+ const members = flatMembers(transformNode2Expression(arg.value) as any);
298
+ rights.push(new naslTypes.SelectMembers({
299
+ expression: transformNode2Expression(expression[0]),
300
+ members,
271
301
  }));
302
+ if (arg?.value) {
303
+ assignmentLines.push(new naslTypes.AssignmentLine({
304
+ leftIndex: [0, index],
305
+ rightIndex: [index, index],
306
+ }));
307
+ }
308
+ } else {
309
+ rights.push(new naslTypes.SelectMembers({
310
+ expression: transformNode2Expression(arg.value)
311
+ }));
312
+ if (arg?.value) {
313
+ assignmentLines.push(new naslTypes.AssignmentLine({
314
+ leftIndex: [0, index],
315
+ rightIndex: [index],
316
+ }));
317
+ }
272
318
  }
273
319
  });
274
320
  const parameters = node?.typeParameters?.params?.[0] || {};
@@ -304,14 +350,29 @@ function handleNewExpression(calleeName: String, node: any, type?: string) {
304
350
  const assignmentLines: any = [];
305
351
  node?.arguments?.[0]?.properties?.forEach((arg: any, index: number) => {
306
352
  properties.push(transformNode2Expression(arg.key));
307
- rights.push(new naslTypes.SelectMembers({
308
- expression: transformNode2Expression(arg.value)
309
- }));
310
- if (arg?.value) {
311
- assignmentLines.push(new naslTypes.AssignmentLine({
312
- leftIndex: [0, index],
313
- rightIndex: [index],
353
+ if (arg.value.type === 'MemberExpression') {
354
+ const expression = flatMemberExpression(arg.value);
355
+ const members = flatMembers(transformNode2Expression(arg.value) as any);
356
+ rights.push(new naslTypes.SelectMembers({
357
+ expression: transformNode2Expression(expression[0]),
358
+ members,
314
359
  }));
360
+ if (arg?.value) {
361
+ assignmentLines.push(new naslTypes.AssignmentLine({
362
+ leftIndex: [0, index],
363
+ rightIndex: [index, index],
364
+ }));
365
+ }
366
+ } else {
367
+ rights.push(new naslTypes.SelectMembers({
368
+ expression: transformNode2Expression(arg.value)
369
+ }));
370
+ if (arg?.value) {
371
+ assignmentLines.push(new naslTypes.AssignmentLine({
372
+ leftIndex: [0, index],
373
+ rightIndex: [index],
374
+ }));
375
+ }
315
376
  }
316
377
  structureProperties.push(new naslTypes.StructureProperty({
317
378
  name: arg?.key?.name,
@@ -1187,6 +1248,7 @@ function transformNode2View(node: babelTypes.FunctionDeclaration, root?: ParseRe
1187
1248
  if (item.type === 'ReturnStatement' && item?.argument?.type === 'ArrayExpression') {
1188
1249
  viewItem?.forEach((element: any) => {
1189
1250
  json.push(element.aiParams);
1251
+ view.addViewElement(element);
1190
1252
  });
1191
1253
  }
1192
1254
  if (viewItem?.concept === 'Variable') {
@@ -29,6 +29,13 @@ function flatMemberExpression(node: babelTypes.Node): Array<babelTypes.Node> {
29
29
  return [...flatMemberExpression(node.object), node.property];
30
30
  return [node];
31
31
  }
32
+
33
+ function flatMembers(node: naslTypes.MemberExpression): Array<naslTypes.MemberExpression> {
34
+ if (node.concept === 'MemberExpression')
35
+ return [...flatMembers(((node as any)?.object)), node];
36
+ return [];
37
+ }
38
+
32
39
  function flatMatchPatternsExpression(node: any): Array<babelTypes.Node> {
33
40
  if (node.concept === 'BinaryExpression') {
34
41
  if (node.operator === '||') {
@@ -79,6 +86,13 @@ export function transformTSCode(tsCode: string, contextLogicName: string, type?:
79
86
  typeNamespace: (node as any).typeNamespace,
80
87
  });
81
88
  }
89
+
90
+ if (['ValidateResult', 'ValidateEvent'].includes(typeName)) {
91
+ return naslTypes.TypeAnnotation.createReference(typeName, {
92
+ typeNamespace: 'nasl.ui'
93
+ });
94
+ }
95
+
82
96
  if (typeName === 'Any' || typeName === 'any') {
83
97
  return undefined;
84
98
  }
@@ -103,7 +117,7 @@ export function transformTSCode(tsCode: string, contextLogicName: string, type?:
103
117
  if (node?.typeName?.type === 'TSQualifiedName') {
104
118
  const allTypeName = generate(node?.typeName?.left as any)?.code;
105
119
  // 实体、枚举、结构体
106
- if (/^app.dataSources|.enums|.structures/.test(allTypeName)) {
120
+ if (/^app.dataSources|.enums|.structures|nasl.ui/.test(allTypeName)) {
107
121
  const curTypeName = (node?.typeName as any)?.right?.name;
108
122
  return naslTypes.TypeAnnotation.createReference(curTypeName, {
109
123
  typeNamespace: allTypeName,
@@ -139,6 +153,8 @@ export function transformTSCode(tsCode: string, contextLogicName: string, type?:
139
153
  }
140
154
  function transformParam(node: babelTypes.Identifier): naslTypes.Param {
141
155
  const typeAnnotation = (node.typeAnnotation as babelTypes.TSTypeAnnotation)?.typeAnnotation;
156
+ const exclude = ['event'];
157
+ if (exclude.includes(node.name)) return null;
142
158
  return new naslTypes.Param({
143
159
  name: node.name,
144
160
  typeAnnotation: typeAnnotation ? transformTypeAnnotation(typeAnnotation) : null,
@@ -204,14 +220,29 @@ export function transformTSCode(tsCode: string, contextLogicName: string, type?:
204
220
  const assignmentLines: any = [];
205
221
  node?.arguments?.[0]?.properties.forEach((arg: any, index: number) => {
206
222
  properties.push(transformLogicNode(arg.key));
207
- rights.push(new naslTypes.SelectMembers({
208
- expression: transformLogicNode(arg.value)
209
- }));
210
- if (arg?.value) {
211
- assignmentLines.push(new naslTypes.AssignmentLine({
212
- leftIndex: [0, index],
213
- rightIndex: [index],
223
+ if (arg.value.type === 'MemberExpression') {
224
+ const expression = flatMemberExpression(arg.value);
225
+ const members = flatMembers(transformLogicNode(arg.value) as any);
226
+ rights.push(new naslTypes.SelectMembers({
227
+ expression: transformLogicNode(expression[0]),
228
+ members,
229
+ }));
230
+ if (arg?.value) {
231
+ assignmentLines.push(new naslTypes.AssignmentLine({
232
+ leftIndex: [0, index],
233
+ rightIndex: [index, index],
234
+ }));
235
+ }
236
+ } else {
237
+ rights.push(new naslTypes.SelectMembers({
238
+ expression: transformLogicNode(arg.value)
214
239
  }));
240
+ if (arg?.value) {
241
+ assignmentLines.push(new naslTypes.AssignmentLine({
242
+ leftIndex: [0, index],
243
+ rightIndex: [index],
244
+ }));
245
+ }
215
246
  }
216
247
  });
217
248
  const parameters = node?.typeParameters?.params?.[0] || {};
@@ -246,14 +277,29 @@ export function transformTSCode(tsCode: string, contextLogicName: string, type?:
246
277
  const assignmentLines: any = [];
247
278
  node?.arguments?.[0]?.properties.forEach((arg: any, index: number) => {
248
279
  properties.push(transformLogicNode(arg.key));
249
- rights.push(new naslTypes.SelectMembers({
250
- expression: transformLogicNode(arg.value)
251
- }));
252
- if (arg?.value) {
253
- assignmentLines.push(new naslTypes.AssignmentLine({
254
- leftIndex: [0, index],
255
- rightIndex: [index],
280
+ if (arg.value.type === 'MemberExpression') {
281
+ const expression = flatMemberExpression(arg.value);
282
+ const members = flatMembers(transformLogicNode(arg.value) as any);
283
+ rights.push(new naslTypes.SelectMembers({
284
+ expression: transformLogicNode(expression[0]),
285
+ members,
286
+ }));
287
+ if (arg?.value) {
288
+ assignmentLines.push(new naslTypes.AssignmentLine({
289
+ leftIndex: [0, index],
290
+ rightIndex: [index, index],
291
+ }));
292
+ }
293
+ } else {
294
+ rights.push(new naslTypes.SelectMembers({
295
+ expression: transformLogicNode(arg.value)
256
296
  }));
297
+ if (arg?.value) {
298
+ assignmentLines.push(new naslTypes.AssignmentLine({
299
+ leftIndex: [0, index],
300
+ rightIndex: [index],
301
+ }));
302
+ }
257
303
  }
258
304
  });
259
305
  const parameters = node?.typeParameters?.params?.[0] || {};
@@ -289,14 +335,29 @@ export function transformTSCode(tsCode: string, contextLogicName: string, type?:
289
335
  const assignmentLines: any = [];
290
336
  node?.arguments?.[0]?.properties?.forEach((arg: any, index: number) => {
291
337
  properties.push(transformLogicNode(arg.key));
292
- rights.push(new naslTypes.SelectMembers({
293
- expression: transformLogicNode(arg.value)
294
- }));
295
- if (arg?.value) {
296
- assignmentLines.push(new naslTypes.AssignmentLine({
297
- leftIndex: [0, index],
298
- rightIndex: [index],
338
+ if (arg.value.type === 'MemberExpression') {
339
+ const expression = flatMemberExpression(arg.value);
340
+ const members = flatMembers(transformLogicNode(arg.value) as any);
341
+ rights.push(new naslTypes.SelectMembers({
342
+ expression: transformLogicNode(expression[0]),
343
+ members,
299
344
  }));
345
+ if (arg?.value) {
346
+ assignmentLines.push(new naslTypes.AssignmentLine({
347
+ leftIndex: [0, index],
348
+ rightIndex: [index, index],
349
+ }));
350
+ }
351
+ } else {
352
+ rights.push(new naslTypes.SelectMembers({
353
+ expression: transformLogicNode(arg.value)
354
+ }));
355
+ if (arg?.value) {
356
+ assignmentLines.push(new naslTypes.AssignmentLine({
357
+ leftIndex: [0, index],
358
+ rightIndex: [index],
359
+ }));
360
+ }
300
361
  }
301
362
  structureProperties.push(new naslTypes.StructureProperty({
302
363
  name: arg?.key?.name,
@@ -23,6 +23,7 @@ import {
23
23
  BusinessLogic,
24
24
  View,
25
25
  Enum,
26
+ SubLogic
26
27
  } from '..';
27
28
  import { getNaslNodeByNodeCallee } from '../automate/engine/utils';
28
29
  import { runGeneratorSync as runSync, getAncestorExistingParamNames } from '../utils';
@@ -701,6 +702,19 @@ function getNodeiconFromLogic(completionProperty: CompletionProperty, node: type
701
702
  const likeComponent = node.getAncestor('View') as View || node.getAncestor('BusinessComponent') as BusinessComponent;
702
703
  const logic = (node as Param).logic || node.getAncestor('BusinessLogic') as BusinessLogic || (node as Param).OverriddenLogic || (node as Param).AuthLogic || (node as Param).AuthLogicForCallInterface;
703
704
 
705
+ // 如果节点存在于SubLogic 中,则可能出现 SubLogic 嵌套 SubLogic 的情况
706
+ // 为此需要找全链路上的所有 SubLogic 及其对应的参数
707
+ let parentSubLogicNode = node.getAncestor('SubLogic');
708
+ const isInSubLogic = !!parentSubLogicNode;
709
+ const logicLikeList: (SubLogic | Logic)[] = [];
710
+ if (isInSubLogic) {
711
+ while(parentSubLogicNode) {
712
+ logicLikeList.push(parentSubLogicNode as SubLogic);
713
+ parentSubLogicNode = parentSubLogicNode.getAncestor('SubLogic');
714
+ }
715
+ logicLikeList.push(logic);
716
+ }
717
+
704
718
  if (node.concept === 'Identifier' || node.concept === 'BindAttribute' || node.concept === 'MemberExpression') {
705
719
  const ancestorParamNames = getAncestorExistingParamNames(node);
706
720
  if (ancestorParamNames.has(propName)) {
@@ -718,7 +732,13 @@ function getNodeiconFromLogic(completionProperty: CompletionProperty, node: type
718
732
 
719
733
  if (logic) {
720
734
  const { returns } = logic;
721
- const params: Param[] = logic.params;
735
+
736
+ let params: Param[] = logic.params;
737
+ if (isInSubLogic) {
738
+ // 保证局部作用域的变量优先级高于全局作用域
739
+ params = logicLikeList.reduce((acc, cur) => acc.concat(cur.params), []);
740
+ }
741
+
722
742
  if (logic instanceof AuthLogicForCallInterface) {
723
743
  const { authParams } = logic;
724
744
  if (authParams.find((item) => item.name === completionProperty.name)) return 'api-auth-params';
@@ -511,12 +511,9 @@ export function getLogicsSync(node: CallLogic | BindEvent | Identifier | Logic,
511
511
  return result;
512
512
  }
513
513
  if (node?.concept === 'Identifier') {
514
- // 之前 连接器 Connector 相关也存在与 app.dependencies 下,
515
- // 现在迁移到 app.connectorDependencies 下,
516
- // 为保证上下游逻辑与之前保持一致,这边做相应的扩展
517
514
  const extensions = [
518
515
  ...app.dependencies,
519
- ...(app.connectorDependencies || [])
516
+ // ...(app.connectorDependencies || [])
520
517
  ]
521
518
  .map((dep) => moduleToLogicNamesapce(dep, app.overriddenLogics))
522
519
  .filter((item) => item.logics && item.logics.length);