@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
@@ -9,6 +9,7 @@ import {
9
9
  getStructures,
10
10
  getLogics,
11
11
  getModuleInterfaces,
12
+ getConnections,
12
13
  getConnectors,
13
14
  getDependencies,
14
15
  getFrontendVariables,
@@ -16,224 +17,317 @@ import {
16
17
  getCurrentNodeContext,
17
18
  getCurrentNodeContextForUI,
18
19
  getNaslUIOld,
20
+ getNaslUICode,
21
+ getEnumsCode,
22
+ getEntitiesCode,
23
+ getStructuresCode,
24
+ getLogicsCode,
25
+ getModuleInterfacesCode,
26
+ getConnectorsCode,
27
+ getDependenciesCode,
28
+ getFrontendViewsCode,
29
+ wrapTSBlock,
19
30
  } from './getContext';
20
31
  import { createCompilerState } from '../translator';
21
32
 
33
+ export * as getNaturalContext from './getContext';
34
+
22
35
  export function genNaturalTS(app: App, currentNode?: BaseNode, focusedNodePath?: string) {
23
36
  if (currentNode?.concept === 'Logic') {
24
37
  const logic = currentNode as Logic;
25
- const code = logic?.toNaturalTS(createCompilerState(undefined, {
26
- focusedNodePath,
27
- needNamespace: true,
28
- autoPrefixName: true,
29
- }));
38
+ const code = logic?.toNaturalTS(
39
+ createCompilerState(undefined, {
40
+ focusedNodePath,
41
+ needNamespace: true,
42
+ autoPrefixName: true,
43
+ })
44
+ );
30
45
  return code;
31
46
  }
32
47
  return getCurrentNodeContextForUI(currentNode).code;
33
48
  }
34
49
 
35
- export function genNaturalTSContextForLogic(
50
+ // =========================== logic ===========================
51
+ export function genNaturalTSContextJSONForLogic(
36
52
  app: App,
37
53
  currentNode?: BaseNode,
38
54
  focusedNodePath?: string,
39
- requiredIndexes?: string[]
55
+ material?: {
56
+ moduleInterfaces: any;
57
+ connectors: any;
58
+ dependencies: any;
59
+ }
40
60
  ) {
41
61
  const frontend = currentNode?.getAncestor('Frontend') as Frontend;
42
62
  const logicType = currentNode?.parentNode?.concept === 'App' ? 'global_logic' : 'view_logic';
43
63
  const state = createCompilerState();
44
64
 
65
+ const { naslCore } = getNaslCore(logicType);
66
+ const { naslUtil } = getNaslUtil();
67
+ const { naslUI } = getNaslUIOld();
68
+ const { naslOql } = getNaslOQL();
69
+ const { enums } = getEnums(app, state);
70
+ const { entities } = getEntities(app, state);
71
+ const { structures } = getStructures(app, state);
72
+ const { appLogics } = getLogics(app, currentNode);
73
+ const { interfaceDependencies } = getModuleInterfaces(
74
+ material?.moduleInterfaces || app?.interfaceDependencies,
75
+ state
76
+ );
77
+
78
+ let connections = [];
79
+ if (material?.connectors?.length) {
80
+ connections = getConnectors(material.connectors, state).connectors;
81
+ } else {
82
+ connections = getConnections(material?.connectors || app.connections, state).connections;
83
+ }
84
+
85
+ const { dependencies } = getDependencies(
86
+ material?.dependencies || app?.dependencies,
87
+ state,
88
+ logicType,
89
+ frontend?.type
90
+ );
91
+ const { frontendVar, frontendVariables } = getFrontendVariables(
92
+ currentNode?.getAncestor('Frontend') as Frontend,
93
+ state
94
+ );
95
+ const { views } = getFrontendViews(frontend, state, currentNode, false);
96
+ const { currentLogic } = getCurrentNodeContext(currentNode, focusedNodePath);
97
+
98
+ return {
99
+ naslCore,
100
+ naslUtil,
101
+ naslUI,
102
+ naslOql,
103
+ enums,
104
+ entities,
105
+ structures,
106
+ appLogics,
107
+ interfaceDependencies,
108
+ connections,
109
+ dependencies,
110
+ frontendVar, // @deprecated
111
+ frontendVariables,
112
+ views,
113
+ currentLogic,
114
+ logicType,
115
+ };
116
+ }
117
+
118
+ /**
119
+ * 生成 Logic 的 TypeScript 上下文
120
+ * @param tsContextJSON: 通过 genNaturalTSContextForLogic 获得到 tsContextJSON
121
+ * @param codeType: 'detail' | 'short'。detail 为详细代码,short 为简短代码
122
+ * 'detail' 将所有的code都返回(拼接成详细的code)。RAG召回,分析和执行阶段使用
123
+ * 'short' 只返回简短的code。模型召回,对应的分析阶段使用
124
+ * @param requiredIndexes?: 通过索引获取对应的 code。可挑选需要的 code
125
+ **/
126
+ export const genNaturalTSContextFromJSONForLogic = (
127
+ tsContextJSON: any,
128
+ codeType: 'detail' | 'short',
129
+ requiredIndexes?: string[]
130
+ ) => {
131
+ const {
132
+ naslCore,
133
+ naslUtil,
134
+ naslUI,
135
+ naslOql,
136
+ enums,
137
+ entities,
138
+ structures,
139
+ appLogics,
140
+ interfaceDependencies,
141
+ connections,
142
+ dependencies,
143
+ frontendVariables,
144
+ views,
145
+ currentLogic,
146
+ logicType,
147
+ } = tsContextJSON;
148
+
45
149
  let code = '';
46
150
  code += '### [1] 标准库\n';
47
- code += getNaslCore(logicType).code;
151
+ code += wrapTSBlock(naslCore);
48
152
 
49
153
  code += '\n### [2] nasl.util\n';
50
- code += getNaslUtil().code;
154
+ code += wrapTSBlock(naslUtil);
51
155
 
52
- if (frontend) {
156
+ if (naslUI && logicType === 'view_logic') {
53
157
  code += '\n### [3] nasl.ui\n';
54
- code += getNaslUIOld().code;
158
+ if (typeof naslUI === 'string') {
159
+ code += wrapTSBlock(naslUI);
160
+ } else {
161
+ code += getNaslUICode(naslUI, codeType, requiredIndexes);
162
+ }
55
163
  }
56
164
 
57
- if (logicType === 'global_logic') {
165
+ if (naslOql && logicType === 'global_logic') {
58
166
  code += '\n### [4] nasl.oql\n';
59
- code += getNaslOQL().code;
167
+ code += wrapTSBlock(naslOql);
60
168
  }
61
169
 
62
170
  code += '\n### [5] 全局上下文\n';
63
- code += '\n#### [5-0] 枚举\n';
64
- code += getEnums(app, state, requiredIndexes).code;
171
+ if (enums.data?.length) {
172
+ code += '\n#### [5-0] 枚举\n';
173
+ code += getEnumsCode(enums);
174
+ }
65
175
 
66
- code += '\n#### [5-1] 实体\n';
67
- code += getEntities(app, state, requiredIndexes).code;
176
+ if (entities?.length) {
177
+ code += '\n#### [5-1] 实体\n';
178
+ code += getEntitiesCode(entities);
179
+ }
68
180
 
69
- code += '\n#### [5-2] 可用的数据结构\n';
70
- code += getStructures(app, state, requiredIndexes).code;
181
+ if (structures.data?.length) {
182
+ code += '\n#### [5-2] 可用的数据结构\n';
183
+ code += getStructuresCode(structures);
184
+ }
71
185
 
72
- code += '\n### [6] 服务端逻辑\n';
73
- code += getLogics(app, currentNode, requiredIndexes).code;
186
+ if (appLogics.data?.length) {
187
+ code += '\n### [6] 服务端逻辑\n';
188
+ code += getLogicsCode(appLogics, codeType, requiredIndexes);
189
+ }
74
190
 
75
- code += '\n### [7] 可调用的接口列表\n';
76
- code += getModuleInterfaces(app, state, requiredIndexes).code;
191
+ if (interfaceDependencies) {
192
+ code += '\n### [7] 可调用的接口列表\n';
193
+ code += getModuleInterfacesCode(interfaceDependencies, codeType, requiredIndexes);
194
+ }
77
195
 
78
- if (app?.connections?.length > 0 && logicType === 'global_logic') {
196
+ if (logicType === 'global_logic' && connections) {
79
197
  code += '\n### [8] 连接器逻辑列表\n';
80
- code += getConnectors(app, state, requiredIndexes).code;
198
+ code += getConnectorsCode(connections, codeType, requiredIndexes);
81
199
  }
82
-
83
- if (app?.dependencies?.length > 0) {
200
+ if (dependencies) {
84
201
  code += '\n### [9] 依赖库逻辑列表\n';
85
- code += getDependencies(app, state, requiredIndexes).code;
202
+ code += getDependenciesCode(dependencies, codeType, requiredIndexes);
86
203
  }
87
204
 
88
- if (frontend) {
205
+ if (logicType === 'view_logic') {
89
206
  code += '\n### [10] 页面上下文\n';
90
- if (frontend?.variables?.length > 0) {
207
+ if (frontendVariables) {
91
208
  code += '\n#### [10-0] 前端全局变量\n';
92
- code += getFrontendVariables(frontend, state).code;
209
+ code += frontendVariables;
93
210
  }
94
211
 
95
- code += '\n#### [10-1] 前端页面列表\n';
96
- code += getFrontendViews(frontend, state, currentNode, true).code;
212
+ if (views?.data?.length) {
213
+ code += '\n#### [10-1] 前端页面列表\n';
214
+ code += getFrontendViewsCode(views);
215
+ }
97
216
  }
98
217
 
99
218
  code += '\n### 当前逻辑上下文\n';
100
- code += getCurrentNodeContext(currentNode, focusedNodePath).code;
101
- return code;
102
- }
219
+ code += wrapTSBlock(currentLogic);
103
220
 
104
- export const genNaturalTSContext = genNaturalTSContextForLogic;
221
+ return code;
222
+ };
105
223
 
106
- export function genNaturalTSContextForUI(
224
+ export function genNaturalTSContextForLogic(
107
225
  app: App,
108
- currentNode: BaseNode,
226
+ currentNode?: BaseNode,
109
227
  focusedNodePath?: string,
110
228
  requiredIndexes?: string[],
111
- material?: { basicMaterials: { json: any; tsDeclaration: string; }, extensionMaterials: { name: string; title: string; description: string; tsDescription: string; }[]; },
112
- ) {
113
- const frontend = currentNode.getAncestor('Frontend') as Frontend;
114
- const state = createCompilerState();
115
-
116
- let code = '';
117
- code += '### [1] 标准库\n';
118
- code += getNaslCore('view_logic').code;
119
-
120
- code += '\n### [2] nasl.util\n';
121
- code += getNaslUtil().code;
122
-
123
- if (frontend) {
124
- code += '\n### [3] nasl.ui\n';
125
- code += getNaslUI(app, frontend.type, material || frontend.type, requiredIndexes).code;
126
- code += '\n';
127
- }
128
-
129
- code += '\n### [5] 全局上下文\n';
130
- code += '\n#### [5-0] 枚举\n';
131
- code += getEnums(app, state, requiredIndexes).code;
132
-
133
- code += '\n#### [5-1] 实体\n';
134
- code += getEntities(app, state, requiredIndexes).code;
135
-
136
- code += '\n#### [5-2] 可用的数据结构\n';
137
- code += getStructures(app, state, requiredIndexes).code;
138
-
139
- code += '\n### [6] 服务端逻辑\n';
140
- code += getLogics(app, currentNode, requiredIndexes).code;
141
-
142
- code += '\n### [7] 可调用的接口列表\n';
143
- code += getModuleInterfaces(app, state, requiredIndexes).code;
144
-
145
- if (app?.dependencies?.length > 0) {
146
- code += '\n### [9] 依赖库逻辑列表\n';
147
- code += getDependencies(app, state, requiredIndexes).code;
148
- }
149
-
150
- if (frontend) {
151
- code += '\n### [10] 页面上下文\n';
152
- if (frontend?.variables?.length > 0) {
153
- code += '\n#### [10-0] 前端全局变量\n';
154
- code += getFrontendVariables(frontend, state).code;
155
- }
156
-
157
- code += '\n#### [10-1] 前端页面列表\n';
158
- code += getFrontendViews(frontend, state, currentNode, true).code;
229
+ material?: {
230
+ moduleInterfaces: any;
231
+ connectors: any;
232
+ dependencies: any;
233
+ },
234
+ restParams?: {
235
+ codeType?: 'detail' | 'short';
159
236
  }
160
-
161
- code += '\n### 当前页面上下文\n';
162
- code += getCurrentNodeContextForUI(currentNode).code;
237
+ ) {
238
+ const tsContextJSON = genNaturalTSContextJSONForLogic(
239
+ app,
240
+ currentNode,
241
+ focusedNodePath,
242
+ material
243
+ );
244
+ const code = genNaturalTSContextFromJSONForLogic(
245
+ tsContextJSON,
246
+ restParams.codeType,
247
+ requiredIndexes
248
+ );
163
249
  return code;
164
250
  }
165
251
 
166
- export function genNaturalTSContextJSONForLogic(
252
+ export const genNaturalTSContext = genNaturalTSContextForLogic;
253
+ export const genNaturalTsContextJson = genNaturalTSContextJSONForLogic;
254
+
255
+ // =========================== view ===========================
256
+
257
+ // 生成 View 的 tsJson
258
+ export function genNaturalTSContextJSONForUI(
167
259
  app: App,
168
- currentNode?: BaseNode,
169
- focusedNodePath?: string
260
+ currentNode: BaseNode,
261
+ material?: {
262
+ basicMaterials: 'pc' | 'h5' | { json: any; tsDeclaration: string };
263
+ extensionMaterials: {
264
+ name: string;
265
+ title: string;
266
+ description: string;
267
+ tsDescription: string;
268
+ }[];
269
+ moduleInterfaces: any;
270
+ connectors: any;
271
+ dependencies: any;
272
+ }
170
273
  ) {
171
- const frontend = currentNode?.getAncestor('Frontend') as Frontend;
172
- const logicType = currentNode?.parentNode?.concept === 'App' ? 'global_logic' : 'view_logic';
274
+ const frontend = currentNode.getAncestor('Frontend') as Frontend;
173
275
  const state = createCompilerState();
174
276
 
175
- const { naslCore } = getNaslCore(logicType);
277
+ const { naslCore } = getNaslCore('view_logic');
176
278
  const { naslUtil } = getNaslUtil();
177
- const { naslUI } = getNaslUIOld();
178
- const { naslOql } = getNaslOQL();
179
- const { enums } = getEnums(app, state, []);
180
- const { entities } = getEntities(app, state, []);
181
- const { structures } = getStructures(app, state, []);
182
- const { appLogics } = getLogics(app, currentNode, []);
183
- const { interfaceDependencies } = getModuleInterfaces(app, state, []);
184
- const { connections } = getConnectors(app, state, []);
185
- const { dependencies } = getDependencies(app, state, []);
186
- const { frontendVar, frontendVariables } = getFrontendVariables(
187
- currentNode?.getAncestor('Frontend') as Frontend,
279
+ const { naslUI } = getNaslUI(app, frontend.type, {
280
+ basicMaterials: material?.basicMaterials,
281
+ extensionMaterials: material?.extensionMaterials,
282
+ });
283
+ const { enums } = getEnums(app, state);
284
+ const { entities } = getEntities(app, state);
285
+ const { structures } = getStructures(app, state);
286
+ const { appLogics } = getLogics(app, currentNode);
287
+ const { interfaceDependencies } = getModuleInterfaces(
288
+ material?.moduleInterfaces || app?.interfaceDependencies,
188
289
  state
189
290
  );
291
+ const { dependencies } = getDependencies(
292
+ material?.dependencies || app?.dependencies,
293
+ state,
294
+ 'view_logic',
295
+ frontend?.type
296
+ );
297
+ const { frontendVariables } = getFrontendVariables(frontend, state);
190
298
  const { views } = getFrontendViews(frontend, state, currentNode, false);
191
- const { currentLogic } = getCurrentNodeContext(currentNode, focusedNodePath);
299
+ const { currentLogic } = getCurrentNodeContextForUI(currentNode);
192
300
 
193
301
  return {
194
302
  naslCore,
195
303
  naslUtil,
196
304
  naslUI,
197
- naslOql,
198
305
  enums,
199
306
  entities,
200
307
  structures,
201
308
  appLogics,
202
309
  interfaceDependencies,
203
- connections,
204
310
  dependencies,
205
- frontendVar, // @deprecated
206
311
  frontendVariables,
207
312
  views,
208
- currentLogic,
313
+ currentPage: currentLogic,
209
314
  };
210
315
  }
211
316
 
212
- export const genNaturalTsContextJson = genNaturalTSContextJSONForLogic;
213
-
214
- export function genNaturalTSContextJSONForUI(
215
- app: App,
216
- currentNode: BaseNode,
217
- material?: { basicMaterials: { json: any; tsDeclaration: string; }, extensionMaterials: { name: string; title: string; description: string; tsDescription: string; }[]; },
218
- requiredIndexes?: string[],
219
- ) {
220
- const frontend = currentNode.getAncestor('Frontend') as Frontend;
221
- const state = createCompilerState();
222
-
223
- const { naslCore } = getNaslCore('view_logic');
224
- const { naslUtil } = getNaslUtil();
225
- const { naslUI } = getNaslUI(app, frontend.type, material || frontend.type, requiredIndexes);
226
- const { enums } = getEnums(app, state, requiredIndexes);
227
- const { entities } = getEntities(app, state, requiredIndexes);
228
- const { structures } = getStructures(app, state, requiredIndexes);
229
- const { appLogics } = getLogics(app, currentNode, requiredIndexes);
230
- const { interfaceDependencies } = getModuleInterfaces(app, state, requiredIndexes);
231
- const { dependencies } = getDependencies(app, state, requiredIndexes);
232
- const { frontendVariables } = getFrontendVariables(frontend, state);
233
- const { views } = getFrontendViews(frontend, state, currentNode, true);
234
- const { currentLogic } = getCurrentNodeContextForUI(currentNode);
235
-
236
- return {
317
+ /**
318
+ * 根据 tsContextJSON 生成 View 的 TypeScript 上下文
319
+ * @param tsContextJSON: 通过 genNaturalTSContextJSONForUI 获得到 tsContextJSON
320
+ * @param codeType: 'detail' | 'short'。detail 为详细代码,short 为简短代码
321
+ * 'detail' 将所有的code都返回(拼接成详细的code)。RAG召回,分析和执行阶段使用
322
+ * 'short' 只返回简短的code。模型召回,对应的分析阶段使用
323
+ * @param requiredIndexes?: 通过索引获取对应的 code。可挑选需要的 code
324
+ **/
325
+ export const genNaturalTSContextFromJSONForUI = (
326
+ tsContextJSON: any,
327
+ codeType: 'detail' | 'short',
328
+ requiredIndexes?: string[]
329
+ ) => {
330
+ const {
237
331
  naslCore,
238
332
  naslUtil,
239
333
  naslUI,
@@ -245,8 +339,100 @@ export function genNaturalTSContextJSONForUI(
245
339
  dependencies,
246
340
  frontendVariables,
247
341
  views,
248
- currentPage: currentLogic,
249
- };
250
- }
342
+ currentPage,
343
+ } = tsContextJSON;
251
344
 
252
- export * as getNaturalContext from './getContext';
345
+ let code = '';
346
+ code += '### [1] 标准库\n';
347
+ code += wrapTSBlock(naslCore);
348
+
349
+ code += '\n### [2] nasl.util\n';
350
+ code += wrapTSBlock(naslUtil);
351
+
352
+ if (naslUI) {
353
+ code += '\n### [3] nasl.ui\n';
354
+ if (typeof naslUI === 'string') {
355
+ code += wrapTSBlock(naslUI);
356
+ } else {
357
+ code += getNaslUICode(naslUI, codeType, requiredIndexes);
358
+ }
359
+ }
360
+
361
+ code += '\n### [5] 全局上下文\n';
362
+ if (enums.data?.length) {
363
+ code += '\n#### [5-0] 枚举\n';
364
+ code += getEnumsCode(enums);
365
+ }
366
+
367
+ if (entities?.length) {
368
+ code += '\n#### [5-1] 实体\n';
369
+ code += getEntitiesCode(entities);
370
+ }
371
+
372
+ if (structures.data?.length) {
373
+ code += '\n#### [5-2] 可用的数据结构\n';
374
+ code += getStructuresCode(structures);
375
+ }
376
+
377
+ if (appLogics.data?.length) {
378
+ code += '\n### [6] 服务端逻辑\n';
379
+ code += getLogicsCode(appLogics, codeType, requiredIndexes);
380
+ }
381
+
382
+ if (interfaceDependencies) {
383
+ code += '\n### [7] 可调用的接口列表\n';
384
+ code += getModuleInterfacesCode(interfaceDependencies, codeType, requiredIndexes);
385
+ }
386
+
387
+ if (dependencies) {
388
+ code += '\n### [9] 依赖库逻辑列表\n';
389
+ code += getDependenciesCode(dependencies, codeType, requiredIndexes);
390
+ }
391
+
392
+ code += '\n### [10] 页面上下文\n';
393
+ if (frontendVariables) {
394
+ code += '\n#### [10-0] 前端全局变量\n';
395
+ code += frontendVariables;
396
+ }
397
+
398
+ if (views?.data?.length) {
399
+ code += '\n#### [10-1] 前端页面列表\n';
400
+ code += getFrontendViewsCode(views);
401
+ }
402
+
403
+ code += '\n### 当前页面上下文\n';
404
+ code += wrapTSBlock(currentPage);
405
+
406
+ return code;
407
+ };
408
+
409
+ // 兼容各版本,统一调用 genNaturalTSContextForUI 方法
410
+ export function genNaturalTSContextForUI(
411
+ app: App,
412
+ currentNode: BaseNode,
413
+ focusedNodePath?: string,
414
+ requiredIndexes?: string[],
415
+ material?: {
416
+ basicMaterials: 'pc' | 'h5' | { json: any; tsDeclaration: string };
417
+ extensionMaterials: {
418
+ name: string;
419
+ title: string;
420
+ description: string;
421
+ tsDescription: string;
422
+ }[];
423
+ moduleInterfaces: any;
424
+ connectors: any;
425
+ dependencies: any;
426
+ },
427
+ restParams?: {
428
+ codeType?: 'detail' | 'short';
429
+ }
430
+ ) {
431
+ const tsContextJSON = genNaturalTSContextJSONForUI(app, currentNode, material);
432
+ const code = genNaturalTSContextFromJSONForUI(
433
+ tsContextJSON,
434
+ restParams.codeType,
435
+ requiredIndexes
436
+ );
437
+ return code;
438
+ }
@@ -42,6 +42,7 @@ export function handleMaterial({ json, tsDeclaration }: { json: Array<{ name: st
42
42
  tsDeclaration = tsDeclaration.replace(/\/\/\/ *<reference types="@nasl\/types" *\/>\s*/g, '')
43
43
  .replace(/\{\s+altKey[\s\S]+?\}/g, 'MouseEvent')
44
44
  .replace(/\{\s+cancelBubble[\s\S]+?\}/g, 'FocusEvent')
45
+ .replace(/\{\s+rawValue[\s\S]+?\}/g, 'ValidateResult')
45
46
  .replace(/\{\s+rawValue[\s\S]+?\}/g, 'ValidateEvent');
46
47
 
47
48
  const snippets = tsDeclaration.split('declare namespace nasl.ui');
@@ -103,9 +104,10 @@ export function getExtensionsDeclaration(viewComponent: any) {
103
104
  code += `${indent(state.tabSize + 1)}}\n`;
104
105
  code += `${indent(state.tabSize + 1)}class ${componentName}Options extends ViewComponentOptions {\n`;
105
106
  // props
106
- viewComponent.props?.forEach((prop: any) => {
107
+ const props = viewComponent.props || viewComponent.attrs || [];
108
+ props?.forEach((prop: any) => {
107
109
  code += `${indent(state.tabSize + 2)}${utils.getDescription(prop.title, prop.description)}\n`;
108
- code += `${indent(state.tabSize + 2)}${prop.name}?: ${prop?.type || prop?.tsType};\n`;
110
+ code += `${indent(state.tabSize + 2)}${camelCase(prop.name)}?: ${prop?.type || prop?.tsType};\n`;
109
111
  });
110
112
  // events
111
113
  viewComponent.events?.forEach((event: any) => {